mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
This commit is contained in:
@@ -187,30 +187,28 @@ const SettingsEntities: FC = () => {
|
||||
setSelectedEntityItem({
|
||||
id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100),
|
||||
name: '',
|
||||
device_id: 11,
|
||||
type_id: 0,
|
||||
device_id: '',
|
||||
type_id: '',
|
||||
offset: 0,
|
||||
factor: 1,
|
||||
uom: 0,
|
||||
value_type: 2,
|
||||
value_type: 0,
|
||||
writeable: false,
|
||||
deleted: false
|
||||
});
|
||||
setDialogOpen(true);
|
||||
};
|
||||
|
||||
function formatValue(value: any, uom: number) {
|
||||
if (value === undefined) {
|
||||
return '';
|
||||
}
|
||||
return new Intl.NumberFormat().format(value) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
|
||||
function formatValue(value: any, uom: any) {
|
||||
return value === undefined || uom === undefined
|
||||
? ''
|
||||
: new Intl.NumberFormat().format(value) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
|
||||
}
|
||||
|
||||
function showHex(value: number, digit: number) {
|
||||
if (digit === 4) {
|
||||
return '0x' + ('000' + value.toString(16).toUpperCase()).slice(-4);
|
||||
}
|
||||
return '0x' + ('0' + value.toString(16).toUpperCase()).slice(-2);
|
||||
return digit === 4
|
||||
? '0x' + ('000' + value.toString(16).toUpperCase()).slice(-4)
|
||||
: '0x' + ('0' + value.toString(16).toUpperCase()).slice(-2);
|
||||
}
|
||||
|
||||
const renderEntity = () => {
|
||||
|
||||
@@ -59,8 +59,8 @@ const SettingsEntitiesDialog = ({
|
||||
// convert to hex strings straight away
|
||||
setEditItem({
|
||||
...selectedEntityItem,
|
||||
device_id: ('0' + selectedEntityItem.device_id.toString(16).toUpperCase()).slice(-2),
|
||||
type_id: ('000' + selectedEntityItem.type_id.toString(16).toUpperCase()).slice(-4)
|
||||
device_id: selectedEntityItem.device_id.toString(16).toUpperCase().slice(-2),
|
||||
type_id: selectedEntityItem.type_id.toString(16).toUpperCase().slice(-4)
|
||||
});
|
||||
}
|
||||
}, [open, selectedEntityItem]);
|
||||
@@ -123,8 +123,9 @@ const SettingsEntitiesDialog = ({
|
||||
name="device_id"
|
||||
label={LL.ID_OF(LL.DEVICE())}
|
||||
margin="normal"
|
||||
type="string"
|
||||
fullWidth
|
||||
value={editItem.device_id}
|
||||
value={editItem.device_id as string}
|
||||
onChange={updateFormValue}
|
||||
inputProps={{ style: { textTransform: 'uppercase' } }}
|
||||
InputProps={{ startAdornment: <InputAdornment position="start">0x</InputAdornment> }}
|
||||
@@ -157,7 +158,7 @@ const SettingsEntitiesDialog = ({
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
name="val_type"
|
||||
name="value_type"
|
||||
label="Value Type"
|
||||
value={editItem.value_type}
|
||||
variant="outlined"
|
||||
|
||||
@@ -344,8 +344,8 @@ export interface EntityItem {
|
||||
device_id: number | string;
|
||||
type_id: number | string;
|
||||
offset: number;
|
||||
factor: number;
|
||||
uom: number;
|
||||
factor?: number; // optional
|
||||
uom?: number; // optional
|
||||
value_type: number;
|
||||
value?: number; // optional
|
||||
writeable: boolean;
|
||||
|
||||
@@ -112,22 +112,20 @@ export const entityItemValidation = () =>
|
||||
}
|
||||
],
|
||||
device_id: [
|
||||
{ required: true, message: 'Device ID is required' },
|
||||
{
|
||||
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
|
||||
if (isNaN(parseInt(value, 16))) {
|
||||
callback('Must be a hex number');
|
||||
callback('Is required and must be in hex format');
|
||||
}
|
||||
callback();
|
||||
}
|
||||
}
|
||||
],
|
||||
type_id: [
|
||||
{ required: true, message: 'Type ID is required' },
|
||||
{
|
||||
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
|
||||
if (isNaN(parseInt(value, 16))) {
|
||||
callback('Must be a hex number');
|
||||
callback('Is required and must be in hex format');
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user