From 395bd604ce4eca6329822291b125f3111d941121 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 20 Feb 2023 18:30:56 +0100 Subject: [PATCH] fix for #1067 and ems-esp restarting --- src/emsdevice.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index f61b2ff39..da401dad2 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -1684,7 +1684,8 @@ 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() void EMSdevice::mqtt_ha_entity_config_remove() { 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.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED); dv.remove_state(DeviceValueState::DV_HA_CONFIG_RECREATE); @@ -1737,9 +1738,7 @@ void EMSdevice::mqtt_ha_entity_config_create() { // remove all config topics in HA void EMSdevice::ha_config_clear() { for (auto & dv : devicevalues_) { - if (dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED)) { - dv.add_state(DeviceValueState::DV_HA_CONFIG_RECREATE); - } + dv.add_state(DeviceValueState::DV_HA_CONFIG_RECREATE); } ha_config_done(false); // this will force the recreation of the main HA device config