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