mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
Merge pull request #1411 from proddy/dev
fix HA warnings - add a device name - #1393
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -615,7 +615,8 @@ void AnalogSensor::publish_values(const bool force) {
|
||||
}
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
dev["name"] = name;
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
// add "availability" section
|
||||
|
||||
19
src/mqtt.cpp
19
src/mqtt.cpp
@@ -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);
|
||||
|
||||
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) {
|
||||
auto cap_name = strdup(device_type_name);
|
||||
Helpers::CharToUpperUTF8(cap_name); // capitalize first letter
|
||||
dev_json["name"] = Mqtt::basename() + " " + cap_name;
|
||||
dev_json["mf"] = brand;
|
||||
dev_json["mdl"] = model;
|
||||
dev_json["via_device"] = "ems-esp";
|
||||
free(cap_name);
|
||||
}
|
||||
|
||||
// calculate the min and max
|
||||
@@ -778,7 +781,8 @@ 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");
|
||||
|
||||
JsonArray ids = dev_json.createNestedArray("ids");
|
||||
dev_json["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev_json.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
return publish_ha_sensor_config(
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -211,7 +211,8 @@ void Shower::set_shower_state(bool state, bool force) {
|
||||
}
|
||||
|
||||
JsonObject dev = doc.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
dev["name"] = "EMS-ESP";
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
Mqtt::add_avty_to_doc(stat_t, doc.as<JsonObject>()); // add "availability" section
|
||||
@@ -240,7 +241,8 @@ void Shower::set_shower_state(bool state, bool force) {
|
||||
doc["ent_cat"] = "diagnostic";
|
||||
|
||||
JsonObject dev2 = doc.createNestedObject("dev");
|
||||
JsonArray ids2 = dev2.createNestedArray("ids");
|
||||
dev2["name"] = "EMS-ESP";
|
||||
JsonArray ids2 = dev2.createNestedArray("ids");
|
||||
ids2.add(Mqtt::basename());
|
||||
|
||||
Mqtt::add_avty_to_doc(stat_t, doc.as<JsonObject>(), "value_json.duration is defined"); // add "availability" section
|
||||
@@ -266,7 +268,8 @@ void Shower::set_shower_state(bool state, bool force) {
|
||||
doc["ent_cat"] = "diagnostic";
|
||||
|
||||
JsonObject dev3 = doc.createNestedObject("dev");
|
||||
JsonArray ids3 = dev3.createNestedArray("ids");
|
||||
dev3["name"] = "EMS-ESP";
|
||||
JsonArray ids3 = dev3.createNestedArray("ids");
|
||||
ids3.add(Mqtt::basename());
|
||||
|
||||
Mqtt::add_avty_to_doc(stat_t, doc.as<JsonObject>(), "value_json.timestamp is defined"); // add "availability" section
|
||||
|
||||
@@ -542,7 +542,8 @@ void TemperatureSensor::publish_values(const bool force) {
|
||||
config["name"] = name;
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
// add "availability" section
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.6.3-dev.6"
|
||||
#define EMSESP_APP_VERSION "3.6.3-dev.7"
|
||||
|
||||
@@ -410,7 +410,8 @@ void WebCustomEntityService::publish(const bool force) {
|
||||
}
|
||||
}
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
// add "availability" section
|
||||
|
||||
@@ -288,7 +288,8 @@ void WebSchedulerService::publish(const bool force) {
|
||||
}
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
// add "availability" section
|
||||
|
||||
Reference in New Issue
Block a user