mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
use mask flags
This commit is contained in:
@@ -110,7 +110,7 @@ const SettingsCustomization: FC = () => {
|
|||||||
<>
|
<>
|
||||||
<Box color="warning.main">
|
<Box color="warning.main">
|
||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
Customize which entities to exclude from all all services (MQTT, API). This will have immediate effect.
|
Customize which entities to exclude. This will have immediate effect on all services including MQTT and API.
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
@@ -138,11 +138,13 @@ const SettingsCustomization: FC = () => {
|
|||||||
|
|
||||||
const saveCustomization = async () => {
|
const saveCustomization = async () => {
|
||||||
if (deviceEntities && selectedDevice) {
|
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 {
|
try {
|
||||||
const response = await EMSESP.writeExcludeEntities({
|
const response = await EMSESP.writeMaskedEntities({
|
||||||
id: selectedDevice,
|
id: selectedDevice,
|
||||||
entity_ids: exclude_entities
|
entity_ids: masked_entities
|
||||||
});
|
});
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
enqueueSnackbar('Customization saved', { variant: 'success' });
|
enqueueSnackbar('Customization saved', { variant: 'success' });
|
||||||
@@ -160,11 +162,11 @@ const SettingsCustomization: FC = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleDeviceEntity = (id: number) => {
|
const toggleDeviceEntity = (id: number, mask: number) => {
|
||||||
setDeviceEntities(
|
setDeviceEntities(
|
||||||
deviceEntities.map((o) => {
|
deviceEntities.map((o) => {
|
||||||
if (o.i === id) {
|
if (o.i === id) {
|
||||||
return { ...o, x: !o.x };
|
return { ...o, m: mask ^ o.m };
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
})
|
})
|
||||||
@@ -177,7 +179,7 @@ const SettingsCustomization: FC = () => {
|
|||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<StyledTableCell>
|
<StyledTableCell>
|
||||||
({deviceEntities.reduce((a, v) => (v.x ? a + 1 : a), 0)}/{deviceEntities.length})
|
({deviceEntities.reduce((a, de) => (de.m === 7 ? a + 1 : a), 0)}/{deviceEntities.length})
|
||||||
</StyledTableCell>
|
</StyledTableCell>
|
||||||
<StyledTableCell align="left">ENTITY NAME</StyledTableCell>
|
<StyledTableCell align="left">ENTITY NAME</StyledTableCell>
|
||||||
<StyledTableCell>CODE</StyledTableCell>
|
<StyledTableCell>CODE</StyledTableCell>
|
||||||
@@ -188,10 +190,10 @@ const SettingsCustomization: FC = () => {
|
|||||||
{deviceEntities.map((de) => (
|
{deviceEntities.map((de) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={de.i}
|
key={de.i}
|
||||||
onClick={() => toggleDeviceEntity(de.i)}
|
onClick={() => toggleDeviceEntity(de.i, 7)}
|
||||||
sx={de.x ? { backgroundColor: '#f8696b' } : { backgroundColor: 'black' }}
|
sx={de.m === 7 ? { backgroundColor: '#f8696b' } : { backgroundColor: 'black' }}
|
||||||
>
|
>
|
||||||
<StyledTableCell padding="checkbox">{de.x && <CloseIcon fontSize="small" />}</StyledTableCell>
|
<StyledTableCell padding="checkbox">{de.m === 7 && <CloseIcon fontSize="small" />}</StyledTableCell>
|
||||||
<StyledTableCell component="th" scope="row">
|
<StyledTableCell component="th" scope="row">
|
||||||
{de.n}
|
{de.n}
|
||||||
</StyledTableCell>
|
</StyledTableCell>
|
||||||
|
|||||||
Reference in New Issue
Block a user