fix HA climate

This commit is contained in:
proddy
2022-02-21 10:29:10 +01:00
parent d06145bb3a
commit 63a94dcef1

View File

@@ -675,19 +675,18 @@ void Thermostat::add_ha_climate(std::shared_ptr<HeatingCircuit> hc) {
return; return;
} }
bool has_values = Helpers::hasValue(hc->selTemp) && Helpers::hasValue(hc->roomTemp);
// see if we need to remove the HA climate component because some of the values have been lost
// note, this doesn't account for whether any of the device values have been excluded // note, this doesn't account for whether any of the device values have been excluded
if (hc->ha_climate_created() && !has_values) { if (hc->ha_climate_created()) {
// remove the whole climate component // see if we've lost the selTemp (roomTemp/currTemp is optional and checked in the publish_ha_config_hc() function)
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; if (!Helpers::hasValue(hc->selTemp)) {
snprintf(topic, sizeof(topic), "climate/%s/thermostat_hc%d/config", Mqtt::base().c_str(), hc->hc_num()); char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
Mqtt::publish_ha(topic); snprintf(topic, sizeof(topic), "climate/%s/thermostat_hc%d/config", Mqtt::base().c_str(), hc->hc_num());
Mqtt::publish_ha(topic);
}
} else { } else {
// create // create the climate component, only once
publish_ha_config_hc(hc); publish_ha_config_hc(hc);
hc->ha_climate_created(true); // only create it once hc->ha_climate_created(true);
} }
} }