mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
Add custom variables #1423
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import AddIcon from '@mui/icons-material/Add';
|
||||
import CancelIcon from '@mui/icons-material/Cancel';
|
||||
import RefreshIcon from '@mui/icons-material/Refresh';
|
||||
import EditOutlinedIcon from '@mui/icons-material/EditOutlined';
|
||||
import WarningIcon from '@mui/icons-material/Warning';
|
||||
import { Button, Typography, Box } from '@mui/material';
|
||||
@@ -44,6 +45,7 @@ const SettingsCustomEntities: FC = () => {
|
||||
function hasEntityChanged(ei: EntityItem) {
|
||||
return (
|
||||
ei.id !== ei.o_id ||
|
||||
ei.ram !== ei.o_ram ||
|
||||
(ei?.name || '') !== (ei?.o_name || '') ||
|
||||
ei.device_id !== ei.o_device_id ||
|
||||
ei.type_id !== ei.o_type_id ||
|
||||
@@ -52,7 +54,8 @@ const SettingsCustomEntities: FC = () => {
|
||||
ei.factor !== ei.o_factor ||
|
||||
ei.value_type !== ei.o_value_type ||
|
||||
ei.writeable !== ei.o_writeable ||
|
||||
ei.deleted !== ei.o_deleted
|
||||
ei.deleted !== ei.o_deleted ||
|
||||
(ei.value || '') !== (ei.o_value || '')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,6 +122,7 @@ const SettingsCustomEntities: FC = () => {
|
||||
.filter((ei) => !ei.deleted)
|
||||
.map((condensed_ei) => ({
|
||||
id: condensed_ei.id,
|
||||
ram: condensed_ei.ram,
|
||||
name: condensed_ei.name,
|
||||
device_id: condensed_ei.device_id,
|
||||
type_id: condensed_ei.type_id,
|
||||
@@ -126,7 +130,8 @@ const SettingsCustomEntities: FC = () => {
|
||||
factor: condensed_ei.factor,
|
||||
uom: condensed_ei.uom,
|
||||
writeable: condensed_ei.writeable,
|
||||
value_type: condensed_ei.value_type
|
||||
value_type: condensed_ei.value_type,
|
||||
value: condensed_ei.value
|
||||
}))
|
||||
})
|
||||
.then(() => {
|
||||
@@ -174,14 +179,16 @@ const SettingsCustomEntities: FC = () => {
|
||||
setSelectedEntityItem({
|
||||
id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100),
|
||||
name: '',
|
||||
device_id: '',
|
||||
type_id: '',
|
||||
ram: 0,
|
||||
device_id: '0',
|
||||
type_id: '0',
|
||||
offset: 0,
|
||||
factor: 1,
|
||||
uom: 0,
|
||||
value_type: 0,
|
||||
writeable: false,
|
||||
deleted: false
|
||||
deleted: false,
|
||||
value: ''
|
||||
});
|
||||
setDialogOpen(true);
|
||||
};
|
||||
@@ -213,7 +220,7 @@ const SettingsCustomEntities: FC = () => {
|
||||
<HeaderCell stiff>{LL.ID_OF(LL.DEVICE())}</HeaderCell>
|
||||
<HeaderCell stiff>{LL.ID_OF(LL.TYPE(1))}</HeaderCell>
|
||||
<HeaderCell stiff>{LL.OFFSET()}</HeaderCell>
|
||||
<HeaderCell stiff>{LL.VALUE(1) + ' ' + LL.TYPE(1)}</HeaderCell>
|
||||
<HeaderCell stiff>{LL.TYPE(1)}</HeaderCell>
|
||||
<HeaderCell stiff>{LL.VALUE(1)}</HeaderCell>
|
||||
</HeaderRow>
|
||||
</Header>
|
||||
@@ -224,10 +231,10 @@ const SettingsCustomEntities: FC = () => {
|
||||
{ei.name}
|
||||
{ei.writeable && <EditOutlinedIcon color="primary" sx={{ fontSize: 12 }} />}
|
||||
</Cell>
|
||||
<Cell>{showHex(ei.device_id as number, 2)}</Cell>
|
||||
<Cell>{showHex(ei.type_id as number, 3)}</Cell>
|
||||
<Cell>{ei.offset}</Cell>
|
||||
<Cell>{DeviceValueTypeNames[ei.value_type]}</Cell>
|
||||
<Cell>{ei.ram === 1 ? '' : showHex(ei.device_id as number, 2)}</Cell>
|
||||
<Cell>{ei.ram === 1 ? '' : showHex(ei.type_id as number, 3)}</Cell>
|
||||
<Cell>{ei.ram === 1 ? '' : ei.offset}</Cell>
|
||||
<Cell>{ei.ram === 1 ? 'RAM' : DeviceValueTypeNames[ei.value_type]}</Cell>
|
||||
<Cell>{formatValue(ei.value, ei.uom)}</Cell>
|
||||
</Row>
|
||||
))}
|
||||
@@ -278,7 +285,10 @@ const SettingsCustomEntities: FC = () => {
|
||||
</Box>
|
||||
<Box flexWrap="nowrap" whiteSpace="nowrap">
|
||||
<ButtonRow>
|
||||
<Button startIcon={<AddIcon />} variant="outlined" color="secondary" onClick={addEntityItem}>
|
||||
<Button startIcon={<RefreshIcon />} variant="outlined" color="secondary" onClick={fetchEntities}>
|
||||
{LL.REFRESH()}
|
||||
</Button>
|
||||
<Button startIcon={<AddIcon />} variant="outlined" color="primary" onClick={addEntityItem}>
|
||||
{LL.ADD(0)}
|
||||
</Button>
|
||||
</ButtonRow>
|
||||
|
||||
@@ -100,7 +100,7 @@ const SettingsCustomEntitiesDialog = ({
|
||||
<Box flexWrap="nowrap" whiteSpace="nowrap" />
|
||||
</Box>
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={8}>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="name"
|
||||
@@ -111,122 +111,154 @@ const SettingsCustomEntitiesDialog = ({
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4} mt={3}>
|
||||
<BlockFormControlLabel
|
||||
control={<Checkbox checked={editItem.writeable} onChange={updateFormValue} name="writeable" />}
|
||||
label={LL.WRITEABLE()}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="device_id"
|
||||
label={LL.ID_OF(LL.DEVICE())}
|
||||
margin="normal"
|
||||
type="string"
|
||||
fullWidth
|
||||
value={editItem.device_id as string}
|
||||
onChange={updateFormValue}
|
||||
inputProps={{ style: { textTransform: 'uppercase' } }}
|
||||
InputProps={{ startAdornment: <InputAdornment position="start">0x</InputAdornment> }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="type_id"
|
||||
label={LL.ID_OF(LL.TYPE(1))}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
value={editItem.type_id}
|
||||
onChange={updateFormValue}
|
||||
inputProps={{ style: { textTransform: 'uppercase' } }}
|
||||
InputProps={{ startAdornment: <InputAdornment position="start">0x</InputAdornment> }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="offset"
|
||||
label={LL.OFFSET()}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
type="number"
|
||||
value={editItem.offset}
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="value_type"
|
||||
name="ram"
|
||||
label={LL.VALUE(1) + ' ' + LL.TYPE(1)}
|
||||
value={editItem.value_type}
|
||||
value={editItem.ram}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
select
|
||||
>
|
||||
<MenuItem value={DeviceValueType.BOOL}>BOOL</MenuItem>
|
||||
<MenuItem value={DeviceValueType.INT}>INT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.UINT}>UINT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.SHORT}>SHORT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.USHORT}>USHORT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.ULONG}>ULONG</MenuItem>
|
||||
<MenuItem value={DeviceValueType.TIME}>TIME</MenuItem>
|
||||
<MenuItem value={DeviceValueType.STRING}>RAW</MenuItem>
|
||||
<MenuItem value={0}>EMS-{LL.VALUE(1)}</MenuItem>
|
||||
<MenuItem value={1}>RAM-{LL.VALUE(1)}</MenuItem>
|
||||
</TextField>
|
||||
</Grid>
|
||||
|
||||
{editItem.value_type !== DeviceValueType.BOOL && editItem.value_type !== DeviceValueType.STRING && (
|
||||
<>
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="factor"
|
||||
label={LL.FACTOR()}
|
||||
value={editItem.factor}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
type="number"
|
||||
inputProps={{ step: '0.001' }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="uom"
|
||||
label={LL.UNIT()}
|
||||
value={editItem.uom}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
onChange={updateFormValue}
|
||||
select
|
||||
>
|
||||
{DeviceValueUOM_s.map((val, i) => (
|
||||
<MenuItem key={i} value={i}>
|
||||
{val}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
</Grid>
|
||||
</>
|
||||
)}
|
||||
{editItem.value_type === DeviceValueType.STRING && (
|
||||
{editItem.ram === 1 && (
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="factor"
|
||||
label="Bytes"
|
||||
value={editItem.factor}
|
||||
name="value"
|
||||
label={LL.STARTVALUE()}
|
||||
value={editItem.value}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
type="number"
|
||||
inputProps={{ min: '1', max: '27', step: '1' }}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
{editItem.ram === 0 && (
|
||||
<>
|
||||
<Grid item xs={4} mt={3}>
|
||||
<BlockFormControlLabel
|
||||
control={<Checkbox checked={editItem.writeable} onChange={updateFormValue} name="writeable" />}
|
||||
label={LL.WRITEABLE()}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="device_id"
|
||||
label={LL.ID_OF(LL.DEVICE())}
|
||||
margin="normal"
|
||||
type="string"
|
||||
fullWidth
|
||||
value={editItem.device_id as string}
|
||||
onChange={updateFormValue}
|
||||
inputProps={{ style: { textTransform: 'uppercase' } }}
|
||||
InputProps={{ startAdornment: <InputAdornment position="start">0x</InputAdornment> }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="type_id"
|
||||
label={LL.ID_OF(LL.TYPE(1))}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
value={editItem.type_id}
|
||||
onChange={updateFormValue}
|
||||
inputProps={{ style: { textTransform: 'uppercase' } }}
|
||||
InputProps={{ startAdornment: <InputAdornment position="start">0x</InputAdornment> }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="offset"
|
||||
label={LL.OFFSET()}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
type="number"
|
||||
value={editItem.offset}
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="value_type"
|
||||
label={LL.VALUE(1) + ' ' + LL.TYPE(1)}
|
||||
value={editItem.value_type}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
select
|
||||
>
|
||||
<MenuItem value={DeviceValueType.BOOL}>BOOL</MenuItem>
|
||||
<MenuItem value={DeviceValueType.INT}>INT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.UINT}>UINT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.SHORT}>SHORT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.USHORT}>USHORT</MenuItem>
|
||||
<MenuItem value={DeviceValueType.ULONG}>ULONG</MenuItem>
|
||||
<MenuItem value={DeviceValueType.TIME}>TIME</MenuItem>
|
||||
<MenuItem value={DeviceValueType.STRING}>RAW</MenuItem>
|
||||
</TextField>
|
||||
</Grid>
|
||||
|
||||
{editItem.value_type !== DeviceValueType.BOOL && editItem.value_type !== DeviceValueType.STRING && (
|
||||
<>
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="factor"
|
||||
label={LL.FACTOR()}
|
||||
value={editItem.factor}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
type="number"
|
||||
inputProps={{ step: '0.001' }}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="uom"
|
||||
label={LL.UNIT()}
|
||||
value={editItem.uom}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
onChange={updateFormValue}
|
||||
select
|
||||
>
|
||||
{DeviceValueUOM_s.map((val, i) => (
|
||||
<MenuItem key={i} value={i}>
|
||||
{val}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
</Grid>
|
||||
</>
|
||||
)}
|
||||
{editItem.value_type === DeviceValueType.STRING && editItem.device_id !== '0' && (
|
||||
<Grid item xs={4}>
|
||||
<TextField
|
||||
name="factor"
|
||||
label="Bytes"
|
||||
value={editItem.factor}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
type="number"
|
||||
inputProps={{ min: '1', max: '27', step: '1' }}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Grid>
|
||||
</DialogContent>
|
||||
|
||||
|
||||
@@ -325,6 +325,7 @@ export enum ScheduleFlag {
|
||||
|
||||
export interface EntityItem {
|
||||
id: number; // unique number
|
||||
ram: number;
|
||||
name: string;
|
||||
device_id: number | string;
|
||||
type_id: number | string;
|
||||
@@ -336,6 +337,7 @@ export interface EntityItem {
|
||||
writeable: boolean;
|
||||
deleted?: boolean;
|
||||
o_id?: number;
|
||||
o_ram?: number;
|
||||
o_name?: string;
|
||||
o_device_id?: number | string;
|
||||
o_type_id?: number | string;
|
||||
@@ -345,6 +347,7 @@ export interface EntityItem {
|
||||
o_value_type?: number;
|
||||
o_deleted?: boolean;
|
||||
o_writeable?: boolean;
|
||||
o_value?: any;
|
||||
}
|
||||
|
||||
export interface Entities {
|
||||
@@ -397,6 +400,6 @@ export const DeviceValueTypeNames = [
|
||||
'ULONG',
|
||||
'TIME',
|
||||
'ENUM',
|
||||
'STRING',
|
||||
'RAW',
|
||||
'CMD'
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user