From 50e54e6a1c7956cfce946f7ed14e747b8ef0db86 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 20 Nov 2021 21:22:10 +0100 Subject: [PATCH] fix removing old HA config topics --- CHANGELOG_LATEST.md | 3 +++ src/locale_EN.h | 2 +- src/mqtt.cpp | 11 ++++------- src/test/test.cpp | 31 +++++++++++++++---------------- src/version.h | 2 +- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 6c21ec375..34ce60043 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -46,6 +46,7 @@ - Improved API. Restful HTTP API works in the same way as MQTT calls - Removed settings for MQTT subscribe format [#173](https://github.com/emsesp/EMS-ESP32/issues/173) - Improve Nefit Moduline 200 functionality [#183](https://github.com/emsesp/EMS-ESP32/issues/183) +- `status` in the MQTT heartbeat renamed to `bus_status` ## **BREAKING CHANGES** @@ -55,3 +56,5 @@ - HA: # removed from counts in MQTT Fails, Rx fails, Rx received, Tx fails, Tx reads & Tx writes - `txread` renamed to `txreads` and `txwrite` renamed to `txwrites` in MQTT heartbeat payload - 'dallas sensors' in api/system/info moved to the "System" section. Renamed "uptime (seconds)" and "reset reason" +- `status` in the MQTT heartbeat renamed to `bus_status` + diff --git a/src/locale_EN.h b/src/locale_EN.h index f36878d5a..8ccf6da7b 100644 --- a/src/locale_EN.h +++ b/src/locale_EN.h @@ -370,7 +370,7 @@ MAKE_PSTR_LIST(enum_progMode4, F("prog_a"), F("prog_b"), F("prog_c"), F("prog_d" MAKE_PSTR_LIST(enum_solarmode, F_(constant), F("pwm"), F("analog")) MAKE_PSTR_LIST(enum_collectortype, F("flat"), F("vacuum")) -// MQTT topics and full text for values and commands +// MQTT topic for homeassistant. Must include / MAKE_PSTR(homeassistant, "homeassistant/") // id used to store the device ID. empty full name so only gets displayed in the MQTT payload diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 2018d4264..698424a6c 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -545,8 +545,8 @@ void Mqtt::on_connect() { } // send initial MQTT messages for some of our services - EMSESP::shower_.send_mqtt_stat(false); // Send shower_activated as false - EMSESP::system_.send_heartbeat(); // send heatbeat + EMSESP::shower_.set_shower_state(false, true); // Send shower_activated as false + EMSESP::system_.send_heartbeat(); // send heatbeat // re-subscribe to all custom registered MQTT topics resubscribe(); @@ -749,7 +749,7 @@ void Mqtt::publish_ha(const std::string & topic) { LOG_DEBUG(F("[DEBUG] Publishing empty HA topic=%s"), fulltopic.c_str()); #endif - publish(topic); // call it immediately, don't queue it + publish(fulltopic); // call it immediately, don't queue it } // publish a Home Assistant config topic and payload, with retain flag off. @@ -758,9 +758,6 @@ void Mqtt::publish_ha(const std::string & topic, const JsonObject & payload) { return; } - // empty payload will remove the previous config - // publish(topic); - std::string payload_text; payload_text.reserve(measureJson(payload) + 1); serializeJson(payload, payload_text); // convert json to string @@ -908,7 +905,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevi // if we're asking to remove this topic, send an empty payload // https://github.com/emsesp/EMS-ESP32/issues/196 if (remove) { - LOG_WARNING(F("Device value %s gone silent. Removing HA config topic %s"), uniq.c_str(), topic); + LOG_WARNING(F("Lost device value for %s. Removing HA config"), uniq.c_str()); publish_ha(topic); return; } diff --git a/src/test/test.cpp b/src/test/test.cpp index d0a6fe8d8..e6fed390b 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -30,7 +30,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "general") == 0) { - EMSESP::logger().info(F("Testing general...")); + EMSESP::logger().info(F("Testing general. Adding a Boiler and Thermostat")); add_device(0x08, 123); // Nefit Trendline add_device(0x18, 157); // Bosch CR100 @@ -54,7 +54,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "310") == 0) { - EMSESP::logger().info(F("Testing GB072/RC310...")); + EMSESP::logger().info(F("Adding a GB072/RC310 combo...")); add_device(0x08, 123); // GB072 add_device(0x10, 158); // RC310 @@ -81,7 +81,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "gateway") == 0) { - EMSESP::logger().info(F("Testing gateway...")); + EMSESP::logger().info(F("Adding a Gateway...")); // add 0x48 KM200, via a version command rx_telegram({0x48, 0x0B, 0x02, 0x00, 0xBD, 0x04, 0x06, 00, 00, 00, 00, 00, 00, 00}); @@ -101,7 +101,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "mixer") == 0) { - EMSESP::logger().info(F("Testing mixer...")); + EMSESP::logger().info(F("Adding a mixer...")); // add controller add_device(0x09, 114); @@ -123,7 +123,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "boiler") == 0) { - EMSESP::logger().info(F("Testing boiler...")); + EMSESP::logger().info(F("Adding boiler...")); add_device(0x08, 123); // Nefit Trendline // UBAuptime @@ -140,7 +140,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "thermostat") == 0) { - EMSESP::logger().info(F("Testing thermostat...")); + EMSESP::logger().info(F("Adding thermostat...")); add_device(0x10, 192); // FW120 @@ -153,7 +153,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "solar") == 0) { - EMSESP::logger().info(F("Testing solar...")); + EMSESP::logger().info(F("Adding solar...")); add_device(0x30, 163); // SM100 @@ -172,7 +172,7 @@ bool Test::run_test(const char * command, int8_t id) { } if (strcmp(command, "heatpump") == 0) { - EMSESP::logger().info(F("Testing heatpump...")); + EMSESP::logger().info(F("Adding heatpump...")); add_device(0x38, 200); // Enviline module add_device(0x10, 192); // FW120 thermostat @@ -187,7 +187,8 @@ bool Test::run_test(const char * command, int8_t id) { return false; } -// used with the 'test' command, under su/admin +// These next tests are run from the Console +// using the test command void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { // switch to su shell.add_flags(CommandFlags::ADMIN); @@ -475,29 +476,27 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { shell.printfln(F("Testing device value rendering")); Mqtt::ha_enabled(true); - // Mqtt::ha_enabled(false); - Mqtt::nested_format(1); Mqtt::send_response(false); run_test("boiler"); run_test("thermostat"); - // shell.invoke_command("show"); - // change a value to null/bogus/dormant - // homeassistant/sensor/ems-esp/boiler_wwseltemp/config shell.invoke_command("call boiler wwseltemp"); shell.invoke_command("call system publish"); + } + + if (command == "dv2") { + shell.printfln(F("Testing device value lost")); // Boiler -> Me, UBAParameterWW(0x33) // wwseltemp = goes from 52 degrees (0x34) to void (0xFF) + // it should delete the HA config topic homeassistant/sensor/ems-esp/boiler_wwseltemp/config uart_telegram({0x08, 0x0B, 0x33, 0x00, 0x08, 0xFF, 0xFF, 0xFB, 0x00, 0x28, 0x00, 0x00, 0x46, 0x00, 0xFF, 0xFF, 0x00}); shell.invoke_command("call boiler wwseltemp"); shell.invoke_command("call system publish"); - - // shell.invoke_command("show mqtt"); } if (command == "api") { diff --git a/src/version.h b/src/version.h index 215017a09..213091a59 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.3.0b8" +#define EMSESP_APP_VERSION "3.3.0b9"