mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fix saving customizatons #450
This commit is contained in:
@@ -849,27 +849,38 @@ void EMSdevice::generate_values_web_all(JsonArray & output) {
|
||||
|
||||
// set mask per device entity based on the id which is prefixed with the 2 char hex mask value
|
||||
// returns true if the entity has a mask set (not 0 the default)
|
||||
bool EMSdevice::mask_entity(const std::string & entity_id) {
|
||||
void EMSdevice::mask_entity(const std::string & entity_id) {
|
||||
for (auto & dv : devicevalues_) {
|
||||
std::string entity_name =
|
||||
dv.tag < DeviceValueTAG::TAG_HC1 ? read_flash_string(dv.short_name) : tag_to_string(dv.tag) + "/" + read_flash_string(dv.short_name);
|
||||
uint8_t current_mask = dv.state >> 4;
|
||||
if (entity_name == entity_id.substr(2)) {
|
||||
// this entity has a new mask set
|
||||
uint8_t new_mask = Helpers::hextoint(entity_id.substr(0, 2).c_str()); // first character contains mask flags
|
||||
uint8_t current_mask = dv.state >> 4;
|
||||
uint8_t new_mask = Helpers::hextoint(entity_id.substr(0, 2).c_str()); // first character contains mask flags
|
||||
if (Mqtt::ha_enabled() && ((current_mask ^ new_mask) & (DeviceValueState::DV_READONLY >> 4))) {
|
||||
// remove ha config on change of dv_readonly flag
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
Mqtt::publish_ha_sensor_config(dv, "", "", true); // delete topic (remove = true)
|
||||
}
|
||||
dv.state = ((dv.state & 0x0F) | (new_mask << 4)); // set state high bits to flag
|
||||
return new_mask; // true if entity mask is not the deafult 0
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return false; // we didn't find the entity
|
||||
}
|
||||
|
||||
// populate a string vector with entities that have masks set
|
||||
void EMSdevice::getMaskedEntities(std::vector<std::string> & entity_ids) {
|
||||
for (auto & dv : devicevalues_) {
|
||||
std::string entity_name =
|
||||
dv.tag < DeviceValueTAG::TAG_HC1 ? read_flash_string(dv.short_name) : tag_to_string(dv.tag) + "/" + read_flash_string(dv.short_name);
|
||||
uint8_t mask = dv.state >> 4;
|
||||
if (mask) {
|
||||
entity_ids.push_back(Helpers::hextoa(mask, false) + entity_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// builds json for a specific device value / entity
|
||||
// cmd is the endpoint or name of the device entity
|
||||
// returns false if failed, otherwise true
|
||||
|
||||
Reference in New Issue
Block a user