2 Commits

Author SHA1 Message Date
Proddy
b4036bf8cd Merge pull request #2888 from MichaelDvP/dev
don't add HA uom/classes for bool values, fix #2885
2026-01-03 18:59:44 +01:00
MichaelDvP
4b457d6cdb don't add HA uom/classes for bool values, fix #2885 2026-01-03 18:24:54 +01:00

View File

@@ -1132,6 +1132,9 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8
if (device_type == EMSdevice::DeviceType::SYSTEM) {
doc["ent_cat"] = "diagnostic"; // instead of 'config'
}
if (type == DeviceValueType::BOOL) {
return;
}
// For display_only, we don't use the aliases, also we don't display the icon
const char * dc_ha = display_only ? "device_class" : "dev_cla"; // device class, dev_cla
@@ -1146,7 +1149,6 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8
// set uom, unless boolean - as HA is fussy with the naming and is case sensitive
// map too HA uom specific codes from https://github.com/home-assistant/core/blob/dev/homeassistant/const.py
if (type != DeviceValueType::BOOL) {
if (uom == DeviceValueUOM::HOURS) {
doc[uom_ha] = "h";
} else if (uom == DeviceValueUOM::MINUTES) {
@@ -1164,7 +1166,6 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8
} else if (discovery_type() != discoveryType::HOMEASSISTANT) {
doc[uom_ha] = " "; // Domoticz uses " " for a no-uom
}
}
// set state and device class - always
// see https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes
@@ -1280,9 +1281,8 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8
// DeviceValueUOM::NONE:
// DeviceValueUOM::KMIN:
// for device entities which have numerical values, with no UOM
if ((type != DeviceValueType::STRING)
&& (type == DeviceValueType::INT8 || type == DeviceValueType::UINT8 || type == DeviceValueType::INT16 || type == DeviceValueType::UINT16
|| type == DeviceValueType::UINT24 || type == DeviceValueType::UINT32)) {
if (type == DeviceValueType::INT8 || type == DeviceValueType::UINT8 || type == DeviceValueType::INT16 || type == DeviceValueType::UINT16
|| type == DeviceValueType::UINT24 || type == DeviceValueType::UINT32) {
if (display_only) {
doc[ic_ha] = F_(iconnum); // set icon
}