mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
add writeable checkbox to custom entities
This commit is contained in:
@@ -320,7 +320,8 @@ const de: Translation = {
|
|||||||
SCHEDULE_TIMER_2: 'jede Minute',
|
SCHEDULE_TIMER_2: 'jede Minute',
|
||||||
SCHEDULE_TIMER_3: 'jede Stunde',
|
SCHEDULE_TIMER_3: 'jede Stunde',
|
||||||
CUSTOM_ENTITIES: 'Individuelle Entitäten',
|
CUSTOM_ENTITIES: 'Individuelle Entitäten',
|
||||||
ENTITIES_HELP_1: 'Abfrage von Werten auf dem EMS-Bus'
|
ENTITIES_HELP_1: 'Abfrage von Werten auf dem EMS-Bus',
|
||||||
|
WRITEABLE: 'Schreibbar'
|
||||||
};
|
};
|
||||||
|
|
||||||
export default de;
|
export default de;
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ const en: Translation = {
|
|||||||
SCHEDULE_TIMER_2: 'every minute',
|
SCHEDULE_TIMER_2: 'every minute',
|
||||||
SCHEDULE_TIMER_3: 'every hour',
|
SCHEDULE_TIMER_3: 'every hour',
|
||||||
CUSTOM_ENTITIES: 'Custom entities',
|
CUSTOM_ENTITIES: 'Custom entities',
|
||||||
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus'
|
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus',
|
||||||
|
WRITEABLE: 'Writeable'
|
||||||
};
|
};
|
||||||
|
|
||||||
export default en;
|
export default en;
|
||||||
|
|||||||
@@ -319,8 +319,9 @@ const fr: Translation = {
|
|||||||
SCHEDULE_TIMER_1: 'on startup', // TODO translate
|
SCHEDULE_TIMER_1: 'on startup', // TODO translate
|
||||||
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
||||||
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
||||||
CUSTOM_ENTITIES: 'Custom entities',
|
CUSTOM_ENTITIES: 'Custom entities', // TODO translate
|
||||||
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus'
|
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus', // TODO translate
|
||||||
|
WRITEABLE: 'Writeable' // TODO translate
|
||||||
};
|
};
|
||||||
|
|
||||||
export default fr;
|
export default fr;
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ const nl: Translation = {
|
|||||||
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
||||||
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
||||||
CUSTOM_ENTITIES: 'Custom entities',
|
CUSTOM_ENTITIES: 'Custom entities',
|
||||||
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus'
|
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus',
|
||||||
|
WRITEABLE: 'Writeable' // TODO translate
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nl;
|
export default nl;
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ const no: Translation = {
|
|||||||
SCHEDULE_TIMER_2: 'hvert minutt',
|
SCHEDULE_TIMER_2: 'hvert minutt',
|
||||||
SCHEDULE_TIMER_3: 'hver time',
|
SCHEDULE_TIMER_3: 'hver time',
|
||||||
CUSTOM_ENTITIES: 'Custom entities',
|
CUSTOM_ENTITIES: 'Custom entities',
|
||||||
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus'
|
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus',
|
||||||
|
WRITEABLE: 'Writeable' // TODO translate
|
||||||
};
|
};
|
||||||
|
|
||||||
export default no;
|
export default no;
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ const pl: BaseTranslation = {
|
|||||||
SCHEDULE_TIMER_2: 'co minutę',
|
SCHEDULE_TIMER_2: 'co minutę',
|
||||||
SCHEDULE_TIMER_3: 'co godzinę',
|
SCHEDULE_TIMER_3: 'co godzinę',
|
||||||
CUSTOM_ENTITIES: 'Custom entities',
|
CUSTOM_ENTITIES: 'Custom entities',
|
||||||
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus'
|
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus',
|
||||||
|
WRITEABLE: 'Writeable' // TODO translate
|
||||||
};
|
};
|
||||||
|
|
||||||
export default pl;
|
export default pl;
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ const sv: Translation = {
|
|||||||
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
||||||
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
||||||
CUSTOM_ENTITIES: 'Custom entities',
|
CUSTOM_ENTITIES: 'Custom entities',
|
||||||
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus'
|
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus',
|
||||||
|
WRITEABLE: 'Writeable' // TODO translate
|
||||||
};
|
};
|
||||||
|
|
||||||
export default sv;
|
export default sv;
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ const tr: Translation = {
|
|||||||
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
SCHEDULE_TIMER_2: 'every minute', // TODO translate
|
||||||
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
SCHEDULE_TIMER_3: 'every hour', // TODO translate
|
||||||
CUSTOM_ENTITIES: 'Custom entities',
|
CUSTOM_ENTITIES: 'Custom entities',
|
||||||
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus'
|
ENTITIES_HELP_1: 'Fetch custom entities from the EMS-bus',
|
||||||
|
WRITEABLE: 'Writeable' // TODO translate
|
||||||
};
|
};
|
||||||
|
|
||||||
export default tr;
|
export default tr;
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import {
|
|||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
TextField,
|
|
||||||
MenuItem,
|
MenuItem,
|
||||||
|
Checkbox,
|
||||||
InputAdornment
|
InputAdornment
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
@@ -26,7 +26,14 @@ import CancelIcon from '@mui/icons-material/Cancel';
|
|||||||
import DoneIcon from '@mui/icons-material/Done';
|
import DoneIcon from '@mui/icons-material/Done';
|
||||||
import AddIcon from '@mui/icons-material/Add';
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
|
|
||||||
import { ValidatedTextField, ButtonRow, FormLoader, SectionContent, BlockNavigation } from 'components';
|
import {
|
||||||
|
ValidatedTextField,
|
||||||
|
ButtonRow,
|
||||||
|
FormLoader,
|
||||||
|
SectionContent,
|
||||||
|
BlockNavigation,
|
||||||
|
BlockFormControlLabel
|
||||||
|
} from 'components';
|
||||||
|
|
||||||
import { DeviceValueUOM_s, EntityItem } from './types';
|
import { DeviceValueUOM_s, EntityItem } from './types';
|
||||||
import { extractErrorMessage, updateValue } from 'utils';
|
import { extractErrorMessage, updateValue } from 'utils';
|
||||||
@@ -54,6 +61,7 @@ const SettingsEntities: FC = () => {
|
|||||||
uom: 0,
|
uom: 0,
|
||||||
val_type: 2,
|
val_type: 2,
|
||||||
name: '',
|
name: '',
|
||||||
|
write: false,
|
||||||
deleted: false
|
deleted: false
|
||||||
};
|
};
|
||||||
const [entity, setEntity] = useState<EntityItem[]>([emptyEntity]);
|
const [entity, setEntity] = useState<EntityItem[]>([emptyEntity]);
|
||||||
@@ -142,6 +150,7 @@ const SettingsEntities: FC = () => {
|
|||||||
o_uom: ei.uom,
|
o_uom: ei.uom,
|
||||||
o_val_type: ei.val_type,
|
o_val_type: ei.val_type,
|
||||||
o_name: ei.name,
|
o_name: ei.name,
|
||||||
|
o_write: ei.write,
|
||||||
o_deleted: ei.deleted
|
o_deleted: ei.deleted
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
@@ -156,6 +165,7 @@ const SettingsEntities: FC = () => {
|
|||||||
ei.uom !== ei.o_uom ||
|
ei.uom !== ei.o_uom ||
|
||||||
ei.factor !== ei.o_factor ||
|
ei.factor !== ei.o_factor ||
|
||||||
ei.val_type !== ei.o_val_type ||
|
ei.val_type !== ei.o_val_type ||
|
||||||
|
ei.write !== ei.o_write ||
|
||||||
ei.deleted !== ei.o_deleted
|
ei.deleted !== ei.o_deleted
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -181,7 +191,8 @@ const SettingsEntities: FC = () => {
|
|||||||
factor: condensed_ei.factor,
|
factor: condensed_ei.factor,
|
||||||
val_type: condensed_ei.val_type,
|
val_type: condensed_ei.val_type,
|
||||||
uom: condensed_ei.uom,
|
uom: condensed_ei.uom,
|
||||||
name: condensed_ei.name
|
name: condensed_ei.name,
|
||||||
|
write: condensed_ei.write
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -306,7 +317,7 @@ const SettingsEntities: FC = () => {
|
|||||||
<Box flexWrap="nowrap" whiteSpace="nowrap"></Box>
|
<Box flexWrap="nowrap" whiteSpace="nowrap"></Box>
|
||||||
</Box>
|
</Box>
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={8}>
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
fieldErrors={fieldErrors}
|
fieldErrors={fieldErrors}
|
||||||
name="name"
|
name="name"
|
||||||
@@ -317,6 +328,14 @@ const SettingsEntities: FC = () => {
|
|||||||
onChange={updateValue(setEntityItem)}
|
onChange={updateValue(setEntityItem)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item xs={4}>
|
||||||
|
<BlockFormControlLabel
|
||||||
|
control={
|
||||||
|
<Checkbox checked={entityItem.write} onChange={updateValue(setEntityItem)} name="write" />
|
||||||
|
}
|
||||||
|
label={LL.WRITEABLE()}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
<Grid item xs={4}>
|
<Grid item xs={4}>
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
name="device_id"
|
name="device_id"
|
||||||
|
|||||||
@@ -356,6 +356,8 @@ export interface EntityItem {
|
|||||||
o_val_type?: number;
|
o_val_type?: number;
|
||||||
deleted?: boolean; // optional
|
deleted?: boolean; // optional
|
||||||
o_deleted?: boolean;
|
o_deleted?: boolean;
|
||||||
|
write: boolean;
|
||||||
|
o_write?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Entities {
|
export interface Entities {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ void WebEntity::read(WebEntity & webEntity, JsonObject & root) {
|
|||||||
ei["name"] = entityItem.name;
|
ei["name"] = entityItem.name;
|
||||||
ei["uom"] = entityItem.uom;
|
ei["uom"] = entityItem.uom;
|
||||||
ei["val_type"] = entityItem.valuetype;
|
ei["val_type"] = entityItem.valuetype;
|
||||||
|
ei["write"] = entityItem.writeable;
|
||||||
EMSESP::webEntityService.render_value(ei, entityItem, true);
|
EMSESP::webEntityService.render_value(ei, entityItem, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,6 +69,7 @@ StateUpdateResult WebEntity::update(JsonObject & root, WebEntity & webEntity) {
|
|||||||
entityItem.name = ei["name"].as<std::string>();
|
entityItem.name = ei["name"].as<std::string>();
|
||||||
entityItem.uom = ei["uom"];
|
entityItem.uom = ei["uom"];
|
||||||
entityItem.valuetype = ei["val_type"];
|
entityItem.valuetype = ei["val_type"];
|
||||||
|
entityItem.writeable = ei["write"];
|
||||||
|
|
||||||
if (entityItem.valuetype == DeviceValueType::BOOL) {
|
if (entityItem.valuetype == DeviceValueType::BOOL) {
|
||||||
entityItem.val = EMS_VALUE_DEFAULT_BOOL;
|
entityItem.val = EMS_VALUE_DEFAULT_BOOL;
|
||||||
@@ -84,12 +86,16 @@ StateUpdateResult WebEntity::update(JsonObject & root, WebEntity & webEntity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
webEntity.entityItems.push_back(entityItem); // add to list
|
webEntity.entityItems.push_back(entityItem); // add to list
|
||||||
Command::add(
|
if (entityItem.writeable) {
|
||||||
EMSdevice::DeviceType::CUSTOM,
|
Command::add(
|
||||||
webEntity.entityItems.back().name.c_str(),
|
EMSdevice::DeviceType::CUSTOM,
|
||||||
[webEntity](const char * value, const int8_t id) { return EMSESP::webEntityService.command_setvalue(value, webEntity.entityItems.back().name); },
|
webEntity.entityItems.back().name.c_str(),
|
||||||
FL_(entity_cmd),
|
[webEntity](const char * value, const int8_t id) {
|
||||||
CommandFlag::ADMIN_ONLY);
|
return EMSESP::webEntityService.command_setvalue(value, webEntity.entityItems.back().name);
|
||||||
|
},
|
||||||
|
FL_(entity_cmd),
|
||||||
|
CommandFlag::ADMIN_ONLY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return StateUpdateResult::CHANGED;
|
return StateUpdateResult::CHANGED;
|
||||||
@@ -215,7 +221,7 @@ bool WebEntityService::get_value_info(JsonObject & output, const char * cmd) {
|
|||||||
output["name"] = entity.name;
|
output["name"] = entity.name;
|
||||||
output["uom"] = EMSdevice::uom_to_string(entity.uom);
|
output["uom"] = EMSdevice::uom_to_string(entity.uom);
|
||||||
output["readable"] = true;
|
output["readable"] = true;
|
||||||
output["writeable"] = true;
|
output["writeable"] = entity.writeable;
|
||||||
output["visible"] = true;
|
output["visible"] = true;
|
||||||
render_value(output, entity, true);
|
render_value(output, entity, true);
|
||||||
if (attribute_s) {
|
if (attribute_s) {
|
||||||
@@ -250,8 +256,8 @@ void WebEntityService::publish_single(const EntityItem & entity) {
|
|||||||
} else {
|
} else {
|
||||||
snprintf(topic, sizeof(topic), "%s/%s", "custom_data", entity.name.c_str());
|
snprintf(topic, sizeof(topic), "%s/%s", "custom_data", entity.name.c_str());
|
||||||
}
|
}
|
||||||
StaticJsonDocument<256> doc;
|
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc;
|
||||||
JsonObject output = doc.to<JsonObject>();
|
JsonObject output = doc.to<JsonObject>();
|
||||||
render_value(output, entity, true);
|
render_value(output, entity, true);
|
||||||
Mqtt::queue_publish(topic, output["value"].as<std::string>());
|
Mqtt::queue_publish(topic, output["value"].as<std::string>());
|
||||||
}
|
}
|
||||||
@@ -343,7 +349,9 @@ void WebEntityService::generate_value_web(JsonObject & output) {
|
|||||||
JsonObject obj = data.createNestedObject(); // create the object, we know there is a value
|
JsonObject obj = data.createNestedObject(); // create the object, we know there is a value
|
||||||
obj["id"] = "00" + entity.name;
|
obj["id"] = "00" + entity.name;
|
||||||
obj["u"] = entity.uom;
|
obj["u"] = entity.uom;
|
||||||
obj["c"] = entity.name;
|
if (entity.writeable) {
|
||||||
|
obj["c"] = entity.name;
|
||||||
|
}
|
||||||
switch (entity.valuetype) {
|
switch (entity.valuetype) {
|
||||||
case DeviceValueType::BOOL: {
|
case DeviceValueType::BOOL: {
|
||||||
char s[12];
|
char s[12];
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class EntityItem {
|
|||||||
uint8_t uom;
|
uint8_t uom;
|
||||||
std::string name;
|
std::string name;
|
||||||
double factor;
|
double factor;
|
||||||
|
bool writeable;
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user