From 147be12583b41d031081dbdbee63b3e09dc6d84d Mon Sep 17 00:00:00 2001 From: Proddy Date: Fri, 16 Dec 2022 22:57:59 +0100 Subject: [PATCH 1/2] fixes for #804 --- CHANGELOG_LATEST.md | 2 +- .../src/framework/mqtt/MqttSettingsForm.tsx | 4 ++-- interface/src/i18n/de/index.ts | 2 +- interface/src/i18n/en/index.ts | 2 +- interface/src/i18n/fr/index.ts | 2 +- interface/src/i18n/nl/index.ts | 2 +- interface/src/i18n/no/index.ts | 2 +- interface/src/i18n/pl/index.ts | 2 +- interface/src/i18n/se/index.ts | 2 +- lib/framework/MqttSettingsService.cpp | 16 +++++++--------- src/analogsensor.cpp | 9 +++++---- src/dallassensor.cpp | 9 +++++---- src/emsdevicevalue.cpp | 7 +++---- src/helpers.cpp | 4 ++++ src/locale_common.h | 2 +- src/mqtt.cpp | 19 +++++++++++++++++-- src/shower.cpp | 6 +++++- src/system.cpp | 10 +++++----- src/test/test.h | 4 ++-- 19 files changed, 64 insertions(+), 42 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 2249b9158..b9f9cd22f 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -5,7 +5,7 @@ ## **IMPORTANT! BREAKING CHANGES** - When upgrading to v3.5 for the first time from v3.4 on a BBQKees Gateway board you will need to use the [EMS-EPS Flasher](https://github.com/emsesp/EMS-ESP-Flasher/releases) to correctly re-partition the flash. Make sure you backup the settings and customizations from the WebUI (System->Upload/Download) and restore after the upgrade. -- Since 3.5.0b11 we have added support for multiple EMS-ESPs [#759] and also renamed the HA Entity IDs. For example what was previously `sensor.boiler_actual_boiler_temperature` is now using the shortname form `sensor.boiler_boiltemp` as opposed to the English description. Unfortunately this does means any HA dashboards, automation scripts and integrations (e.g. Grafana) need to be adjusted accordingly. +- Since 3.5.0b11 we have added support for multiple EMS-ESPs [#759] as an optional setting in MQTT. When this is enabled, which is now the default, all MQTT Discovery Entity IDs will include the base name and the shortname of the EMS-ESP device entity. For example what was previously `sensor.boiler_actual_boiler_temperature` will become `sensor.ems-esp_boiler_boiltemp`. If you still want to use the old format and retain the history and script compatibility in Home Assistant then set this back to the old format. ## Added diff --git a/interface/src/framework/mqtt/MqttSettingsForm.tsx b/interface/src/framework/mqtt/MqttSettingsForm.tsx index 85f468771..ef78c8436 100644 --- a/interface/src/framework/mqtt/MqttSettingsForm.tsx +++ b/interface/src/framework/mqtt/MqttSettingsForm.tsx @@ -245,8 +245,8 @@ const MqttSettingsForm: FC = () => { margin="normal" select > - {LL.MQTT_ENTITY_FORMAT_0()} - {LL.MQTT_ENTITY_FORMAT_1()} + {LL.MQTT_ENTITY_FORMAT_0()} + {LL.MQTT_ENTITY_FORMAT_1()} diff --git a/interface/src/i18n/de/index.ts b/interface/src/i18n/de/index.ts index f480b9c51..5ee053fca 100644 --- a/interface/src/i18n/de/index.ts +++ b/interface/src/i18n/de/index.ts @@ -250,7 +250,7 @@ const de: Translation = { MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Standard', MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name', + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)', MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name', MQTT_CLEAN_SESSION: 'Setze `Clean Session`', MQTT_RETAIN_FLAG: 'Setze `Retain flag` immer', diff --git a/interface/src/i18n/en/index.ts b/interface/src/i18n/en/index.ts index e76450b70..95f386a5f 100644 --- a/interface/src/i18n/en/index.ts +++ b/interface/src/i18n/en/index.ts @@ -249,7 +249,7 @@ const en: Translation = { MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Default', MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name', + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)', MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name', MQTT_CLEAN_SESSION: 'Set Clean Session', MQTT_RETAIN_FLAG: 'Always set Retain flag', diff --git a/interface/src/i18n/fr/index.ts b/interface/src/i18n/fr/index.ts index 659c96359..8665ddb2a 100644 --- a/interface/src/i18n/fr/index.ts +++ b/interface/src/i18n/fr/index.ts @@ -249,7 +249,7 @@ const fr: Translation = { MQTT_QUEUE: 'Queue MQTT', DEFAULT: 'Défaut', MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name', + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)', MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name', MQTT_CLEAN_SESSION: 'Flag Clean Session', MQTT_RETAIN_FLAG: 'Toujours activer le Retain Flag', diff --git a/interface/src/i18n/nl/index.ts b/interface/src/i18n/nl/index.ts index dc250c99b..41cfe4bae 100644 --- a/interface/src/i18n/nl/index.ts +++ b/interface/src/i18n/nl/index.ts @@ -249,7 +249,7 @@ const nl: Translation = { MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Default', MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name', + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)', MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name', MQTT_CLEAN_SESSION: 'Clean Session aan', MQTT_RETAIN_FLAG: 'Retain flag aan', diff --git a/interface/src/i18n/no/index.ts b/interface/src/i18n/no/index.ts index b9e7db89c..2eaf3e2fd 100644 --- a/interface/src/i18n/no/index.ts +++ b/interface/src/i18n/no/index.ts @@ -249,7 +249,7 @@ const no: Translation = { MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Standard', MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name', + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)', MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name', MQTT_CLEAN_SESSION: 'Benytt Clean Session', MQTT_RETAIN_FLAG: 'Alltid sett Retain flag', diff --git a/interface/src/i18n/pl/index.ts b/interface/src/i18n/pl/index.ts index ed542e798..8e023ed85 100644 --- a/interface/src/i18n/pl/index.ts +++ b/interface/src/i18n/pl/index.ts @@ -249,7 +249,7 @@ const pl: BaseTranslation = { MQTT_QUEUE: 'Kolejka MQTT', DEFAULT: '{{Pozostałe|Domyślna|}}', MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name', + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)', MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name', MQTT_CLEAN_SESSION: 'Ustawiaj flagę "Clean session"', MQTT_RETAIN_FLAG: 'Ustawiaj flagę "Retain"', diff --git a/interface/src/i18n/se/index.ts b/interface/src/i18n/se/index.ts index 99e33eebc..74a2898c2 100644 --- a/interface/src/i18n/se/index.ts +++ b/interface/src/i18n/se/index.ts @@ -249,7 +249,7 @@ const se: Translation = { MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Standard', MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name', + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)', MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name', MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan', MQTT_RETAIN_FLAG: 'Använd "Always Retain"-flaggan', diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index aa6198706..a52af34f6 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -223,6 +223,10 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting changed = true; } + if (newSettings.multiple_instances != settings.multiple_instances) { + changed = true; + } + // if both settings are stored from older version, HA has priority if (newSettings.ha_enabled && newSettings.publish_single) { newSettings.publish_single = false; @@ -258,44 +262,38 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting if (newSettings.publish_time_boiler != settings.publish_time_boiler) { emsesp::EMSESP::mqtt_.set_publish_time_boiler(newSettings.publish_time_boiler); - changed = true; } if (newSettings.publish_time_thermostat != settings.publish_time_thermostat) { emsesp::EMSESP::mqtt_.set_publish_time_thermostat(newSettings.publish_time_thermostat); - changed = true; } if (newSettings.publish_time_solar != settings.publish_time_solar) { emsesp::EMSESP::mqtt_.set_publish_time_solar(newSettings.publish_time_solar); - changed = true; } if (newSettings.publish_time_mixer != settings.publish_time_mixer) { emsesp::EMSESP::mqtt_.set_publish_time_mixer(newSettings.publish_time_mixer); - changed = true; } if (newSettings.publish_time_other != settings.publish_time_other) { emsesp::EMSESP::mqtt_.set_publish_time_other(newSettings.publish_time_other); - changed = true; } if (newSettings.publish_time_sensor != settings.publish_time_sensor) { emsesp::EMSESP::mqtt_.set_publish_time_sensor(newSettings.publish_time_sensor); - changed = true; } if (newSettings.publish_time_heartbeat != settings.publish_time_heartbeat) { emsesp::EMSESP::mqtt_.set_publish_time_heartbeat(newSettings.publish_time_heartbeat); - changed = true; } + // save the new settings + settings = newSettings; + if (changed) { emsesp::EMSESP::mqtt_.reset_mqtt(); } - settings = newSettings; - return StateUpdateResult::CHANGED; } diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index ffb02bb7c..da7c350f3 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -451,14 +451,15 @@ void AnalogSensor::publish_values(const bool force) { } config["val_tpl"] = str; + char uniq_s[70]; if (Mqtt::multiple_instances()) { - snprintf(str, sizeof(str), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio()); + snprintf(uniq_s, sizeof(uniq_s), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio()); } else { - snprintf(str, sizeof(str), "analogsensor_%d", sensor.gpio()); + snprintf(uniq_s, sizeof(uniq_s), "analogsensor_%d", sensor.gpio()); } - config["object_id"] = str; - config["uniq_id"] = str; // same as object_id + config["object_id"] = uniq_s; + config["uniq_id"] = uniq_s; // same as object_id snprintf(str, sizeof(str), "%s", sensor.name().c_str()); config["name"] = str; diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index d58f22d7c..59607909b 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -518,14 +518,15 @@ void DallasSensor::publish_values(const bool force) { } config["val_tpl"] = str; + char uniq_s[70]; if (Mqtt::multiple_instances()) { - snprintf(str, sizeof(str), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str()); + snprintf(uniq_s, sizeof(uniq_s), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str()); } else { - snprintf(str, sizeof(str), "dallassensor_%s", sensor.id().c_str()); + snprintf(uniq_s, sizeof(uniq_s), "dallassensor_%s", sensor.id().c_str()); } - config["object_id"] = str; - config["uniq_id"] = str; // same as object_id + config["object_id"] = uniq_s; + config["uniq_id"] = uniq_s; // same as object_id snprintf(str, sizeof(str), "%s", sensor.name().c_str()); config["name"] = str; diff --git a/src/emsdevicevalue.cpp b/src/emsdevicevalue.cpp index 20e4d463a..c3d2cc0fe 100644 --- a/src/emsdevicevalue.cpp +++ b/src/emsdevicevalue.cpp @@ -105,10 +105,9 @@ DeviceValue::DeviceValue(uint8_t device_type, // must be an int of 4 bytes, 32bit aligned const char * DeviceValue::DeviceValueUOM_s[] = { - F_(uom_blank), F_(uom_degrees), F_(uom_degrees), F_(uom_percent), F_(uom_lmin), F_(uom_kwh), F_(uom_wh), - FL_(hours)[0], FL_(minutes)[0], F_(uom_ua), F_(uom_bar), F_(uom_kw), F_(uom_w), F_(uom_kb), - FL_(seconds)[0], F_(uom_dbm), F_(uom_fahrenheit), F_(uom_mv), F_(uom_sqm), F_(uom_m3), - F_(uom_blank) // connectivity + F_(uom_blank), F_(uom_degrees), F_(uom_degrees), F_(uom_percent), F_(uom_lmin), F_(uom_kwh), F_(uom_wh), FL_(hours)[0], + FL_(minutes)[0], F_(uom_ua), F_(uom_bar), F_(uom_kw), F_(uom_w), F_(uom_kb), FL_(seconds)[0], F_(uom_dbm), + F_(uom_fahrenheit), F_(uom_mv), F_(uom_sqm), F_(uom_m3), F_(uom_blank) }; diff --git a/src/helpers.cpp b/src/helpers.cpp index 6865f9081..5b4cad590 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -678,6 +678,10 @@ std::string Helpers::toUpper(std::string const & s) { // replace char in char string void Helpers::replace_char(char * str, char find, char replace) { + if (str == nullptr) { + return; + } + int i = 0; while (str[i] != '\0') { diff --git a/src/locale_common.h b/src/locale_common.h index fdc4b59fa..9c4879147 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -224,7 +224,7 @@ MAKE_PSTR(tag_boiler_data_ww_mqtt, "ww") MAKE_PSTR(tag_device_data_ww_mqtt, "") // Home Assistant - this is special and has no translations -MAKE_PSTR_LIST(climate, "HA climate config creation") +MAKE_PSTR_LIST(climate, "") // syslog MAKE_PSTR_LIST(list_syslog_level, "off", "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", "trace", "all") diff --git a/src/mqtt.cpp b/src/mqtt.cpp index d279fc931..2b36aba8d 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -974,7 +974,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev const int16_t dv_set_max, const JsonObject & dev_json) { // ignore if name (fullname) is empty - if (!fullname) { + if (!fullname || !en_name) { return; } @@ -990,13 +990,28 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } // build unique identifier which will be used in the topic, also used as object_id + // and becomes the Entity ID in HA char uniq_id[70]; if (Mqtt::multiple_instances()) { // prefix base name to each uniq_id and use the shortname snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag); } else { // old v3.4 style - snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, en_name); + // if there is no en_name take the shortname + if (en_name == nullptr || strlen(en_name) == 0) { + strlcpy(uniq_id, entity, sizeof(uniq_id)); + } else { + // old v3.4 style + // take en_name and replace all spaces and lowercase it + char uniq_s[40]; + strlcpy(uniq_s, en_name, sizeof(uniq_s)); + Helpers::replace_char(uniq_s, ' ', '_'); + if (EMSdevice::tag_to_string(tag).empty()) { + snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str()); + } else { + snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", device_name, EMSdevice::tag_to_string(tag).c_str(), Helpers::toLower(uniq_s).c_str()); + } + } } // build a config topic that will be prefix onto a HA type (e.g. number, switch) diff --git a/src/shower.cpp b/src/shower.cpp index fa43a6f05..61c5f9ab6 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -155,7 +155,11 @@ void Shower::set_shower_state(bool state, bool force) { doc["name"] = "Shower Active"; char str[70]; - snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str()); + if (Mqtt::multiple_instances()) { + snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str()); + } else { + snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible + } doc["uniq_id"] = str; doc["object_id"] = str; diff --git a/src/system.cpp b/src/system.cpp index 5275a2a1a..b7e23086d 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -1059,11 +1059,11 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp JsonObject node; // System - node = output.createNestedObject("System Info"); - node["version"] = EMSESP_APP_VERSION; - node["platform"] = EMSESP_PLATFORM; - node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3); - // node["uptime (seconds)"] = uuid::get_uptime_sec(); + node = output.createNestedObject("System Info"); + node["version"] = EMSESP_APP_VERSION; + node["platform"] = EMSESP_PLATFORM; + node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3); + node["uptime (seconds)"] = uuid::get_uptime_sec(); #ifndef EMSESP_STANDALONE node["free mem"] = ESP.getFreeHeap() / 1024; // kilobytes node["max alloc"] = ESP.getMaxAllocHeap() / 1024; // kilobytes diff --git a/src/test/test.h b/src/test/test.h index e8d7a287e..5abd892bc 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -30,12 +30,12 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "solar" // #define EMSESP_DEBUG_DEFAULT "mixer" // #define EMSESP_DEBUG_DEFAULT "web" -#define EMSESP_DEBUG_DEFAULT "mqtt" +// #define EMSESP_DEBUG_DEFAULT "mqtt" // #define EMSESP_DEBUG_DEFAULT "general" // #define EMSESP_DEBUG_DEFAULT "boiler" // #define EMSESP_DEBUG_DEFAULT "mqtt2" // #define EMSESP_DEBUG_DEFAULT "mqtt_nested" -// #define EMSESP_DEBUG_DEFAULT "ha" +#define EMSESP_DEBUG_DEFAULT "ha" // #define EMSESP_DEBUG_DEFAULT "masked" // #define EMSESP_DEBUG_DEFAULT "board_profile" // #define EMSESP_DEBUG_DEFAULT "shower_alert" From 4b7bbb3d502b6f6eb44db9bac493180c95672a7c Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 17 Dec 2022 11:05:20 +0100 Subject: [PATCH 2/2] minor cleanup and testing --- CHANGELOG_LATEST.md | 2 +- interface/package-lock.json | 64 ++++++++++++++++++------------------- interface/package.json | 4 +-- src/mqtt.cpp | 23 +++++-------- 4 files changed, 43 insertions(+), 50 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index b9f9cd22f..b585670a0 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -5,7 +5,7 @@ ## **IMPORTANT! BREAKING CHANGES** - When upgrading to v3.5 for the first time from v3.4 on a BBQKees Gateway board you will need to use the [EMS-EPS Flasher](https://github.com/emsesp/EMS-ESP-Flasher/releases) to correctly re-partition the flash. Make sure you backup the settings and customizations from the WebUI (System->Upload/Download) and restore after the upgrade. -- Since 3.5.0b11 we have added support for multiple EMS-ESPs [#759] as an optional setting in MQTT. When this is enabled, which is now the default, all MQTT Discovery Entity IDs will include the base name and the shortname of the EMS-ESP device entity. For example what was previously `sensor.boiler_actual_boiler_temperature` will become `sensor.ems-esp_boiler_boiltemp`. If you still want to use the old format and retain the history and script compatibility in Home Assistant then set this back to the old format. +- Support for multiple EMS-ESPs [#759] has been added as an optional setting for MQTT. When enabled, which is now the default, all MQTT Discovery Entity IDs will include the MQTT base name and the shortname of the EMS-ESP device entity. For example what was previously `sensor.boiler_actual_boiler_temperature` will now become `sensor.ems_esp_boiler_boiltemp`. If you still want to use the old format and retain the history and script compatibility in Home Assistant then set this back to the old format. ## Added diff --git a/interface/package-lock.json b/interface/package-lock.json index d954a2317..6d51b4195 100644 --- a/interface/package-lock.json +++ b/interface/package-lock.json @@ -15,7 +15,7 @@ "@mui/material": "^5.11.0", "@table-library/react-table-library": "4.0.23", "@types/lodash": "^4.14.191", - "@types/node": "^18.11.15", + "@types/node": "^18.11.16", "@types/react": "^18.0.26", "@types/react-dom": "^18.0.9", "@types/react-router-dom": "^5.3.3", @@ -31,7 +31,7 @@ "react-dom": "^18.2.0", "react-dropzone": "^14.2.3", "react-icons": "^4.7.1", - "react-router-dom": "^6.4.5", + "react-router-dom": "^6.5.0", "react-scripts": "5.0.1", "sockette": "^2.0.6", "typesafe-i18n": "^5.17.1", @@ -3458,9 +3458,9 @@ } }, "node_modules/@remix-run/router": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.5.tgz", - "integrity": "sha512-my0Mycd+jruq/1lQuO5LBB6WTlL/e8DTCYWp44DfMTDcXz8DcTlgF0ISaLsGewt+ctHN+yA8xMq3q/N7uWJPug==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.1.0.tgz", + "integrity": "sha512-rGl+jH/7x1KBCQScz9p54p0dtPLNeKGb3e0wD2H5/oZj41bwQUnXdzbj2TbUAFhvD7cp9EyEQA4dEgpUFa1O7Q==", "engines": { "node": ">=14" } @@ -4017,9 +4017,9 @@ "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==" }, "node_modules/@types/node": { - "version": "18.11.15", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz", - "integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==" + "version": "18.11.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.16.tgz", + "integrity": "sha512-6T7P5bDkRhqRxrQtwj7vru+bWTpelgtcETAZEUSdq0YISKz8WKdoBukQLYQQ6DFHvU9JRsbFq0JH5C51X2ZdnA==" }, "node_modules/@types/parse-json": { "version": "4.0.0", @@ -14561,11 +14561,11 @@ } }, "node_modules/react-router": { - "version": "6.4.5", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.5.tgz", - "integrity": "sha512-1RQJ8bM70YEumHIlNUYc6mFfUDoWa5EgPDenK/fq0bxD8DYpQUi/S6Zoft+9DBrh2xmtg92N5HMAJgGWDhKJ5Q==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.5.0.tgz", + "integrity": "sha512-fqqUSU0NC0tSX0sZbyuxzuAzvGqbjiZItBQnyicWlOUmzhAU8YuLgRbaCL2hf3sJdtRy4LP/WBrWtARkMvdGPQ==", "dependencies": { - "@remix-run/router": "1.0.5" + "@remix-run/router": "1.1.0" }, "engines": { "node": ">=14" @@ -14575,12 +14575,12 @@ } }, "node_modules/react-router-dom": { - "version": "6.4.5", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.5.tgz", - "integrity": "sha512-a7HsgikBR0wNfroBHcZUCd9+mLRqZS8R5U1Z1mzLWxFXEkUT3vR1XXmSIVoVpxVX8Bar0nQYYYc9Yipq8dWwAA==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.5.0.tgz", + "integrity": "sha512-/XzRc5fq80gW1ctiIGilyKFZC/j4kfe75uivMsTChFbkvrK4ZrF3P3cGIc1f/SSkQ4JiJozPrf+AwUHHWVehVg==", "dependencies": { - "@remix-run/router": "1.0.5", - "react-router": "6.4.5" + "@remix-run/router": "1.1.0", + "react-router": "6.5.0" }, "engines": { "node": ">=14" @@ -19818,9 +19818,9 @@ "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==" }, "@remix-run/router": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.5.tgz", - "integrity": "sha512-my0Mycd+jruq/1lQuO5LBB6WTlL/e8DTCYWp44DfMTDcXz8DcTlgF0ISaLsGewt+ctHN+yA8xMq3q/N7uWJPug==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.1.0.tgz", + "integrity": "sha512-rGl+jH/7x1KBCQScz9p54p0dtPLNeKGb3e0wD2H5/oZj41bwQUnXdzbj2TbUAFhvD7cp9EyEQA4dEgpUFa1O7Q==" }, "@rollup/plugin-babel": { "version": "5.3.1", @@ -20232,9 +20232,9 @@ "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==" }, "@types/node": { - "version": "18.11.15", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz", - "integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==" + "version": "18.11.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.16.tgz", + "integrity": "sha512-6T7P5bDkRhqRxrQtwj7vru+bWTpelgtcETAZEUSdq0YISKz8WKdoBukQLYQQ6DFHvU9JRsbFq0JH5C51X2ZdnA==" }, "@types/parse-json": { "version": "4.0.0", @@ -27723,20 +27723,20 @@ "integrity": "sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==" }, "react-router": { - "version": "6.4.5", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.5.tgz", - "integrity": "sha512-1RQJ8bM70YEumHIlNUYc6mFfUDoWa5EgPDenK/fq0bxD8DYpQUi/S6Zoft+9DBrh2xmtg92N5HMAJgGWDhKJ5Q==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.5.0.tgz", + "integrity": "sha512-fqqUSU0NC0tSX0sZbyuxzuAzvGqbjiZItBQnyicWlOUmzhAU8YuLgRbaCL2hf3sJdtRy4LP/WBrWtARkMvdGPQ==", "requires": { - "@remix-run/router": "1.0.5" + "@remix-run/router": "1.1.0" } }, "react-router-dom": { - "version": "6.4.5", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.5.tgz", - "integrity": "sha512-a7HsgikBR0wNfroBHcZUCd9+mLRqZS8R5U1Z1mzLWxFXEkUT3vR1XXmSIVoVpxVX8Bar0nQYYYc9Yipq8dWwAA==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.5.0.tgz", + "integrity": "sha512-/XzRc5fq80gW1ctiIGilyKFZC/j4kfe75uivMsTChFbkvrK4ZrF3P3cGIc1f/SSkQ4JiJozPrf+AwUHHWVehVg==", "requires": { - "@remix-run/router": "1.0.5", - "react-router": "6.4.5" + "@remix-run/router": "1.1.0", + "react-router": "6.5.0" } }, "react-scripts": { diff --git a/interface/package.json b/interface/package.json index bda56b4c0..8d95636ef 100644 --- a/interface/package.json +++ b/interface/package.json @@ -11,7 +11,7 @@ "@mui/material": "^5.11.0", "@table-library/react-table-library": "4.0.23", "@types/lodash": "^4.14.191", - "@types/node": "^18.11.15", + "@types/node": "^18.11.16", "@types/react": "^18.0.26", "@types/react-dom": "^18.0.9", "@types/react-router-dom": "^5.3.3", @@ -27,7 +27,7 @@ "react-dom": "^18.2.0", "react-dropzone": "^14.2.3", "react-icons": "^4.7.1", - "react-router-dom": "^6.4.5", + "react-router-dom": "^6.5.0", "react-scripts": "5.0.1", "sockette": "^2.0.6", "typesafe-i18n": "^5.17.1", diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 2b36aba8d..38817bdce 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -989,28 +989,21 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev snprintf(entity_with_tag, sizeof(entity_with_tag), "%s", entity); } - // build unique identifier which will be used in the topic, also used as object_id - // and becomes the Entity ID in HA + // build unique identifier also used as object_id and becomes the Entity ID in HA char uniq_id[70]; if (Mqtt::multiple_instances()) { // prefix base name to each uniq_id and use the shortname snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag); } else { // old v3.4 style - // if there is no en_name take the shortname - if (en_name == nullptr || strlen(en_name) == 0) { - strlcpy(uniq_id, entity, sizeof(uniq_id)); + // take en_name and replace all spaces and lowercase it + char uniq_s[40]; + strlcpy(uniq_s, en_name, sizeof(uniq_s)); + Helpers::replace_char(uniq_s, ' ', '_'); + if (EMSdevice::tag_to_string(tag).empty()) { + snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str()); } else { - // old v3.4 style - // take en_name and replace all spaces and lowercase it - char uniq_s[40]; - strlcpy(uniq_s, en_name, sizeof(uniq_s)); - Helpers::replace_char(uniq_s, ' ', '_'); - if (EMSdevice::tag_to_string(tag).empty()) { - snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str()); - } else { - snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", device_name, EMSdevice::tag_to_string(tag).c_str(), Helpers::toLower(uniq_s).c_str()); - } + snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", device_name, EMSdevice::tag_to_string(tag).c_str(), Helpers::toLower(uniq_s).c_str()); } }