Skip to content

Commit

Permalink
Improve sensor handling
Browse files Browse the repository at this point in the history
  • Loading branch information
drc38 committed Feb 9, 2023
1 parent 0b75370 commit 9e09c35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/solarweb/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"precision": 2,
"icon": "mdi:cash-multiple",
},
"Percent": {
"Percentage": {
"device": SensorDeviceClass.BATTERY,
"state": SensorStateClass.MEASUREMENT,
"precision": 1,
Expand Down
8 changes: 4 additions & 4 deletions custom_components/solarweb/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9e09c35

Please sign in to comment.