improve device value helper text

This commit is contained in:
proddy
2023-05-01 13:39:12 +02:00
parent 8a01a1e471
commit 148e35ea53
4 changed files with 36 additions and 15 deletions

View File

@@ -83,6 +83,22 @@ const DashboarDevicesDialog = ({ open, onClose, onSave, selectedItem, validator
} }
}; };
const showHelperText = (dv: DeviceValue) => {
if (dv.h) {
return dv.h;
}
if (dv.l) {
return '[ ' + dv.l.join(' | ') + ' ]';
}
if (dv.u !== DeviceValueUOM.NONE) {
if (dv.m && dv.x) {
return '<number between ' + dv.m + ' and ' + dv.x + '>';
}
return '<number>';
}
return '';
};
return ( return (
<Dialog open={open} onClose={close}> <Dialog open={open} onClose={close}>
<DialogTitle>{selectedItem.v === '' && selectedItem.c ? LL.RUN_COMMAND() : LL.CHANGE_VALUE()}</DialogTitle> <DialogTitle>{selectedItem.v === '' && selectedItem.c ? LL.RUN_COMMAND() : LL.CHANGE_VALUE()}</DialogTitle>
@@ -90,7 +106,7 @@ const DashboarDevicesDialog = ({ open, onClose, onSave, selectedItem, validator
<Box color="warning.main" p={0} pl={0} pr={0} mt={0} mb={2}> <Box color="warning.main" p={0} pl={0} pr={0} mt={0} mb={2}>
<Typography variant="body2">{editItem.id.slice(2)}</Typography> <Typography variant="body2">{editItem.id.slice(2)}</Typography>
</Box> </Box>
<Grid container spacing={1}> <Grid>
<Grid item> <Grid item>
{editItem.l && ( {editItem.l && (
<TextField <TextField
@@ -125,7 +141,9 @@ const DashboarDevicesDialog = ({ open, onClose, onSave, selectedItem, validator
/> />
)} )}
</Grid> </Grid>
{editItem.h && <FormHelperText>{editItem.h}</FormHelperText>} <Grid item>
<FormHelperText>format:&nbsp;{showHelperText(editItem)}</FormHelperText>
</Grid>
</Grid> </Grid>
</DialogContent> </DialogContent>

View File

@@ -170,14 +170,10 @@ export const deviceValueItemValidation = (dv: DeviceValue) =>
{ {
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) { validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
if (dv.u !== DeviceValueUOM.NONE && isNaN(+value)) { if (dv.u !== DeviceValueUOM.NONE && isNaN(+value)) {
// not a number callback('Not a valid number');
dv.m && dv.x
? callback('Value must be a number between ' + dv.m + ' and ' + dv.x)
: callback('Value must be a number');
} }
// is a number
(dv.m && Number(value) < dv.m) || (dv.x && Number(value) > dv.x) (dv.m && Number(value) < dv.m) || (dv.x && Number(value) > dv.x)
? callback('Value must be between ' + dv.m + ' and ' + dv.x) ? callback('Value out of range')
: callback(); : callback();
} }
} }

View File

@@ -492,6 +492,13 @@ const emsesp_devicedata_1 = {
id: '00hc1 mode', id: '00hc1 mode',
c: 'hc1/mode', c: 'hc1/mode',
l: ['off', 'on', 'auto'] l: ['off', 'on', 'auto']
},
{
v: '00 mo 00:00 T1',
u: 0,
id: '00hc1 program switchtime',
c: 'hc1/switchtime',
h: '<nn> [ not_set | day hh:mm Tn ]'
} }
] ]
}; };

View File

@@ -194,13 +194,13 @@ MAKE_NOTRANSLATION(6kW, "6 kW")
MAKE_NOTRANSLATION(9kW, "9 kW") MAKE_NOTRANSLATION(9kW, "9 kW")
// templates - this are not translated and will be saved under options_single // templates - this are not translated and will be saved under options_single
MAKE_NOTRANSLATION(tpl_datetime, "Format: < NTP | dd.mm.yyyy-hh:mm:ss-day(0-6)-dst(0/1) >") MAKE_NOTRANSLATION(tpl_datetime, "< NTP | dd.mm.yyyy-hh:mm:ss-day(0-6)-dst(0/1) >")
MAKE_NOTRANSLATION(tpl_switchtime, "Format: <nn> [ not_set | day hh:mm on|off ]") MAKE_NOTRANSLATION(tpl_switchtime, "<nn> [ not_set | day hh:mm on|off ]")
MAKE_NOTRANSLATION(tpl_switchtime1, "Format: <nn> [ not_set | day hh:mm Tn ]") MAKE_NOTRANSLATION(tpl_switchtime1, "<nn> [ not_set | day hh:mm Tn ]")
MAKE_NOTRANSLATION(tpl_holidays, "Format: < dd.mm.yyyy-dd.mm.yyyy >") MAKE_NOTRANSLATION(tpl_holidays, "< dd.mm.yyyy-dd.mm.yyyy >")
MAKE_NOTRANSLATION(tpl_date, "Format: < dd.mm.yyyy >") MAKE_NOTRANSLATION(tpl_date, "< dd.mm.yyyy >")
MAKE_NOTRANSLATION(tpl_input, "Format: <inv>[<evu1><evu2><evu3><comp><aux><cool><heat><dhw><pv>]") MAKE_NOTRANSLATION(tpl_input, "<inv>[<evu1><evu2><evu3><comp><aux><cool><heat><dhw><pv>]")
MAKE_NOTRANSLATION(tpl_input4, "Format: <inv>[<comp><aux><cool><heat><dhw><pv>]") MAKE_NOTRANSLATION(tpl_input4, "<inv>[<comp><aux><cool><heat><dhw><pv>]")
#if defined(EMSESP_TEST) #if defined(EMSESP_TEST)
MAKE_NOTRANSLATION(test_cmd, "run a test") MAKE_NOTRANSLATION(test_cmd, "run a test")