Call read commands from Web #2116

This commit is contained in:
proddy
2024-10-20 15:02:11 +02:00
parent bd08b7e0e4
commit 798e20a266
25 changed files with 282 additions and 127 deletions

View File

@@ -2,13 +2,24 @@ import { useEffect, useRef, useState } from 'react';
import { toast } from 'react-toastify';
import DownloadIcon from '@mui/icons-material/GetApp';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import WarningIcon from '@mui/icons-material/Warning';
import { Box, Button, Checkbox, MenuItem, TextField, styled } from '@mui/material';
import {
Box,
Button,
Checkbox,
IconButton,
MenuItem,
TextField,
styled
} from '@mui/material';
import Grid from '@mui/material/Grid2';
import { API } from 'api/app';
import { fetchLogES, readLogSettings, updateLogSettings } from 'api/system';
import { useSSE } from 'alova/client';
import { useRequest, useSSE } from 'alova/client';
import type { APIcall } from 'app/main/types';
import {
BlockFormControlLabel,
BlockNavigation,
@@ -80,9 +91,20 @@ const SystemLog = () => {
update: updateLogSettings
});
const { send } = useRequest(
(data: string) => API({ device: 'system', cmd: 'read', id: 0, value: data }),
{
immediate: false
}
);
const [readValue, setReadValue] = useState('');
const [readOpen, setReadOpen] = useState(false);
const [logEntries, setLogEntries] = useState<LogEntry[]>([]);
const [autoscroll, setAutoscroll] = useState(true);
const ALPHA_NUMERIC_DASH_REGEX = /^[a-fA-F0-9 ]+$/;
const updateFormValue = updateValueDirty(
origData,
dirtyFlags,
@@ -150,6 +172,17 @@ const SystemLog = () => {
}
}, [logEntries.length]);
const sendReadCommand = () => {
if (readValue === '') {
setReadOpen(!readOpen);
return;
}
void send(readValue);
console.log('send read command', readValue); // TODO remove
setReadOpen(false);
setReadValue('');
};
const content = () => {
if (!data) {
return <FormLoader onRetry={loadData} errorMessage={errorMessage} />;
@@ -163,7 +196,7 @@ const SystemLog = () => {
name="level"
label={LL.LOG_LEVEL()}
value={data.level}
sx={{ width: '15ch' }}
sx={{ width: '10ch' }}
variant="outlined"
onChange={updateFormValue}
margin="normal"
@@ -218,24 +251,49 @@ const SystemLog = () => {
label={LL.AUTO_SCROLL()}
/>
</Grid>
<Button
startIcon={<DownloadIcon />}
variant="outlined"
color="secondary"
onClick={onDownload}
>
{LL.EXPORT()}
</Button>
{dirtyFlags && dirtyFlags.length !== 0 && (
<Grid>
<Button
startIcon={<WarningIcon color="warning" />}
variant="contained"
color="info"
onClick={saveSettings}
startIcon={<DownloadIcon />}
variant="outlined"
color="secondary"
onClick={onDownload}
>
{LL.APPLY_CHANGES(dirtyFlags.length)}
{LL.EXPORT()}
</Button>
)}
{dirtyFlags && dirtyFlags.length !== 0 && (
<Button
startIcon={<WarningIcon color="warning" />}
variant="contained"
color="info"
onClick={saveSettings}
>
{LL.APPLY_CHANGES(dirtyFlags.length)}
</Button>
)}
</Grid>
<Grid>
{readOpen && (
<TextField
value={readValue}
onChange={(event) => {
const value = event.target.value;
if (value !== '' && !ALPHA_NUMERIC_DASH_REGEX.test(value)) {
return;
}
setReadValue(value);
}}
focused={true}
label="Send Read command"
variant="outlined"
helperText="<deviceID> <type ID> [offset] [length]"
size="small"
/>
)}
<IconButton onClick={sendReadCommand}>
<PlayArrowIcon color="primary" />
</IconButton>
</Grid>
</Grid>
<Box
sx={{

View File

@@ -344,6 +344,7 @@ const cz: Translation = {
DASHBOARD: 'Dashboard',
NO_DATA: 'Žádná data nejsou k dispozici',
DASHBOARD_1: 'Přizpůsobte si dashboard označením EMS entit jako Oblíbené pomocí modulu Přizpůsobení.',
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default cz;

View File

@@ -343,7 +343,8 @@ const de: Translation = {
AUTO_SCROLL: 'Automatisches Scrollen',
DASHBOARD: 'Dashboard',
NO_DATA: 'Keine Daten verfügbar',
DASHBOARD_1: 'Passen Sie Ihr Dashboard an, indem Sie EMS-Entitäten mithilfe des Moduls „Anpassungen“ als Favorit markieren.'
DASHBOARD_1: 'Passen Sie Ihr Dashboard an, indem Sie EMS-Entitäten mithilfe des Moduls „Anpassungen“ als Favorit markieren.',
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default de;

View File

@@ -115,7 +115,7 @@ const en: Translation = {
READONLY: 'Enable read-only mode (blocks all outgoing EMS Tx Write commands)',
UNDERCLOCK_CPU: 'Underclock CPU speed',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote on missing room temperature',
HEATINGOFF: 'Start boiler with forced heating off',
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Enable Shower Timer',
@@ -344,6 +344,7 @@ const en: Translation = {
DASHBOARD: 'Dashboard',
NO_DATA: 'No data available',
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.',
DEVELOPER_MODE: 'Developer Mode'
};
export default en;

View File

@@ -116,7 +116,7 @@ const fr: Translation = {
UNDERCLOCK_CPU: 'Underclock du CPU',
HEATINGOFF: 'Start boiler with forced heating off', // TODO translate
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote on missing room temperature', // TODO translate
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Activer la minuterie de la douche',
ENABLE_SHOWER_ALERT: 'Activer les alertes de durée de douche',
@@ -343,7 +343,8 @@ const fr: Translation = {
AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.' // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default fr;

View File

@@ -115,7 +115,7 @@ const it: Translation = {
READONLY: 'Abilita modalità sola-lettura (blocca tutti i comandi di scrittura EMS Tx in uscita)',
UNDERCLOCK_CPU: 'Abbassa velocità della CPU',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote on missing room temperature', // TODO translate
HEATINGOFF: 'Avviamento caldaia con riscaldamento forzato spento',
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Abilita timer doccia',
@@ -343,7 +343,8 @@ const it: Translation = {
AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.' // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default it;

View File

@@ -115,7 +115,7 @@ const nl: Translation = {
READONLY: 'Activeer read-only modus (blokkeert alle outgaande EMS Tx schrijf commandos)',
UNDERCLOCK_CPU: 'Underclock CPU snelheid',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote on missing room temperature', // TODO translate
HEATINGOFF: 'Start ketel met geforceerde verwarming uit',
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Activeer Douche Timer (tijdmeting)',
@@ -343,7 +343,8 @@ const nl: Translation = {
AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.' // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default nl;

View File

@@ -115,7 +115,7 @@ const no: Translation = {
READONLY: 'Aktiver read-only modus (blokker all EMS Tx Skriving)',
UNDERCLOCK_CPU: 'Underklokking av prosessorhastighet',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote control on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote control on missing room temperature', // TODO translate
HEATINGOFF: 'Start boiler with forced heating off', // TODO translate
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Aktiver Dusjtimer',
@@ -343,7 +343,8 @@ const no: Translation = {
AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.' // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default no;

View File

@@ -115,7 +115,7 @@ const pl: BaseTranslation = {
READONLY: 'Tryb pracy "tylko do odczytu" (blokuje wszystkie komendy zapisu na magistralę EMS)',
UNDERCLOCK_CPU: 'Obniż taktowanie CPU',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote control on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote control on missing room temperature', // TODO translate
HEATINGOFF: 'Uruchom kocioł z wymuszonym wyłączonym grzaniem',
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Aktywuj minutnik prysznica',
@@ -343,7 +343,8 @@ const pl: BaseTranslation = {
AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.' // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default pl;

View File

@@ -115,7 +115,7 @@ const sk: Translation = {
READONLY: 'Povoliť režim len na čítanie (blokuje všetky odchádzajúce príkazy EMS Tx Write)',
UNDERCLOCK_CPU: 'Podtaktovanie rýchlosti procesora',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote on missing room temperature', // TODO translate
HEATINGOFF: 'Spustiť kotol s vynúteným vykurovaním',
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Povoliť časovač sprchovania',
@@ -343,7 +343,8 @@ const sk: Translation = {
AUTO_SCROLL: 'Automatické rolovanie',
DASHBOARD: 'Panel',
NO_DATA: 'Nie sú k dispozícii žiadne údaje',
DASHBOARD_1: 'Prispôsobte si svoj informačný panel tak, že označíte entity EMS ako Obľúbené pomocou modulu Prispôsobenia.'
DASHBOARD_1: 'Prispôsobte si svoj informačný panel tak, že označíte entity EMS ako Obľúbené pomocou modulu Prispôsobenia.',
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default sk;

View File

@@ -115,7 +115,7 @@ const sv: Translation = {
READONLY: 'Aktivera read-only (blockerar alla utgående skrivkommandon mot EMS-bussen)',
UNDERCLOCK_CPU: 'Nedklocka Processorhastighet',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote on missing room temperature', // TODO translate
HEATINGOFF: 'Start boiler with forced heating off', // TODO translate
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Aktivera Dusch-timer',
@@ -343,7 +343,8 @@ const sv: Translation = {
AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.' // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default sv;

View File

@@ -115,7 +115,7 @@ const tr: Translation = {
READONLY: 'Salt okunur modu devreye al (bütün giden EMS Tx Yazma komutlarını engeller)',
UNDERCLOCK_CPU: 'İşlemci hızını düşür',
REMOTE_TIMEOUT: 'Remote timeout',
REMOTE_TIMEOUT_EN: 'Disable remote on missing roomtemperature',
REMOTE_TIMEOUT_EN: 'Disable remote on missing room temperature', // TODO translate
HEATINGOFF: 'Start boiler with forced heating off', // TODO translate
MIN_DURATION: 'Wait time',
ENABLE_SHOWER_TIMER: 'Duş Sayacını Devreye Al',
@@ -343,7 +343,8 @@ const tr: Translation = {
AUTO_SCROLL: 'Auto Scroll', // TODO translate
DASHBOARD: 'Dashboard', // TODO translate
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.' // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module.', // TODO translate
DEVELOPER_MODE: 'Developer Mode' // TODO translate
};
export default tr;