Merge pull request #429 from proddy/dev

updates to customization screen
This commit is contained in:
Proddy
2022-03-30 13:16:40 +02:00
committed by GitHub
3 changed files with 33 additions and 28 deletions

View File

@@ -158,6 +158,8 @@ const DashboardData: FC = () => {
} }
}; };
const isCmdOnly = (dv: DeviceValue) => dv.v === undefined && dv.c;
function formatValue(value: any, uom: number) { function formatValue(value: any, uom: number) {
if (value === undefined) { if (value === undefined) {
return ''; return '';
@@ -218,7 +220,7 @@ const DashboardData: FC = () => {
if (deviceValue) { if (deviceValue) {
return ( return (
<Dialog open={deviceValue !== undefined} onClose={() => setDeviceValue(undefined)}> <Dialog open={deviceValue !== undefined} onClose={() => setDeviceValue(undefined)}>
<DialogTitle>Change Value</DialogTitle> <DialogTitle>{isCmdOnly(deviceValue) ? 'Run Command' : 'Change Value'}</DialogTitle>
<DialogContent dividers> <DialogContent dividers>
{deviceValue.l && ( {deviceValue.l && (
<ValidatedTextField <ValidatedTextField
@@ -506,7 +508,6 @@ const DashboardData: FC = () => {
{hasMask(dv.n, DeviceEntityMask.DV_API_MQTT_EXCLUDE) && ( {hasMask(dv.n, DeviceEntityMask.DV_API_MQTT_EXCLUDE) && (
<CommentsDisabledOutlinedIcon color="primary" sx={{ fontSize: 12 }} /> <CommentsDisabledOutlinedIcon color="primary" sx={{ fontSize: 12 }} />
)} )}
{dv.v === undefined && dv.c && <PlayArrowIcon color="primary" sx={{ fontSize: 14 }} />}
</> </>
); );
@@ -519,21 +520,13 @@ const DashboardData: FC = () => {
<TableHead> <TableHead>
<TableRow> <TableRow>
<StyledTableCell padding="checkbox" style={{ width: 18 }}></StyledTableCell> <StyledTableCell padding="checkbox" style={{ width: 18 }}></StyledTableCell>
<StyledTableCell align="left">ENTITY NAME/COMMAND</StyledTableCell> <StyledTableCell align="left">ENTITY NAME</StyledTableCell>
<StyledTableCell align="right">VALUE</StyledTableCell> <StyledTableCell align="right">VALUE</StyledTableCell>
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{deviceData.data.map((dv, i) => ( {deviceData.data.map((dv, i) => (
<TableRow <StyledTableRow key={i} onClick={() => sendCommand(dv)}>
key={i}
onClick={() => sendCommand(dv)}
// sx={
// hasMask(dv.n, DeviceEntityMask.DV_FAVORITE)
// ? { backgroundColor: '#334900' }
// : { backgroundColor: 'black' }
// }
>
<StyledTableCell padding="checkbox"> <StyledTableCell padding="checkbox">
{dv.c && me.admin && !hasMask(dv.n, DeviceEntityMask.DV_READONLY) && ( {dv.c && me.admin && !hasMask(dv.n, DeviceEntityMask.DV_READONLY) && (
<IconButton size="small"> <IconButton size="small">
@@ -544,8 +537,10 @@ const DashboardData: FC = () => {
<StyledTableCell component="th" scope="row"> <StyledTableCell component="th" scope="row">
{renderNameCell(dv)} {renderNameCell(dv)}
</StyledTableCell> </StyledTableCell>
<StyledTableCell align="right">{formatValue(dv.v, dv.u)}</StyledTableCell> <StyledTableCell align="right">
</TableRow> {isCmdOnly(dv) ? <PlayArrowIcon color="primary" sx={{ fontSize: 14 }} /> : formatValue(dv.v, dv.u)}
</StyledTableCell>
</StyledTableRow>
))} ))}
</TableBody> </TableBody>
</Table> </Table>

View File

@@ -116,14 +116,27 @@ const SettingsCustomization: FC = () => {
return ( return (
<> <>
<Box mb={2} color="warning.main"> <Box mb={1} color="warning.main">
<Typography variant="body2"> Select a device and customize each entity using the options:
You can mark an entity as a favorite to be listed first in the Dashboard ( <Typography display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
<FavoriteBorderOutlinedIcon color="success" fontSize="small" />) ,or remove it entirely from the Dashboard ( &nbsp;
<VisibilityOffOutlinedIcon color="action" fontSize="small" />) ,or disable it's write operation ( <FavoriteBorderOutlinedIcon color="success" fontSize="small" />
<EditOffOutlinedIcon color="action" fontSize="small" />) or have it excluded from the MQTT and API outputs ( &nbsp;mark it as favorite to be listed at the top of the Dashboard
</Typography>
<Typography display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
&nbsp;
<VisibilityOffOutlinedIcon color="action" fontSize="small" />
&nbsp;hide from the Dashboard
</Typography>
<Typography display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
&nbsp;
<EditOffOutlinedIcon color="action" fontSize="small" />
&nbsp;make it read-only (if it has write operation available)
</Typography>
<Typography display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
&nbsp;
<CommentsDisabledOutlinedIcon color="action" fontSize="small" /> <CommentsDisabledOutlinedIcon color="action" fontSize="small" />
). &nbsp;excluded it from MQTT and API outputs
</Typography> </Typography>
</Box> </Box>
<ValidatedTextField <ValidatedTextField

View File

@@ -725,8 +725,9 @@ void EMSdevice::generate_values_web(JsonObject & output) {
} }
} else if (dv.type == DeviceValueType::BOOL) { } else if (dv.type == DeviceValueType::BOOL) {
JsonArray l = obj.createNestedArray("l"); JsonArray l = obj.createNestedArray("l");
l.add("off"); char result[10];
l.add("on"); l.add(Helpers::render_boolean(result, false));
l.add(Helpers::render_boolean(result, true));
} }
// add command help template // add command help template
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) { else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
@@ -861,10 +862,6 @@ void EMSdevice::mask_entity(const std::string & entity_id) {
for (auto & dv : devicevalues_) { for (auto & dv : devicevalues_) {
std::string entity = dv.tag < DeviceValueTAG::TAG_HC1 ? read_flash_string(dv.short_name) : tag_to_string(dv.tag) + "/" + read_flash_string(dv.short_name); std::string entity = dv.tag < DeviceValueTAG::TAG_HC1 ? read_flash_string(dv.short_name) : tag_to_string(dv.tag) + "/" + read_flash_string(dv.short_name);
if (entity == entity_id.substr(2)) { if (entity == entity_id.substr(2)) {
#if defined(EMSESP_USE_SERIAL)
Serial.print("mask_entity() Removing Visible for device value: ");
Serial.println(read_flash_string(dv.full_name).c_str());
#endif
dv.state = (dv.state & 0x0F) | (flag << 4); // set state high bits to flag, turn off active and ha flags dv.state = (dv.state & 0x0F) | (flag << 4); // set state high bits to flag, turn off active and ha flags
return; return;
} }
@@ -1217,7 +1214,7 @@ bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, c
return has_values; return has_values;
} }
// remove the Home Assistant configs for each device value/entity if its not visible or active // remove the Home Assistant configs for each device value/entity if its not visible or active or marked as read-only
// this is called when an MQTT publish is done via an EMS Device in emsesp.cpp::publish_device_values() // this is called when an MQTT publish is done via an EMS Device in emsesp.cpp::publish_device_values()
void EMSdevice::mqtt_ha_entity_config_remove() { void EMSdevice::mqtt_ha_entity_config_remove() {
for (auto & dv : devicevalues_) { for (auto & dv : devicevalues_) {