From 2c337f1d030bd8d5fb88bccab3527b17ebe597db Mon Sep 17 00:00:00 2001 From: proddy Date: Tue, 28 Sep 2021 16:15:47 +0200 Subject: [PATCH 1/2] fixed #129 --- CHANGELOG_LATEST.md | 5 +++-- src/emsdevice.cpp | 2 +- src/mqtt.cpp | 42 ++++++++++++++++++++---------------------- src/mqtt.h | 3 ++- src/version.h | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index c011d049a..74f09f645 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -9,7 +9,8 @@ - Add RC300 second summermode telegram [#108](https://github.com/emsesp/EMS-ESP32/issues/108) - Add support for the RC25 thermostat [#106](https://github.com/emsesp/EMS-ESP32/issues/106) - Add new command 'entities' for a device, e.g. http://ems-esp/api/boiler/entities to show the shortname, description and HA Entity name (if HA enabled) [#116](https://github.com/emsesp/EMS-ESP32/issues/116) -- Junkers program and remote (fb10/fb110) temperature +- Support for Junkers program and remote (fb10/fb110) temperature +- Home Assistant `state_class` attribute for Wh, kWh, W and KW [#129](https://github.com/emsesp/EMS-ESP32/issues/129) ## Fixed @@ -25,7 +26,7 @@ - rename `fastheatupfactor` to `fastheatup` and add percent [#122] - "unit" renamed to "uom" in API call to recall a Device Value - initial backend React changes to replace the class components (HOCs) with React Hooks -- program-names instead of numbers +- Use program-names instead of numbers ## **BREAKING CHANGES** diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 7d3abcb2a..22cf78edb 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -1051,7 +1051,7 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter void EMSdevice::publish_mqtt_ha_sensor() { for (auto & dv : devicevalues_) { if (dv.ha == DeviceValueHA::HA_VALUE) { - Mqtt::publish_ha_sensor(dv.type, dv.tag, dv.full_name, device_type_, dv.short_name, dv.uom); + Mqtt::publish_ha_sensor(dv.type, dv.tag, dv.full_name, dv.device_type, dv.short_name, dv.uom, dv.has_cmd); dv.ha |= DeviceValueHA::HA_DONE; } } diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 7ba28f82b..fd27b62b4 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -721,7 +721,7 @@ void Mqtt::ha_status() { DeviceValueUOM::PERCENT); } - publish_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime"), EMSdevice::DeviceType::SYSTEM, F("uptime")); + publish_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime"), EMSdevice::DeviceType::SYSTEM, F("uptime"), DeviceValueUOM::NONE); publish_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime (sec)"), EMSdevice::DeviceType::SYSTEM, F("uptime_sec"), DeviceValueUOM::SECONDS); publish_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Free memory"), EMSdevice::DeviceType::SYSTEM, F("freemem"), DeviceValueUOM::KB); publish_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("# MQTT fails"), EMSdevice::DeviceType::SYSTEM, F("mqttfails"), DeviceValueUOM::NONE); @@ -929,7 +929,8 @@ void Mqtt::publish_ha_sensor(uint8_t type, // EMSdevice::Dev const __FlashStringHelper * name, const uint8_t device_type, // EMSdevice::DeviceType const __FlashStringHelper * entity, - const uint8_t uom) { // EMSdevice::DeviceValueUOM (0=NONE) + const uint8_t uom, // EMSdevice::DeviceValueUOM (0=NONE) + const bool has_cmd) { // ignore if name (fullname) is empty if (name == nullptr) { return; @@ -1002,8 +1003,8 @@ void Mqtt::publish_ha_sensor(uint8_t type, // EMSdevice::Dev // normal HA sensor, not a boolean one snprintf(topic, sizeof(topic), "sensor/%s/%s/config", mqtt_base_.c_str(), uniq.c_str()); // topic - uint8_t set_state_class = 0; - enum uint8_t { MEASURE = 1, TOTAL }; + enum uint8_t { STATE_CLASS_NONE, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING }; + uint8_t set_state_class = STATE_CLASS_NONE; // default // unit of measure and map the HA icon if (uom != DeviceValueUOM::NONE) { @@ -1012,12 +1013,10 @@ void Mqtt::publish_ha_sensor(uint8_t type, // EMSdevice::Dev switch (uom) { case DeviceValueUOM::DEGREES: - doc["ic"] = F_(icondegrees); - set_state_class = MEASURE; + doc["ic"] = F_(icondegrees); break; case DeviceValueUOM::PERCENT: - doc["ic"] = F_(iconpercent); - set_state_class = MEASURE; + doc["ic"] = F_(iconpercent); break; case DeviceValueUOM::SECONDS: case DeviceValueUOM::MINUTES: @@ -1028,26 +1027,23 @@ void Mqtt::publish_ha_sensor(uint8_t type, // EMSdevice::Dev doc["ic"] = F_(iconkb); break; case DeviceValueUOM::LMIN: - doc["ic"] = F_(iconlmin); - set_state_class = MEASURE; + doc["ic"] = F_(iconlmin); break; case DeviceValueUOM::WH: case DeviceValueUOM::KWH: doc["ic"] = F_(iconkwh); - set_state_class = TOTAL; + set_state_class = STATE_CLASS_TOTAL_INCREASING; break; case DeviceValueUOM::UA: - doc["ic"] = F_(iconua); - set_state_class = MEASURE; + doc["ic"] = F_(iconua); break; case DeviceValueUOM::BAR: - doc["ic"] = F_(iconbar); - set_state_class = MEASURE; + doc["ic"] = F_(iconbar); break; case DeviceValueUOM::W: case DeviceValueUOM::KW: doc["ic"] = F_(iconkw); - set_state_class = MEASURE; + set_state_class = STATE_CLASS_MEASUREMENT; break; case DeviceValueUOM::DBM: doc["ic"] = F_(icondbm); @@ -1055,18 +1051,20 @@ void Mqtt::publish_ha_sensor(uint8_t type, // EMSdevice::Dev case DeviceValueUOM::NONE: if (type == DeviceValueType::INT || type == DeviceValueType::UINT || type == DeviceValueType::SHORT || type == DeviceValueType::USHORT || type == DeviceValueType::ULONG) { - doc["ic"] = F_(iconnum); - set_state_class = TOTAL; + doc["ic"] = F_(iconnum); } default: break; } // see if we need to set the state_class - if (set_state_class == MEASURE) { - doc["state_class"] = F("measurement"); - } else if (set_state_class == TOTAL) { - doc["state_class"] = F("total_increasing"); + // ignore any commands + if (!has_cmd) { + if (set_state_class == STATE_CLASS_MEASUREMENT) { + doc["state_class"] = F("measurement"); + } else if (set_state_class == STATE_CLASS_TOTAL_INCREASING) { + doc["state_class"] = F("total_increasing"); + } } } diff --git a/src/mqtt.h b/src/mqtt.h index b964be7c8..07ed70943 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -121,7 +121,8 @@ class Mqtt { const __FlashStringHelper * name, const uint8_t device_type, const __FlashStringHelper * entity, - const uint8_t uom = 0); + const uint8_t uom, + const bool has_cmd = false); static void register_command(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_p cb, uint8_t flags = 0); static void show_topic_handlers(uuid::console::Shell & shell, const uint8_t device_type); diff --git a/src/version.h b/src/version.h index e87f7cd11..cebdcb7ec 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.2.2b8" +#define EMSESP_APP_VERSION "3.2.2b10" From 24fae0d03e7b682b1bcf84d6304010b135a9754d Mon Sep 17 00:00:00 2001 From: proddy Date: Tue, 28 Sep 2021 16:15:53 +0200 Subject: [PATCH 2/2] updated comment --- pio_local.ini_example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pio_local.ini_example b/pio_local.ini_example index 6ca3c0b16..22478ea9a 100644 --- a/pio_local.ini_example +++ b/pio_local.ini_example @@ -16,7 +16,7 @@ my_build_flags = ; upload_port = 10.10.10.101 ; to prevent the web UI from building each time, comment out this next line -extra_scripts = +extra_scripts = scripts/rename_fw.py ; don't build WebUI ; pio run -e debug ; or from Visual Studio Code do PIO -> Project Tasks -> debug -> General -> Upload and Monitor