This commit is contained in:
Proddy
2023-04-24 16:50:28 +02:00
parent 9553161b07
commit 005485188f
4 changed files with 19 additions and 22 deletions

View File

@@ -187,30 +187,28 @@ const SettingsEntities: FC = () => {
setSelectedEntityItem({ setSelectedEntityItem({
id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100), id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100),
name: '', name: '',
device_id: 11, device_id: '',
type_id: 0, type_id: '',
offset: 0, offset: 0,
factor: 1, factor: 1,
uom: 0, uom: 0,
value_type: 2, value_type: 0,
writeable: false, writeable: false,
deleted: false deleted: false
}); });
setDialogOpen(true); setDialogOpen(true);
}; };
function formatValue(value: any, uom: number) { function formatValue(value: any, uom: any) {
if (value === undefined) { return value === undefined || uom === undefined
return ''; ? ''
} : new Intl.NumberFormat().format(value) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
return new Intl.NumberFormat().format(value) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
} }
function showHex(value: number, digit: number) { function showHex(value: number, digit: number) {
if (digit === 4) { return digit === 4
return '0x' + ('000' + value.toString(16).toUpperCase()).slice(-4); ? '0x' + ('000' + value.toString(16).toUpperCase()).slice(-4)
} : '0x' + ('0' + value.toString(16).toUpperCase()).slice(-2);
return '0x' + ('0' + value.toString(16).toUpperCase()).slice(-2);
} }
const renderEntity = () => { const renderEntity = () => {

View File

@@ -59,8 +59,8 @@ const SettingsEntitiesDialog = ({
// convert to hex strings straight away // convert to hex strings straight away
setEditItem({ setEditItem({
...selectedEntityItem, ...selectedEntityItem,
device_id: ('0' + selectedEntityItem.device_id.toString(16).toUpperCase()).slice(-2), device_id: selectedEntityItem.device_id.toString(16).toUpperCase().slice(-2),
type_id: ('000' + selectedEntityItem.type_id.toString(16).toUpperCase()).slice(-4) type_id: selectedEntityItem.type_id.toString(16).toUpperCase().slice(-4)
}); });
} }
}, [open, selectedEntityItem]); }, [open, selectedEntityItem]);
@@ -123,8 +123,9 @@ const SettingsEntitiesDialog = ({
name="device_id" name="device_id"
label={LL.ID_OF(LL.DEVICE())} label={LL.ID_OF(LL.DEVICE())}
margin="normal" margin="normal"
type="string"
fullWidth fullWidth
value={editItem.device_id} value={editItem.device_id as string}
onChange={updateFormValue} onChange={updateFormValue}
inputProps={{ style: { textTransform: 'uppercase' } }} inputProps={{ style: { textTransform: 'uppercase' } }}
InputProps={{ startAdornment: <InputAdornment position="start">0x</InputAdornment> }} InputProps={{ startAdornment: <InputAdornment position="start">0x</InputAdornment> }}
@@ -157,7 +158,7 @@ const SettingsEntitiesDialog = ({
</Grid> </Grid>
<Grid item xs={4}> <Grid item xs={4}>
<ValidatedTextField <ValidatedTextField
name="val_type" name="value_type"
label="Value Type" label="Value Type"
value={editItem.value_type} value={editItem.value_type}
variant="outlined" variant="outlined"

View File

@@ -344,8 +344,8 @@ export interface EntityItem {
device_id: number | string; device_id: number | string;
type_id: number | string; type_id: number | string;
offset: number; offset: number;
factor: number; factor?: number; // optional
uom: number; uom?: number; // optional
value_type: number; value_type: number;
value?: number; // optional value?: number; // optional
writeable: boolean; writeable: boolean;

View File

@@ -112,22 +112,20 @@ export const entityItemValidation = () =>
} }
], ],
device_id: [ device_id: [
{ required: true, message: 'Device ID is required' },
{ {
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) { validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
if (isNaN(parseInt(value, 16))) { if (isNaN(parseInt(value, 16))) {
callback('Must be a hex number'); callback('Is required and must be in hex format');
} }
callback(); callback();
} }
} }
], ],
type_id: [ type_id: [
{ required: true, message: 'Type ID is required' },
{ {
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) { validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
if (isNaN(parseInt(value, 16))) { if (isNaN(parseInt(value, 16))) {
callback('Must be a hex number'); callback('Is required and must be in hex format');
} }
callback(); callback();
} }