From 2b679daabc79c3a92048b8b7899945f7ecf3f487 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 15 Dec 2025 11:56:54 +0100 Subject: [PATCH] dev 37, add SRC thermostat icons to climate --- src/core/emsdevice.cpp | 9 ++++++++- src/core/mqtt.cpp | 5 ++++- src/core/mqtt.h | 6 +++++- src/emsesp_version.h | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/emsdevice.cpp b/src/core/emsdevice.cpp index 586607241..6746c6d62 100644 --- a/src/core/emsdevice.cpp +++ b/src/core/emsdevice.cpp @@ -2134,9 +2134,16 @@ void EMSdevice::mqtt_ha_entity_config_create() { // SRC thermostats mapped to connect/src1/... if (dv.tag >= DeviceValueTAG::TAG_SRC1 && dv.tag <= DeviceValueTAG::TAG_SRC16 && !strcmp(dv.short_name, FL_(selRoomTemp)[0])) { + const char * icon = nullptr; + for (auto & d : devicevalues_) { + if (d.tag == dv.tag && !strcmp(d.short_name, FL_(icon)[0]) && *(uint8_t *)(d.value_p != 0)) { + icon = d.options[*(uint8_t *)(d.value_p)][0]; + break; + } + } // add all modes - auto, heat, off, cool // https://github.com/emsesp/EMS-ESP32/issues/2636 - Mqtt::publish_ha_climate_config(dv, true, nullptr, false); + Mqtt::publish_ha_climate_config(dv, true, nullptr, false, icon); } #ifndef EMSESP_STANDALONE diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index b82f2a3e5..61a88926c 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -1244,7 +1244,7 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8 // publish the HA climate config // https://www.home-assistant.io/integrations/climate.mqtt/ -bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_roomtemp, const char * const ** mode_options, const bool remove) { +bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_roomtemp, const char * const ** mode_options, const bool remove, const char * icon) { int8_t tag = dv.tag; int16_t min = dv.min; uint32_t max = dv.max; @@ -1402,6 +1402,9 @@ bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_room modes.add("cool"); } + if (icon != nullptr) { + doc["ic"] = icon; + } add_ha_dev_section(doc.as(), devicename, nullptr, nullptr, nullptr, false); // add dev section add_ha_avty_section(doc.as(), topic_t, seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond); // add availability section diff --git a/src/core/mqtt.h b/src/core/mqtt.h index 60e0fc1ea..b55000407 100644 --- a/src/core/mqtt.h +++ b/src/core/mqtt.h @@ -113,7 +113,11 @@ class Mqtt { const bool create_device_config = false); static bool publish_system_ha_sensor_config(uint8_t type, const char * name, const char * entity, const uint8_t uom); - static bool publish_ha_climate_config(const DeviceValue & dv, const bool has_roomtemp, const char * const ** mode_options, const bool remove = false); + static bool publish_ha_climate_config(const DeviceValue & dv, + const bool has_roomtemp, + const char * const ** mode_options, + const bool remove = false, + const char * icon = nullptr); static void show_topic_handlers(uuid::console::Shell & shell, const uint8_t device_type); static void show_mqtt(uuid::console::Shell & shell); diff --git a/src/emsesp_version.h b/src/emsesp_version.h index 1b5f3d375..20ec83fc6 100644 --- a/src/emsesp_version.h +++ b/src/emsesp_version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.7.3-dev.36" +#define EMSESP_APP_VERSION "3.7.3-dev.37"