From ca81a02a8c0d1df288964f407173314a6640c7aa Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 23 May 2025 07:41:43 +0200 Subject: [PATCH 1/2] masked enums with single mask, update seltemp in advance --- src/core/emsdevice.h | 17 +++++++++-------- src/devices/boiler.cpp | 6 +++--- src/devices/thermostat.cpp | 12 ++++++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/core/emsdevice.h b/src/core/emsdevice.h index bfe3560e8..74b0dd1aa 100644 --- a/src/core/emsdevice.h +++ b/src/core/emsdevice.h @@ -197,16 +197,17 @@ class EMSdevice { } } - void has_enumupdate(std::shared_ptr telegram, - uint8_t & value, - const uint8_t index, - const std::vector & maskIn, - const std::vector & maskOut) { + void has_enumupdate(std::shared_ptr telegram, uint8_t & value, const uint8_t index, const std::vector & maskIn) { uint8_t val = value < maskIn.size() ? maskIn[value] : EMS_VALUE_UINT8_NOTSET; if (telegram->read_value(val, index)) { - value = val < maskOut.size() ? maskOut[val] : EMS_VALUE_UINT8_NOTSET; - has_update_ = true; - publish_value((void *)&value); + for (uint8_t i = 0; i < maskIn.size(); i++) { + if (val == maskIn[i]) { + value = i; + has_update_ = true; + publish_value((void *)&value); + return; + } + } } } diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index dc61a9b08..7cdac85ed 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -1805,9 +1805,9 @@ void Boiler::process_HpCooling(std::shared_ptr telegram) { // Boiler(0x08) -W-> Me(0x0B), HpHeaterConfig(0x0492), data: 03 00 00 04 00 void Boiler::process_HpHeaterConfig(std::shared_ptr telegram) { if (model() == EMSdevice::EMS_DEVICE_FLAG_CS6800) { - has_enumupdate(telegram, maxHeatComp_, 2, {0, 2, 4, 5}, {0, 0, 1, 0, 2, 3}); - has_enumupdate(telegram, maxHeatHeat_, 3, {2, 4, 5}, {0, 0, 0, 0, 1, 2}); - has_enumupdate(telegram, maxHeatDhw_, 4, {2, 4, 5}, {0, 0, 0, 0, 1, 2}); + has_enumupdate(telegram, maxHeatComp_, 2, {0, 2, 4, 5}); + has_enumupdate(telegram, maxHeatHeat_, 3, {2, 4, 5}); + has_enumupdate(telegram, maxHeatDhw_, 4, {2, 4, 5}); return; } has_update(telegram, maxHeatComp_, 2); diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index edb028a10..a49e10485 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -1275,14 +1275,14 @@ void Thermostat::process_RC300WWmode(std::shared_ptr telegram) { has_update(telegram, dhw->wwCircPump_, 1); // FF=off, 0=on ? if (model() == EMSdevice::EMS_DEVICE_FLAG_BC400 || model() == EMSdevice::EMS_DEVICE_FLAG_HMC310) { - has_enumupdate(telegram, dhw->wwMode_, 2, {0, 5, 1, 2, 4}, {0, 2, 3, 0, 4, 1}); + has_enumupdate(telegram, dhw->wwMode_, 2, {0, 5, 1, 2, 4}); } else if (model() == EMSdevice::EMS_DEVICE_FLAG_R3000) { // https://github.com/emsesp/EMS-ESP32/pull/1722#discussion_r1582823521 - has_enumupdate(telegram, dhw->wwMode_, 2, {1, 2, 5}, {0, 0, 1, 0, 0, 2}); // normal, comfort, eco+ + has_enumupdate(telegram, dhw->wwMode_, 2, {1, 2, 5}); // normal, comfort, eco+ } else if (model() == EMSdevice::EMS_DEVICE_FLAG_CR120) { - has_enumupdate(telegram, dhw->wwMode_, 2, {1, 2, 4}, {0, 0, 1, 0, 2, 0}); // normal, comfort, auto + has_enumupdate(telegram, dhw->wwMode_, 2, {1, 2, 4}); // normal, comfort, auto } else if (model() == EMSdevice::EMS_DEVICE_FLAG_RC100) { - has_enumupdate(telegram, dhw->wwMode_, 2, {0, 2, 3}, {0, 0, 1, 2, 0, 0}); // normal, on, auto + has_enumupdate(telegram, dhw->wwMode_, 2, {0, 2, 3}); // normal, on, auto } else { has_update(telegram, dhw->wwMode_, 2); // 0=off, 1=low, 2=high, 3=auto, 4=own prog } @@ -4171,6 +4171,10 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co // add the write command to the Tx queue. value is *2 // post validate is the corresponding monitor or set type IDs as they can differ per model write_command(set_typeid, offset, (uint8_t)(temperature * (float)factor), validate_typeid); + // update selTemp now, readback from monitor telegram takes a while + if (mode == HeatingCircuit::Mode::AUTO) { + has_update(hc->selTemp,(int16_t)(temperature * factor)); + } return true; } LOG_DEBUG("temperature mode %d not found", mode); From 090491aab60db32e11d840a46e00f0d32dabf6fa Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 23 May 2025 07:42:21 +0200 Subject: [PATCH 2/2] remove optimistic option #2551 --- CHANGELOG_LATEST.md | 1 - interface/src/app/settings/MqttSettings.tsx | 12 ------------ interface/src/types/mqtt.ts | 1 - lib_standalone/ESP32React.h | 1 - mock-api/restServer.ts | 1 - src/ESP32React/MqttSettingsService.cpp | 10 ---------- src/ESP32React/MqttSettingsService.h | 1 - src/core/analogsensor.cpp | 3 --- src/core/mqtt.cpp | 8 -------- src/core/mqtt.h | 9 --------- src/web/WebCustomEntityService.cpp | 3 --- src/web/WebSchedulerService.cpp | 3 --- 12 files changed, 53 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index ab783ed08..792e485a3 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -11,7 +11,6 @@ For more details go to [docs.emsesp.org](https://docs.emsesp.org/). - boiler auxheatersource [#2489](https://github.com/emsesp/EMS-ESP32/discussions/2489) - thermostat last error for RC100/300 [#2501](https://github.com/emsesp/EMS-ESP32/issues/2501) - boiler 0xC6 telegram [#1963](https://github.com/emsesp/EMS-ESP32/issues/1963) -- HA optimistic [#2551](https://github.com/emsesp/EMS-ESP32/issues/2551) - CS6800i changes [#2448](https://github.com/emsesp/EMS-ESP32/issues/2448), [#2449](https://github.com/emsesp/EMS-ESP32/issues/2449) - charging pump [#2544](https://github.com/emsesp/EMS-ESP32/issues/2544) diff --git a/interface/src/app/settings/MqttSettings.tsx b/interface/src/app/settings/MqttSettings.tsx index c8567e435..10921a96c 100644 --- a/interface/src/app/settings/MqttSettings.tsx +++ b/interface/src/app/settings/MqttSettings.tsx @@ -296,18 +296,6 @@ const MqttSettings = () => { } label={LL.MQTT_PUBLISH_TEXT_3()} /> - {data.ha_enabled && data.discovery_type === 0 && ( - - } - label="Optimistic" - /> - )} {data.ha_enabled && ( diff --git a/interface/src/types/mqtt.ts b/interface/src/types/mqtt.ts index f930a12bf..738dafa75 100644 --- a/interface/src/types/mqtt.ts +++ b/interface/src/types/mqtt.ts @@ -43,7 +43,6 @@ export interface MqttSettingsType { mqtt_qos: number; mqtt_retain: boolean; ha_enabled: boolean; - ha_optimistic: boolean; nested_format: number; send_response: boolean; publish_single: boolean; diff --git a/lib_standalone/ESP32React.h b/lib_standalone/ESP32React.h index 5b1d1a384..115a42aae 100644 --- a/lib_standalone/ESP32React.h +++ b/lib_standalone/ESP32React.h @@ -36,7 +36,6 @@ class DummySettings { String discovery_prefix = "homeassistant"; uint8_t discovery_type = 0; // HA bool ha_enabled = true; - bool ha_optimistic = false; String base = "ems-esp"; bool publish_single = false; bool publish_single2cmd = false; diff --git a/mock-api/restServer.ts b/mock-api/restServer.ts index 54d0ae13a..0e95bd836 100644 --- a/mock-api/restServer.ts +++ b/mock-api/restServer.ts @@ -567,7 +567,6 @@ let mqtt_settings = { rootCA: '', mqtt_retain: false, ha_enabled: true, - ha_optimistic: false, nested_format: 1, discovery_type: 0, discovery_prefix: 'homeassistant', diff --git a/src/ESP32React/MqttSettingsService.cpp b/src/ESP32React/MqttSettingsService.cpp index 55d5a5881..f6fb78872 100644 --- a/src/ESP32React/MqttSettingsService.cpp +++ b/src/ESP32React/MqttSettingsService.cpp @@ -244,7 +244,6 @@ void MqttSettings::read(MqttSettings & settings, JsonObject root) { root["mqtt_qos"] = settings.mqtt_qos; root["mqtt_retain"] = settings.mqtt_retain; root["ha_enabled"] = settings.ha_enabled; - root["ha_optimistic"] = settings.ha_optimistic; root["nested_format"] = settings.nested_format; root["discovery_prefix"] = settings.discovery_prefix; root["discovery_type"] = settings.discovery_type; @@ -285,7 +284,6 @@ StateUpdateResult MqttSettings::update(JsonObject root, MqttSettings & settings) newSettings.publish_time_heartbeat = static_cast(root["publish_time_heartbeat"] | EMSESP_DEFAULT_PUBLISH_HEARTBEAT); newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED; - newSettings.ha_optimistic = root["ha_optimistic"] | EMSESP_DEFAULT_HA_OPTIMISTIC; newSettings.nested_format = static_cast(root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT); newSettings.discovery_prefix = root["discovery_prefix"] | EMSESP_DEFAULT_DISCOVERY_PREFIX; newSettings.discovery_type = static_cast(root["discovery_type"] | EMSESP_DEFAULT_DISCOVERY_TYPE); @@ -347,14 +345,6 @@ StateUpdateResult MqttSettings::update(JsonObject root, MqttSettings & settings) changed = true; } - if (newSettings.discovery_type != 0) { - newSettings.ha_optimistic = false; - } - if (newSettings.ha_optimistic != settings.ha_optimistic) { - emsesp::EMSESP::mqtt_.ha_optimistic(newSettings.ha_optimistic); - changed = true; - } - if (newSettings.mqtt_retain != settings.mqtt_retain) { emsesp::EMSESP::mqtt_.set_retain(newSettings.mqtt_retain); changed = true; diff --git a/src/ESP32React/MqttSettingsService.h b/src/ESP32React/MqttSettingsService.h index 760507ef2..ef448af0d 100644 --- a/src/ESP32React/MqttSettingsService.h +++ b/src/ESP32React/MqttSettingsService.h @@ -76,7 +76,6 @@ class MqttSettings { uint8_t mqtt_qos; bool mqtt_retain; bool ha_enabled; - bool ha_optimistic; uint8_t nested_format; String discovery_prefix; uint8_t discovery_type; diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index 0ca1084fe..ff3d7baf8 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -682,9 +682,6 @@ void AnalogSensor::publish_values(const bool force) { Mqtt::add_ha_sections_to_doc("analog", stat_t, config, !is_ha_device_created, val_cond); - if (Mqtt::ha_optimistic() && config["cmd_t"].is()) { - config["optimistic"] = true; - } sensor.ha_registered = Mqtt::queue_ha(topic, config.as()); } } diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index 188fffd8e..199f2202c 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -40,7 +40,6 @@ uint32_t Mqtt::publish_time_heartbeat_; bool Mqtt::mqtt_enabled_; uint8_t Mqtt::entity_format_; bool Mqtt::ha_enabled_; -bool Mqtt::ha_optimistic_; uint8_t Mqtt::nested_format_; std::string Mqtt::discovery_prefix_; uint8_t Mqtt::discovery_type_; @@ -341,7 +340,6 @@ void Mqtt::load_settings() { mqtt_retain_ = mqttSettings.mqtt_retain; mqtt_enabled_ = mqttSettings.enabled; ha_enabled_ = mqttSettings.ha_enabled; - ha_optimistic_ = mqttSettings.ha_optimistic; nested_format_ = mqttSettings.nested_format; publish_single_ = mqttSettings.publish_single; publish_single2cmd_ = mqttSettings.publish_single2cmd; @@ -1127,9 +1125,6 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev doc["dev"] = dev_json; - if (ha_optimistic_ && has_cmd) { - doc["optimistic"] = true; - } return queue_ha(topic, doc.as()); } @@ -1359,9 +1354,6 @@ bool Mqtt::publish_ha_climate_config(const int8_t tag, const bool has_roomtemp, // device name must be different to the entity name, take the ids value we just created add_ha_sections_to_doc("thermostat", topic_t, doc, false, seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond); - if (ha_optimistic_) { - doc["optimistic"] = true; - } return queue_ha(topic, doc.as()); // publish the config payload with retain flag } diff --git a/src/core/mqtt.h b/src/core/mqtt.h index f6565cbdb..fe0e2474b 100644 --- a/src/core/mqtt.h +++ b/src/core/mqtt.h @@ -210,14 +210,6 @@ class Mqtt { ha_enabled_ = ha_enabled; } - static bool ha_optimistic() { - return ha_optimistic_; - } - - static void ha_optimistic(bool ha_optimistic) { - ha_optimistic_ = ha_optimistic; - } - static bool ha_climate_reset() { return ha_climate_reset_; } @@ -321,7 +313,6 @@ class Mqtt { static uint32_t publish_time_heartbeat_; static bool mqtt_enabled_; static bool ha_enabled_; - static bool ha_optimistic_; static uint8_t nested_format_; static uint8_t entity_format_; static std::string discovery_prefix_; diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index a96755cb2..391190352 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -452,9 +452,6 @@ void WebCustomEntityService::publish(const bool force) { Mqtt::add_ha_sections_to_doc(F_(custom), stat_t, config, !ha_created, val_cond); - if (Mqtt::ha_optimistic() && (entityItem.writeable || entityItem.ram > 0)) { - config["optimistic"] = true; - } ha_created |= Mqtt::queue_ha(topic, config.as()); } } diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index e8fc309d8..3807b3503 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -290,9 +290,6 @@ void WebSchedulerService::publish(const bool force) { Mqtt::add_ha_bool(config); Mqtt::add_ha_sections_to_doc(F_(scheduler), stat_t, config, !ha_created, val_cond); - if (Mqtt::ha_optimistic()) { - config["optimistic"] = true; - } ha_created |= Mqtt::queue_ha(topic, config.as()); } }