From b615f7fc1fb1376361e5f895867498975cc5335d Mon Sep 17 00:00:00 2001 From: AmSe2000 Date: Mon, 21 Oct 2024 22:29:02 +0200 Subject: [PATCH] Some more Device_Classes and two digit CPU_Temp (#140) * Added data["device_class"] = "temperature" to align with other temperature values. * Device_Class = temperature also for device + "_temp" * Added some more device_classes: voltage, frequency, duration, signal_strength Changed 'check_cpu_temp' to work with locale "DE" and showing 2 digits (maybe this needs to be double checked on different systems/hardware) * Bugfix: changed unit_of_measurement from days to d to suppress warning: ... using native unit of measurement 'days' which is not a valid unit for the device class ('duration') it is using; expected one of ['h', 'ms', 'd', 's', 'min']; in homeassistant log --- src/rpi-cpu2mqtt.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpi-cpu2mqtt.py b/src/rpi-cpu2mqtt.py index a03d3ad..e348910 100644 --- a/src/rpi-cpu2mqtt.py +++ b/src/rpi-cpu2mqtt.py @@ -360,6 +360,7 @@ def config_json(what_config, device=0): data["icon"] = "mdi:flash" data["name"] = "CPU Voltage" data["unit_of_measurement"] = "V" + data["device_class"] = "voltage" data["state_class"] = "measurement" elif what_config == "swap": data["icon"] = "mdi:harddisk" @@ -375,11 +376,13 @@ def config_json(what_config, device=0): data["icon"] = "mdi:speedometer" data["name"] = "CPU Clock Speed" data["unit_of_measurement"] = "MHz" + data["device_class"] = "frequency" data["state_class"] = "measurement" elif what_config == "uptime_days": data["icon"] = "mdi:calendar" data["name"] = "Uptime" - data["unit_of_measurement"] = "days" + data["unit_of_measurement"] = "d" + data["device_class"] = "duration" data["state_class"] = "total_increasing" elif what_config == "uptime_seconds": data["icon"] = "mdi:timer-outline" @@ -396,6 +399,7 @@ def config_json(what_config, device=0): data["icon"] = "mdi:wifi" data["name"] = "Wifi Signal" data["unit_of_measurement"] = "dBm" + data["device_class"] = "signal_strength" data["state_class"] = "measurement" elif what_config == "rpi5_fan_speed": data["icon"] = "mdi:fan"