From 9e09c35641ea9cf37b1b656e34e3bdcb22c3501e Mon Sep 17 00:00:00 2001 From: drc38 Date: Thu, 9 Feb 2023 20:28:13 +1300 Subject: [PATCH] Improve sensor handling --- custom_components/solarweb/const.py | 2 +- custom_components/solarweb/sensor.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/custom_components/solarweb/const.py b/custom_components/solarweb/const.py index b373a6b..e9ee22f 100644 --- a/custom_components/solarweb/const.py +++ b/custom_components/solarweb/const.py @@ -64,7 +64,7 @@ "precision": 2, "icon": "mdi:cash-multiple", }, - "Percent": { + "Percentage": { "device": SensorDeviceClass.BATTERY, "state": SensorStateClass.MEASUREMENT, "precision": 1, diff --git a/custom_components/solarweb/sensor.py b/custom_components/solarweb/sensor.py index 0383df3..2789bf4 100644 --- a/custom_components/solarweb/sensor.py +++ b/custom_components/solarweb/sensor.py @@ -65,7 +65,7 @@ def native_value(self): def native_precision(self): """Return the native measurement precision.""" value = self.coordinator.data["data"]["sensors"][self._attr_name]["channelType"] - if value: + if value and value in CHANNEL_HA_MAP: return CHANNEL_HA_MAP.get(value).get("precision") else: return None @@ -74,7 +74,7 @@ def native_precision(self): def state_class(self): """Return the state class.""" value = self.coordinator.data["data"]["sensors"][self._attr_name]["channelType"] - if value: + if value and value in CHANNEL_HA_MAP: return CHANNEL_HA_MAP.get(value).get("state") else: return None @@ -83,7 +83,7 @@ def state_class(self): def device_class(self): """Return the device class.""" value = self.coordinator.data["data"]["sensors"][self._attr_name]["channelType"] - if value: + if value and value in CHANNEL_HA_MAP: return CHANNEL_HA_MAP.get(value).get("device") else: return None @@ -92,7 +92,7 @@ def device_class(self): def icon(self): """Return the state class.""" value = self.coordinator.data["data"]["sensors"][self._attr_name]["channelType"] - if value: + if value and value in CHANNEL_HA_MAP: return CHANNEL_HA_MAP.get(value).get("icon") else: return None