From 3a2d3ac985f672827b49bb513ea0709e51ba6d22 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 15 Dec 2025 19:34:48 +0100 Subject: [PATCH] fix mixed up logic with HA modes --- src/core/mqtt.cpp | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index 61a88926c..de6c00f6c 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -1367,10 +1367,10 @@ bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_room // map EMS modes to HA climate modes // EMS modes: auto, manual, heat, off, night, day, nofrost, eco, comfort, cool) // HA supports: auto, off, cool, heat, dry, fan_only - bool found_auto = true; - bool found_heat = true; - bool found_off = true; - bool found_cool = true; + bool found_auto = false; + bool found_heat = false; + bool found_off = false; + bool found_cool = false; if (mode_options != nullptr) { // scan through mode_options and add to modes for (uint8_t i = 0; i < Helpers::count_items(mode_options); i++) { @@ -1385,26 +1385,35 @@ bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_room found_cool = true; } } + } else { + // add all modes if no mode_options are available, e.g. for SRC thermostats + found_auto = true; // auto + found_heat = true; // heat + found_off = true; // off + found_cool = true; // cool } - // only add modes if we found at least one - JsonArray modes = doc["modes"].to(); - if (found_auto) { - modes.add("auto"); - } - if (found_heat) { - modes.add("heat"); - } - if (found_off) { - modes.add("off"); - } - if (found_cool) { - modes.add("cool"); + // only add modes if we found at least one, i.e. if mode_options are available + if (found_auto || found_heat || found_off || found_cool) { + JsonArray modes = doc["modes"].to(); + if (found_auto) { + modes.add("auto"); + } + if (found_heat) { + modes.add("heat"); + } + if (found_off) { + modes.add("off"); + } + if (found_cool) { + 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