HA config recreate #1067

This commit is contained in:
MichaelDvP
2023-02-21 13:56:31 +01:00
parent 016e18002c
commit dfa5e23e90

View File

@@ -1646,8 +1646,7 @@ bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, c
// 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_) {
if ((dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) if (dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED)
|| (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) && dv.has_state(DeviceValueState::DV_HA_CONFIG_RECREATE)))
&& ((dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE)) || (!dv.has_state(DeviceValueState::DV_ACTIVE)))) { && ((dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE)) || (!dv.has_state(DeviceValueState::DV_ACTIVE)))) {
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED); dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
dv.remove_state(DeviceValueState::DV_HA_CONFIG_RECREATE); dv.remove_state(DeviceValueState::DV_HA_CONFIG_RECREATE);
@@ -1701,6 +1700,9 @@ void EMSdevice::mqtt_ha_entity_config_create() {
void EMSdevice::ha_config_clear() { void EMSdevice::ha_config_clear() {
for (auto & dv : devicevalues_) { for (auto & dv : devicevalues_) {
dv.add_state(DeviceValueState::DV_HA_CONFIG_RECREATE); dv.add_state(DeviceValueState::DV_HA_CONFIG_RECREATE);
if (ha_config_firstrun()) {
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED); // make sure it is removed if not active
}
} }
ha_config_done(false); // this will force the recreation of the main HA device config ha_config_done(false); // this will force the recreation of the main HA device config