From af0346552fd9e530953a85804ef185f49f4bf68e Mon Sep 17 00:00:00 2001 From: James Connor Date: Wed, 19 Apr 2023 21:34:27 +0100 Subject: [PATCH] Fix sensor warnings --- .../hildebrand_glow_ihd_mqtt/sensor.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/custom_components/hildebrand_glow_ihd_mqtt/sensor.py b/custom_components/hildebrand_glow_ihd_mqtt/sensor.py index df49fef..f60283a 100755 --- a/custom_components/hildebrand_glow_ihd_mqtt/sensor.py +++ b/custom_components/hildebrand_glow_ihd_mqtt/sensor.py @@ -120,7 +120,7 @@ "name": "Smart Meter Electricity: Import Unit Rate", "device_class": SensorDeviceClass.MONETARY, "unit_of_measurement": "GBP/kWh", - "state_class": SensorStateClass.MEASUREMENT, + "state_class": None, "icon": "mdi:cash", "func": lambda js : js['electricitymeter']['energy']['import']['price']['unitrate'], "ignore_zero_values": True, @@ -129,7 +129,7 @@ "name": "Smart Meter Electricity: Import Standing Charge", "device_class": SensorDeviceClass.MONETARY, "unit_of_measurement": "GBP", - "state_class": SensorStateClass.MEASUREMENT, + "state_class": None, "icon": "mdi:cash", "func": lambda js : js['electricitymeter']['energy']['import']['price']['standingcharge'], "ignore_zero_values": True, @@ -146,7 +146,7 @@ "name": "Smart Meter Electricity: Cost (Today)", "device_class": SensorDeviceClass.MONETARY, "unit_of_measurement": "GBP", - "state_class": SensorStateClass.TOTAL_INCREASING, + "state_class": None, "icon": "mdi:cash", "func": lambda js : round(js['electricitymeter']['energy']['import']['price']['standingcharge'] + \ (js['electricitymeter']['energy']['import']['day'] * js['electricitymeter']['energy']['import']['price']['unitrate']), 2), @@ -224,7 +224,7 @@ "name": "Smart Meter Gas: Import Unit Rate", "device_class": SensorDeviceClass.MONETARY, "unit_of_measurement": "GBP/kWh", - "state_class": SensorStateClass.MEASUREMENT, + "state_class": None, "icon": "mdi:cash", "func": lambda js : js['gasmeter']['energy']['import']['price']['unitrate'], "ignore_zero_values": True, @@ -233,7 +233,7 @@ "name": "Smart Meter Gas: Import Standing Charge", "device_class": SensorDeviceClass.MONETARY, "unit_of_measurement": "GBP", - "state_class": SensorStateClass.MEASUREMENT, + "state_class": None, "icon": "mdi:cash", "func": lambda js : js['gasmeter']['energy']['import']['price']['standingcharge'], "ignore_zero_values": True, @@ -251,7 +251,7 @@ "name": "Smart Meter Gas: Cost (Today)", "device_class": SensorDeviceClass.MONETARY, "unit_of_measurement": "GBP", - "state_class": SensorStateClass.TOTAL_INCREASING, + "state_class": None, "icon": "mdi:cash", "func": lambda js : round((js['gasmeter']['energy']['import']['price']['standingcharge'] or 0)+ \ ((js['gasmeter']['energy']['import']['day'] or 0) * (js['gasmeter']['energy']['import']['price']['unitrate'] or 0)), 2), @@ -339,9 +339,12 @@ def __init__(self, device_id, name, icon, device_class, unit_of_measurement, sta self._attr_name = name self._attr_unique_id = slugify(device_id + "_" + name) self._attr_icon = icon - self._attr_device_class = device_class - self._attr_native_unit_of_measurement = unit_of_measurement - self._attr_state_class = state_class + if (device_class): + self._attr_device_class = device_class + if (unit_of_measurement): + self._attr_native_unit_of_measurement = unit_of_measurement + if (state_class): + self._attr_state_class = state_class self._attr_entity_category = entity_category self._attr_should_poll = False