HA climate mode and icon check

This commit is contained in:
MichaelDvP
2026-01-29 09:53:20 +01:00
parent 4e194287c9
commit 8fc6752290
2 changed files with 21 additions and 22 deletions

View File

@@ -2108,7 +2108,6 @@ bool EMSdevice::generate_values(JsonObject output, const int8_t tag_filter, cons
void EMSdevice::mqtt_ha_entity_config_create() { void EMSdevice::mqtt_ha_entity_config_create() {
bool create_device_config = !ha_config_done(); // do we need to create the main Discovery device config with this entity? bool create_device_config = !ha_config_done(); // do we need to create the main Discovery device config with this entity?
uint16_t count = 0; uint16_t count = 0;
const char * const ** mode_options = nullptr;
// check the state of each of the device values // check the state of each of the device values
// create the discovery topic if if hasn't already been created, not a command (like reset) and is active and visible // create the discovery topic if if hasn't already been created, not a command (like reset) and is active and visible
@@ -2121,17 +2120,15 @@ void EMSdevice::mqtt_ha_entity_config_create() {
bool needs_update = !has_config_created || (haclimate_value == 1 ? has_climate_no_rt : !has_climate_no_rt); bool needs_update = !has_config_created || (haclimate_value == 1 ? has_climate_no_rt : !has_climate_no_rt);
if (needs_update) { if (needs_update) {
// if it's a thermostat go fetch the list of modes const char * const ** mode_options = nullptr;
if (device_type() == EMSdevice::DeviceType::THERMOSTAT) { for (auto & d : devicevalues_) {
for (auto & dv : devicevalues_) { // make sure mode in same circuit is DeviceValueType::ENUM
// make sure it's a type DeviceValueType::ENUM if ((d.tag == dv.tag) && (d.type == DeviceValueType::ENUM) && !strcmp(d.short_name, FL_(mode)[0]) && (d.options_size > 0)) {
if ((dv.type == DeviceValueType::ENUM) && !strcmp(dv.short_name, FL_(mode)[0])) {
// get options // get options
mode_options = dv.options; mode_options = d.options;
break; break;
} }
} }
}
bool has_room_temp = (haclimate_value == 1); bool has_room_temp = (haclimate_value == 1);
if (Mqtt::publish_ha_climate_config(dv, has_room_temp, mode_options, false)) { if (Mqtt::publish_ha_climate_config(dv, has_room_temp, mode_options, false)) {
@@ -2155,21 +2152,22 @@ void EMSdevice::mqtt_ha_entity_config_create() {
count++; count++;
} }
// SRC thermostats mapped to connect/src1/... // SRC thermostats mapped to connect/src1/... always contains mode, seltemp, currtemp
/* removed climate for testing if (dv.tag >= DeviceValueTAG::TAG_SRC1 && dv.tag <= DeviceValueTAG::TAG_SRC16 && !strcmp(dv.short_name, FL_(mode)[0])) {
if (dv.tag >= DeviceValueTAG::TAG_SRC1 && dv.tag <= DeviceValueTAG::TAG_SRC16 && !strcmp(dv.short_name, FL_(selRoomTemp)[0])) { // add icon if we have one
const char * icon = nullptr; const char * icon = nullptr;
for (auto & d : devicevalues_) { for (auto & d : devicevalues_) {
if (d.tag == dv.tag && !strcmp(d.short_name, FL_(icon)[0]) && *(uint8_t *)d.value_p != 0) { if (d.tag == dv.tag && !strcmp(d.short_name, FL_(icon)[0]) && (dv.type == DeviceValueType::ENUM)) {
icon = d.options[*(uint8_t *)d.value_p][0]; uint8_t val = *(uint8_t *)(d.value_p);
if (val != 0 && val < d.options_size) {
icon = d.options[val][0];
}
break; break;
} }
} }
// add all modes - auto, heat, off, cool Mqtt::publish_ha_climate_config(dv, true, dv.options, false, icon);
// https://github.com/emsesp/EMS-ESP32/issues/2636 count++;
Mqtt::publish_ha_climate_config(dv, true, nullptr, false, icon);
} }
*/
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
// always create minimum one config // always create minimum one config

View File

@@ -476,7 +476,8 @@ void Thermostat::add_ha_climate(std::shared_ptr<HeatingCircuit> hc) const {
return; return;
} }
if (Helpers::hasValue(hc->selTemp) && is_readable(&hc->selTemp)) { // create climate only if we have modes
if (Helpers::hasValue(hc->mode) && Helpers::hasValue(hc->selTemp) && is_readable(&hc->selTemp)) {
if (Helpers::hasValue(hc->roomTemp) && is_readable(&hc->roomTemp)) { if (Helpers::hasValue(hc->roomTemp) && is_readable(&hc->roomTemp)) {
hc->climate = 1; // use roomTemp as we have a sensor hc->climate = 1; // use roomTemp as we have a sensor
} else { } else {