Skip to content

Commit

Permalink
Merge pull request #413 from proddy/dev
Browse files Browse the repository at this point in the history
rename exclude_entities to masked_entities - fixes for #411
  • Loading branch information
proddy authored Mar 27, 2022
2 parents b031e1a + 3853c6c commit 6c3d33d
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 233 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- sync time with thermostat [#386](https://github.com/emsesp/EMS-ESP32/issues/386), [#408](https://github.com/emsesp/EMS-ESP32/issues/408)
- set mode has immediate effect [#395](https://github.com/emsesp/EMS-ESP32/issues/395)
- min/max in web value setting
- Extend customization to select if an entity is to be shown in the WebUI or forced as read-only [#317](https://github.com/emsesp/EMS-ESP32/issues/317)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion interface/src/framework/security/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const UserForm: FC<UserFormProps> = ({ creating, validator, user, setUser, onDon
};

return (
<Dialog onClose={onCancelEditing} aria-labelledby="user-form-dialog-title" open={!!user} fullWidth maxWidth="sm">
<Dialog onClose={onCancelEditing} open={!!user} fullWidth maxWidth="sm">
{user && (
<>
<DialogTitle id="user-form-dialog-title">{creating ? 'Add' : 'Modify'} User</DialogTitle>
Expand Down
13 changes: 8 additions & 5 deletions interface/src/project/DashboardData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
ListItem,
ListItemText,
Grid,
useMediaQuery
useMediaQuery,
Tooltip
} from '@mui/material';

import TableCell, { tableCellClasses } from '@mui/material/TableCell';
Expand Down Expand Up @@ -524,8 +525,10 @@ const DashboardData: FC = () => {
<StyledTableRow key={i} onClick={() => sendCommand(dv)}>
<StyledTableCell padding="checkbox">
{dv.c && me.admin && (
<IconButton size="small" aria-label="Edit">
<EditIcon color="primary" fontSize="small" />
<IconButton size="small">
<Tooltip title="Change value...">
<EditIcon color="primary" fontSize="small" />
</Tooltip>
</IconButton>
)}
</StyledTableCell>
Expand Down Expand Up @@ -569,7 +572,7 @@ const DashboardData: FC = () => {
<StyledTableRow key={sensor_data.n} onClick={() => updateSensor(sensor_data)}>
<StyledTableCell padding="checkbox">
{me.admin && (
<IconButton edge="start" size="small" aria-label="Edit">
<IconButton edge="start" size="small">
<EditIcon color="primary" fontSize="small" />
</IconButton>
)}
Expand Down Expand Up @@ -605,7 +608,7 @@ const DashboardData: FC = () => {
<StyledTableRow key={analog_data.i} onClick={() => updateAnalog(analog_data)}>
<StyledTableCell padding="checkbox">
{me.admin && (
<IconButton edge="start" size="small" aria-label="Edit">
<IconButton edge="start" size="small">
<EditIcon color="primary" fontSize="small" />
</IconButton>
)}
Expand Down
140 changes: 98 additions & 42 deletions interface/src/project/SettingsCustomization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
Dialog,
DialogActions,
DialogContent,
DialogTitle
DialogTitle,
ToggleButton,
ToggleButtonGroup,
Tooltip
} from '@mui/material';

import TableCell, { tableCellClasses } from '@mui/material/TableCell';
Expand All @@ -22,8 +25,11 @@ import { styled } from '@mui/material/styles';
import { useSnackbar } from 'notistack';

import SaveIcon from '@mui/icons-material/Save';
import CloseIcon from '@mui/icons-material/Close';
import CancelIcon from '@mui/icons-material/Cancel';
import EditOffOutlinedIcon from '@mui/icons-material/EditOffOutlined';
import FavoriteBorderOutlinedIcon from '@mui/icons-material/FavoriteBorderOutlined';
import VisibilityOffOutlinedIcon from '@mui/icons-material/VisibilityOffOutlined';
import CommentsDisabledOutlinedIcon from '@mui/icons-material/CommentsDisabledOutlined';
import SettingsBackupRestoreIcon from '@mui/icons-material/SettingsBackupRestore';

import { ButtonRow, FormLoader, ValidatedTextField, SectionContent } from '../components';
Expand Down Expand Up @@ -53,6 +59,7 @@ const SettingsCustomization: FC = () => {
const [errorMessage, setErrorMessage] = useState<string>();
const [selectedDevice, setSelectedDevice] = useState<number>(0);
const [confirmReset, setConfirmReset] = useState<boolean>(false);
const [masks, setMasks] = useState(() => ['1']);

const fetchDevices = useCallback(async () => {
try {
Expand Down Expand Up @@ -110,7 +117,8 @@ const SettingsCustomization: FC = () => {
<>
<Box color="warning.main">
<Typography variant="body2">
Customize which entities to exclude from all all services (MQTT, API). This will have immediate effect.
You can mark an entity as a favorite to be listed first in the Web Dashboard, or remove it from the
Dashboard, or disable it's write operation or exclude it from the MQTT and API outputs.
</Typography>
</Box>
<ValidatedTextField
Expand Down Expand Up @@ -138,11 +146,13 @@ const SettingsCustomization: FC = () => {

const saveCustomization = async () => {
if (deviceEntities && selectedDevice) {
const exclude_entities = deviceEntities.filter((de) => de.x).map((new_de) => "07" + new_de.s);
const masked_entities = deviceEntities
.filter((de) => de.m)
.map((new_de) => new_de.m.toString(16).padStart(2, '0') + new_de.s);
try {
const response = await EMSESP.writeExcludeEntities({
const response = await EMSESP.writeMaskedEntities({
id: selectedDevice,
entity_ids: exclude_entities
entity_ids: masked_entities
});
if (response.status === 200) {
enqueueSnackbar('Customization saved', { variant: 'success' });
Expand All @@ -160,48 +170,94 @@ const SettingsCustomization: FC = () => {
return;
}

const toggleDeviceEntity = (id: number) => {
setDeviceEntities(
deviceEntities.map((o) => {
if (o.i === id) {
return { ...o, x: !o.x };
}
return o;
})
);
const setMask = (de: DeviceEntity, newMask: string[]) => {
var new_mask = 0;
if (newMask.includes('1')) {
new_mask |= 1;
}
if (newMask.includes('2')) {
new_mask |= 2;
}
if (newMask.includes('4')) {
new_mask |= 4;
}
if (newMask.includes('8')) {
new_mask |= 8;
}

de.m = new_mask;
setMasks(newMask);
};

const getMask = (de: DeviceEntity) => {
var new_masks = [];
if ((de.m & 1) === 1) {
new_masks.push('1');
}
if ((de.m & 2) === 2) {
new_masks.push('2');
}
if ((de.m & 4) === 4) {
new_masks.push('4');
}
if ((de.m & 8) === 8) {
new_masks.push('8');
}

return new_masks;
};

return (
<>
<Table size="small">
<TableHead>
<TableRow>
<Table size="small">
<TableHead>
<TableRow>
<StyledTableCell align="center">OPTIONS</StyledTableCell>
<StyledTableCell align="left">ENTITY NAME (CODE)</StyledTableCell>
<StyledTableCell align="right">VALUE</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>
{deviceEntities.map((de) => (
<TableRow key={de.i}>
<StyledTableCell padding="checkbox">
<ToggleButtonGroup
size="small"
color="error"
value={getMask(de)}
onChange={(event, mask) => {
setMask(de, mask);
}}
>
<ToggleButton value="8" color="success" disabled={(de.m & 1) !== 0}>
<Tooltip title="Favorite">
<FavoriteBorderOutlinedIcon fontSize="small" />
</Tooltip>
</ToggleButton>
<ToggleButton value="4" disabled={!de.w}>
<Tooltip title="Force read-only">
<EditOffOutlinedIcon fontSize="small" />
</Tooltip>
</ToggleButton>
<ToggleButton value="2">
<Tooltip title="Exclude in MQTT and API">
<CommentsDisabledOutlinedIcon fontSize="small" />
</Tooltip>
</ToggleButton>
<ToggleButton value="1">
<Tooltip title="Don't show Web Dashboard">
<VisibilityOffOutlinedIcon fontSize="small" />
</Tooltip>
</ToggleButton>
</ToggleButtonGroup>
</StyledTableCell>
<StyledTableCell>
({deviceEntities.reduce((a, v) => (v.x ? a + 1 : a), 0)}/{deviceEntities.length})
{de.n}&nbsp;({de.s})
</StyledTableCell>
<StyledTableCell align="left">ENTITY NAME</StyledTableCell>
<StyledTableCell>CODE</StyledTableCell>
<StyledTableCell align="right">VALUE</StyledTableCell>
<StyledTableCell align="right">{formatValue(de.v)}</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>
{deviceEntities.map((de) => (
<TableRow
key={de.i}
onClick={() => toggleDeviceEntity(de.i)}
sx={de.x ? { backgroundColor: '#f8696b' } : { backgroundColor: 'black' }}
>
<StyledTableCell padding="checkbox">{de.x && <CloseIcon fontSize="small" />}</StyledTableCell>
<StyledTableCell component="th" scope="row">
{de.n}
</StyledTableCell>
<StyledTableCell>{de.s}</StyledTableCell>
<StyledTableCell align="right">{formatValue(de.v)}</StyledTableCell>
</TableRow>
))}
</TableBody>
</Table>
</>
))}
</TableBody>
</Table>
);
};

Expand Down
6 changes: 3 additions & 3 deletions interface/src/project/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
DeviceData,
DeviceEntity,
UniqueID,
ExcludeEntities,
MaskedEntities,
WriteValue,
WriteSensor,
WriteAnalog,
Expand Down Expand Up @@ -63,8 +63,8 @@ export function readDeviceEntities(unique_id: UniqueID): AxiosPromise<DeviceEnti
return AXIOS_BIN.post('/deviceEntities', unique_id);
}

export function writeExcludeEntities(excludeEntities: ExcludeEntities): AxiosPromise<void> {
return AXIOS.post('/excludeEntities', excludeEntities);
export function writeMaskedEntities(maskedEntities: MaskedEntities): AxiosPromise<void> {
return AXIOS.post('/maskedEntities', maskedEntities);
}

export function writeValue(writevalue: WriteValue): AxiosPromise<void> {
Expand Down
5 changes: 3 additions & 2 deletions interface/src/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ export interface DeviceEntity {
v?: any; // value, in any format
n: string; // name
s: string; // shortname
x: boolean; // excluded flag
m: number; // mask
w?: boolean; // writeable
i: number; // unique id
}

export interface ExcludeEntities {
export interface MaskedEntities {
id: number;
entity_ids: string[];
}
Expand Down
Loading

0 comments on commit 6c3d33d

Please sign in to comment.