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) { if (device_type == EMSdevice::DeviceType::SYSTEM) {
doc["ent_cat"] = "diagnostic"; // instead of 'config' 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 // 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 const char * dc_ha = display_only ? "device_class" : "dev_cla"; // device class, dev_cla
@@ -1146,24 +1149,22 @@ 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 // 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 // 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) {
if (uom == DeviceValueUOM::HOURS) { doc[uom_ha] = "h";
doc[uom_ha] = "h"; } else if (uom == DeviceValueUOM::MINUTES) {
} else if (uom == DeviceValueUOM::MINUTES) { doc[uom_ha] = "min";
doc[uom_ha] = "min"; } else if (uom == DeviceValueUOM::SECONDS) {
} else if (uom == DeviceValueUOM::SECONDS) { doc[uom_ha] = "s";
doc[uom_ha] = "s"; } else if (uom == DeviceValueUOM::KB) {
} else if (uom == DeviceValueUOM::KB) { doc[uom_ha] = "kB";
doc[uom_ha] = "kB"; } else if (uom == DeviceValueUOM::LMIN) {
} else if (uom == DeviceValueUOM::LMIN) { doc[uom_ha] = "L/min";
doc[uom_ha] = "L/min"; } else if (uom == DeviceValueUOM::LH) {
} else if (uom == DeviceValueUOM::LH) { doc[uom_ha] = "L/h";
doc[uom_ha] = "L/h"; } else if (uom != DeviceValueUOM::NONE) {
} else if (uom != DeviceValueUOM::NONE) { doc[uom_ha] = EMSdevice::uom_to_string(uom); // use default
doc[uom_ha] = EMSdevice::uom_to_string(uom); // use default } else if (discovery_type() != discoveryType::HOMEASSISTANT) {
} else if (discovery_type() != discoveryType::HOMEASSISTANT) { doc[uom_ha] = " "; // Domoticz uses " " for a no-uom
doc[uom_ha] = " "; // Domoticz uses " " for a no-uom
}
} }
// set state and device class - always // set state and device class - always
@@ -1280,9 +1281,8 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8
// DeviceValueUOM::NONE: // DeviceValueUOM::NONE:
// DeviceValueUOM::KMIN: // DeviceValueUOM::KMIN:
// for device entities which have numerical values, with no UOM // for device entities which have numerical values, with no UOM
if ((type != DeviceValueType::STRING) if (type == DeviceValueType::INT8 || type == DeviceValueType::UINT8 || type == DeviceValueType::INT16 || type == DeviceValueType::UINT16
&& (type == DeviceValueType::INT8 || type == DeviceValueType::UINT8 || type == DeviceValueType::INT16 || type == DeviceValueType::UINT16 || type == DeviceValueType::UINT24 || type == DeviceValueType::UINT32) {
|| type == DeviceValueType::UINT24 || type == DeviceValueType::UINT32)) {
if (display_only) { if (display_only) {
doc[ic_ha] = F_(iconnum); // set icon doc[ic_ha] = F_(iconnum); // set icon
} }