fix removing old HA config topics

This commit is contained in:
proddy
2021-11-20 21:22:10 +01:00
parent a63f2e6131
commit 50e54e6a1c
5 changed files with 24 additions and 25 deletions

View File

@@ -46,6 +46,7 @@
- Improved API. Restful HTTP API works in the same way as MQTT calls - 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) - 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) - 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** ## **BREAKING CHANGES**
@@ -55,3 +56,5 @@
- HA: # removed from counts in MQTT Fails, Rx fails, Rx received, Tx fails, Tx reads & Tx writes - 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 - `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" - '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`

View File

@@ -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_solarmode, F_(constant), F("pwm"), F("analog"))
MAKE_PSTR_LIST(enum_collectortype, F("flat"), F("vacuum")) 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/") MAKE_PSTR(homeassistant, "homeassistant/")
// id used to store the device ID. empty full name so only gets displayed in the MQTT payload // id used to store the device ID. empty full name so only gets displayed in the MQTT payload

View File

@@ -545,8 +545,8 @@ void Mqtt::on_connect() {
} }
// send initial MQTT messages for some of our services // send initial MQTT messages for some of our services
EMSESP::shower_.send_mqtt_stat(false); // Send shower_activated as false EMSESP::shower_.set_shower_state(false, true); // Send shower_activated as false
EMSESP::system_.send_heartbeat(); // send heatbeat EMSESP::system_.send_heartbeat(); // send heatbeat
// re-subscribe to all custom registered MQTT topics // re-subscribe to all custom registered MQTT topics
resubscribe(); 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()); LOG_DEBUG(F("[DEBUG] Publishing empty HA topic=%s"), fulltopic.c_str());
#endif #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. // 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; return;
} }
// empty payload will remove the previous config
// publish(topic);
std::string payload_text; std::string payload_text;
payload_text.reserve(measureJson(payload) + 1); payload_text.reserve(measureJson(payload) + 1);
serializeJson(payload, payload_text); // convert json to string 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 // if we're asking to remove this topic, send an empty payload
// https://github.com/emsesp/EMS-ESP32/issues/196 // https://github.com/emsesp/EMS-ESP32/issues/196
if (remove) { 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); publish_ha(topic);
return; return;
} }

View File

@@ -30,7 +30,7 @@ bool Test::run_test(const char * command, int8_t id) {
} }
if (strcmp(command, "general") == 0) { 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(0x08, 123); // Nefit Trendline
add_device(0x18, 157); // Bosch CR100 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) { 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(0x08, 123); // GB072
add_device(0x10, 158); // RC310 add_device(0x10, 158); // RC310
@@ -81,7 +81,7 @@ bool Test::run_test(const char * command, int8_t id) {
} }
if (strcmp(command, "gateway") == 0) { 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 // add 0x48 KM200, via a version command
rx_telegram({0x48, 0x0B, 0x02, 0x00, 0xBD, 0x04, 0x06, 00, 00, 00, 00, 00, 00, 00}); 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) { if (strcmp(command, "mixer") == 0) {
EMSESP::logger().info(F("Testing mixer...")); EMSESP::logger().info(F("Adding a mixer..."));
// add controller // add controller
add_device(0x09, 114); add_device(0x09, 114);
@@ -123,7 +123,7 @@ bool Test::run_test(const char * command, int8_t id) {
} }
if (strcmp(command, "boiler") == 0) { if (strcmp(command, "boiler") == 0) {
EMSESP::logger().info(F("Testing boiler...")); EMSESP::logger().info(F("Adding boiler..."));
add_device(0x08, 123); // Nefit Trendline add_device(0x08, 123); // Nefit Trendline
// UBAuptime // UBAuptime
@@ -140,7 +140,7 @@ bool Test::run_test(const char * command, int8_t id) {
} }
if (strcmp(command, "thermostat") == 0) { if (strcmp(command, "thermostat") == 0) {
EMSESP::logger().info(F("Testing thermostat...")); EMSESP::logger().info(F("Adding thermostat..."));
add_device(0x10, 192); // FW120 add_device(0x10, 192); // FW120
@@ -153,7 +153,7 @@ bool Test::run_test(const char * command, int8_t id) {
} }
if (strcmp(command, "solar") == 0) { if (strcmp(command, "solar") == 0) {
EMSESP::logger().info(F("Testing solar...")); EMSESP::logger().info(F("Adding solar..."));
add_device(0x30, 163); // SM100 add_device(0x30, 163); // SM100
@@ -172,7 +172,7 @@ bool Test::run_test(const char * command, int8_t id) {
} }
if (strcmp(command, "heatpump") == 0) { 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(0x38, 200); // Enviline module
add_device(0x10, 192); // FW120 thermostat add_device(0x10, 192); // FW120 thermostat
@@ -187,7 +187,8 @@ bool Test::run_test(const char * command, int8_t id) {
return false; 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) { void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
// switch to su // switch to su
shell.add_flags(CommandFlags::ADMIN); 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")); shell.printfln(F("Testing device value rendering"));
Mqtt::ha_enabled(true); Mqtt::ha_enabled(true);
// Mqtt::ha_enabled(false);
Mqtt::nested_format(1); Mqtt::nested_format(1);
Mqtt::send_response(false); Mqtt::send_response(false);
run_test("boiler"); run_test("boiler");
run_test("thermostat"); run_test("thermostat");
// shell.invoke_command("show");
// change a value to null/bogus/dormant // change a value to null/bogus/dormant
// homeassistant/sensor/ems-esp/boiler_wwseltemp/config
shell.invoke_command("call boiler wwseltemp"); shell.invoke_command("call boiler wwseltemp");
shell.invoke_command("call system publish"); shell.invoke_command("call system publish");
}
if (command == "dv2") {
shell.printfln(F("Testing device value lost"));
// Boiler -> Me, UBAParameterWW(0x33) // Boiler -> Me, UBAParameterWW(0x33)
// wwseltemp = goes from 52 degrees (0x34) to void (0xFF) // 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}); 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 boiler wwseltemp");
shell.invoke_command("call system publish"); shell.invoke_command("call system publish");
// shell.invoke_command("show mqtt");
} }
if (command == "api") { if (command == "api") {

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.3.0b8" #define EMSESP_APP_VERSION "3.3.0b9"