Merge pull request #1411 from proddy/dev

fix HA warnings - add a device name - #1393
This commit is contained in:
Proddy
2023-11-11 18:02:46 +01:00
committed by GitHub
9 changed files with 34 additions and 20 deletions

View File

@@ -65,7 +65,7 @@
"eslint-plugin-prettier": "alpha",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"preact": "^10.18.2",
"preact": "^10.19.1",
"prettier": "^3.0.3",
"rollup-plugin-visualizer": "^5.9.2",
"terser": "^5.24.0",

View File

@@ -1678,7 +1678,7 @@ __metadata:
jwt-decode: "npm:^4.0.0"
lodash-es: "npm:^4.17.21"
mime-types: "npm:^2.1.35"
preact: "npm:^10.18.2"
preact: "npm:^10.19.1"
prettier: "npm:^3.0.3"
react: "npm:latest"
react-dom: "npm:latest"
@@ -6758,10 +6758,10 @@ __metadata:
languageName: node
linkType: hard
"preact@npm:^10.18.2":
version: 10.18.2
resolution: "preact@npm:10.18.2"
checksum: c7dcd6ea812adb0bdc215366b14aadc44724b6dd6c4e9aadd986126d94abde62f3e02e18d6157a9984873be9877f206c0afa10a09346178c4c828a103a66a0e1
"preact@npm:^10.19.1":
version: 10.19.1
resolution: "preact@npm:10.19.1"
checksum: 1dce5b00d9031aca2266ef64cc38b27a4696f1c4d78baecc1f66a9bf2798c022a792b97257d64db450723edb69c12bc967e993d3b516734eff57895b9258c419
languageName: node
linkType: hard

View File

@@ -615,6 +615,7 @@ void AnalogSensor::publish_values(const bool force) {
}
JsonObject dev = config.createNestedObject("dev");
dev["name"] = name;
JsonArray ids = dev.createNestedArray("ids");
ids.add(Mqtt::basename());

View File

@@ -729,21 +729,24 @@ bool Mqtt::queue_ha(const char * topic, const JsonObject & payload) {
bool Mqtt::publish_ha_sensor_config(DeviceValue & dv, const char * model, const char * brand, const bool remove, const bool create_device_config) {
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> dev_json;
// always create the ids
// always create the ids (discovery indentifiers)
// with the name always
// and the manufacturer and model if we're creating the device config for the first entity
JsonArray ids = dev_json.createNestedArray("ids");
char ha_device[40];
auto device_type_name = EMSdevice::device_type_2_device_name(dv.device_type);
snprintf(ha_device, sizeof(ha_device), "%s-%s", Mqtt::basename().c_str(), device_type_name);
ids.add(ha_device);
if (create_device_config) {
auto cap_name = strdup(device_type_name);
Helpers::CharToUpperUTF8(cap_name); // capitalize first letter
dev_json["name"] = Mqtt::basename() + " " + cap_name;
free(cap_name);
if (create_device_config) {
dev_json["mf"] = brand;
dev_json["mdl"] = model;
dev_json["via_device"] = "ems-esp";
free(cap_name);
}
// calculate the min and max
@@ -778,6 +781,7 @@ bool Mqtt::publish_system_ha_sensor_config(uint8_t type, const char * name, cons
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
JsonObject dev_json = doc.createNestedObject("dev");
dev_json["name"] = Mqtt::basename();
JsonArray ids = dev_json.createNestedArray("ids");
ids.add(Mqtt::basename());
@@ -1245,6 +1249,9 @@ bool Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp,
snprintf(ha_device, sizeof(ha_device), "%s-thermostat", Mqtt::basename().c_str());
ids.add(ha_device);
// device name must be different to the entity name, take the ids value we just created
dev["name"] = ha_device;
// add "availability" section
add_avty_to_doc(topic_t, doc.as<JsonObject>(), seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond);

View File

@@ -211,6 +211,7 @@ void Shower::set_shower_state(bool state, bool force) {
}
JsonObject dev = doc.createNestedObject("dev");
dev["name"] = "EMS-ESP";
JsonArray ids = dev.createNestedArray("ids");
ids.add(Mqtt::basename());
@@ -240,6 +241,7 @@ void Shower::set_shower_state(bool state, bool force) {
doc["ent_cat"] = "diagnostic";
JsonObject dev2 = doc.createNestedObject("dev");
dev2["name"] = "EMS-ESP";
JsonArray ids2 = dev2.createNestedArray("ids");
ids2.add(Mqtt::basename());
@@ -266,6 +268,7 @@ void Shower::set_shower_state(bool state, bool force) {
doc["ent_cat"] = "diagnostic";
JsonObject dev3 = doc.createNestedObject("dev");
dev3["name"] = "EMS-ESP";
JsonArray ids3 = dev3.createNestedArray("ids");
ids3.add(Mqtt::basename());

View File

@@ -542,6 +542,7 @@ void TemperatureSensor::publish_values(const bool force) {
config["name"] = name;
JsonObject dev = config.createNestedObject("dev");
dev["name"] = Mqtt::basename();
JsonArray ids = dev.createNestedArray("ids");
ids.add(Mqtt::basename());

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.6.3-dev.6"
#define EMSESP_APP_VERSION "3.6.3-dev.7"

View File

@@ -410,6 +410,7 @@ void WebCustomEntityService::publish(const bool force) {
}
}
JsonObject dev = config.createNestedObject("dev");
dev["name"] = Mqtt::basename();
JsonArray ids = dev.createNestedArray("ids");
ids.add(Mqtt::basename());

View File

@@ -288,6 +288,7 @@ void WebSchedulerService::publish(const bool force) {
}
JsonObject dev = config.createNestedObject("dev");
dev["name"] = Mqtt::basename();
JsonArray ids = dev.createNestedArray("ids");
ids.add(Mqtt::basename());