mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
This commit is contained in:
18
src/mqtt.cpp
18
src/mqtt.cpp
@@ -624,6 +624,7 @@ void Mqtt::ha_status() {
|
|||||||
doc["pl_off"] = "offline";
|
doc["pl_off"] = "offline";
|
||||||
doc["stat_cla"] = "measurement";
|
doc["stat_cla"] = "measurement";
|
||||||
doc["dev_cla"] = "connectivity";
|
doc["dev_cla"] = "connectivity";
|
||||||
|
doc["ent_cat"] = "diagnostic";
|
||||||
|
|
||||||
// doc["avty_t"] = "~/status"; // commented out, as it causes errors in HA sometimes
|
// doc["avty_t"] = "~/status"; // commented out, as it causes errors in HA sometimes
|
||||||
// doc["json_attr_t"] = "~/heartbeat"; // store also as HA attributes
|
// doc["json_attr_t"] = "~/heartbeat"; // store also as HA attributes
|
||||||
@@ -633,7 +634,13 @@ void Mqtt::ha_status() {
|
|||||||
dev["sw"] = "v" + std::string(EMSESP_APP_VERSION);
|
dev["sw"] = "v" + std::string(EMSESP_APP_VERSION);
|
||||||
dev["mf"] = "proddy";
|
dev["mf"] = "proddy";
|
||||||
dev["mdl"] = "EMS-ESP";
|
dev["mdl"] = "EMS-ESP";
|
||||||
JsonArray ids = dev.createNestedArray("ids");
|
#ifndef EMSESP_STANDALONE
|
||||||
|
if (EMSESP::system_.ethernet_connected())
|
||||||
|
dev["cu"] = "http://" + ETH.localIP().toString();
|
||||||
|
else
|
||||||
|
dev["cu"] = "http://" + WiFi.localIP().toString();
|
||||||
|
#endif
|
||||||
|
JsonArray ids = dev.createNestedArray("ids");
|
||||||
ids.add("ems-esp");
|
ids.add("ems-esp");
|
||||||
|
|
||||||
char topic[MQTT_TOPIC_MAX_SIZE];
|
char topic[MQTT_TOPIC_MAX_SIZE];
|
||||||
@@ -1092,7 +1099,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
|
|
||||||
// for enums, add options
|
// for enums, add options
|
||||||
if (type == DeviceValueType::ENUM) {
|
if (type == DeviceValueType::ENUM) {
|
||||||
JsonArray option_list = doc.createNestedArray("options");
|
JsonArray option_list = doc.createNestedArray("ops"); // options
|
||||||
for (uint8_t i = 0; i < options_size; i++) {
|
for (uint8_t i = 0; i < options_size; i++) {
|
||||||
option_list.add(Helpers::translated_word(options[i]));
|
option_list.add(Helpers::translated_word(options[i]));
|
||||||
}
|
}
|
||||||
@@ -1194,7 +1201,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
// this next section is adding the state class, device class and sometimes the icon
|
// this next section is adding the state class, device class and sometimes the icon
|
||||||
// used for Sensor and Binary Sensor Entities in HA
|
// used for Sensor and Binary Sensor Entities in HA
|
||||||
if (set_ha_classes) {
|
if (set_ha_classes) {
|
||||||
const char * dc_ha = "device_class"; // device class
|
const char * dc_ha = "dev_cla"; // device class
|
||||||
|
|
||||||
switch (uom) {
|
switch (uom) {
|
||||||
case DeviceValueUOM::DEGREES:
|
case DeviceValueUOM::DEGREES:
|
||||||
@@ -1278,6 +1285,11 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add category "diagnostic" for system entities
|
||||||
|
if (device_type == EMSdevice::DeviceType::SYSTEM) {
|
||||||
|
doc["ent_cat"] = "diagnostic";
|
||||||
|
}
|
||||||
|
|
||||||
// add the dev json object to the end
|
// add the dev json object to the end
|
||||||
doc["dev"] = dev_json;
|
doc["dev"] = dev_json;
|
||||||
|
|
||||||
|
|||||||
@@ -601,10 +601,7 @@ bool System::heartbeat_json(JsonObject & output) {
|
|||||||
output["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
output["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
||||||
output["uptime_sec"] = uuid::get_uptime_sec();
|
output["uptime_sec"] = uuid::get_uptime_sec();
|
||||||
bool value_b = ntp_connected();
|
bool value_b = ntp_connected();
|
||||||
if (Mqtt::ha_enabled()) {
|
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
||||||
char s[12];
|
|
||||||
output["ntp_status"] = Helpers::render_boolean(s, value_b); // for HA always render as string
|
|
||||||
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
|
||||||
output["ntp_status"] = value_b;
|
output["ntp_status"] = value_b;
|
||||||
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
||||||
output["ntp_status"] = value_b ? 1 : 0;
|
output["ntp_status"] = value_b ? 1 : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user