mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
recreate instaed of remove/recreate HA config when mqtt reconnecs #1067
This commit is contained in:
@@ -1687,6 +1687,7 @@ void EMSdevice::mqtt_ha_entity_config_remove() {
|
||||
if (dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED)
|
||||
&& ((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);
|
||||
if (dv.short_name == FL_(climate)[0]) {
|
||||
Mqtt::publish_ha_climate_config(dv.tag, false, true); // delete topic (remove = true)
|
||||
} else {
|
||||
@@ -1705,6 +1706,10 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
// create climate if roomtemp is visible
|
||||
// create the discovery topic if if hasn't already been created, not a command (like reset) and is active and visible
|
||||
for (auto & dv : devicevalues_) {
|
||||
if (dv.has_state(DeviceValueState::DV_HA_CONFIG_RECREATE)) {
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_RECREATE);
|
||||
}
|
||||
if ((dv.short_name == FL_(climate)[0]) && !dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE) && dv.has_state(DeviceValueState::DV_ACTIVE)) {
|
||||
if (*(int8_t *)(dv.value_p) == 1 && (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) || dv.has_state(DeviceValueState::DV_HA_CLIMATE_NO_RT))) {
|
||||
dv.remove_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
|
||||
@@ -1732,8 +1737,9 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
// remove all config topics in HA
|
||||
void EMSdevice::ha_config_clear() {
|
||||
for (auto & dv : devicevalues_) {
|
||||
Mqtt::publish_ha_sensor_config(dv, "", "", true); // delete topic (remove = true)
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
if (dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED)) {
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_RECREATE);
|
||||
}
|
||||
}
|
||||
|
||||
ha_config_done(false); // this will force the recreation of the main HA device config
|
||||
|
||||
Reference in New Issue
Block a user