Skip to content

Commit

Permalink
use native value
Browse files Browse the repository at this point in the history
  • Loading branch information
kongo09 committed Apr 11, 2022
1 parent 688be47 commit 6a63b50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion custom_components/philips_airpurifier_coap/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"requirements": [
"aioairctrl @ git+https://github.com/kongo09/aioairctrl"
],
"version": "0.9.3"
"version": "0.9.4"
}
14 changes: 7 additions & 7 deletions custom_components/philips_airpurifier_coap/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, coordinator: Coordinator, name: str, model: str, kind: str) -
self._norm_icon = self._description.get(ATTR_ICON)
self._attr_name = f"{name} {self._description[ATTR_LABEL].replace('_', ' ').title()}"
self._attr_state_class = self._description.get(ATTR_STATE_CLASS)
self._attr_unit_of_measurement = self._description.get(ATTR_UNIT)
self._attr_native_unit_of_measurement = self._description.get(ATTR_UNIT)
self._attr_entity_category = self._description.get(CONF_ENTITY_CATEGORY)

try:
Expand All @@ -103,7 +103,7 @@ def __init__(self, coordinator: Coordinator, name: str, model: str, kind: str) -
self.kind = kind

@property
def state(self) -> StateType:
def native_value(self) -> StateType:
value = self._device_status[self.kind]
convert = self._description.get(ATTR_VALUE)
if convert:
Expand All @@ -112,7 +112,7 @@ def state(self) -> StateType:

@property
def icon(self) -> str:
if self._warn_value and self._warn_value >= int(self.state):
if self._warn_value and self._warn_value >= int(self.native_value):
return self._warn_icon
else:
return self._norm_icon
Expand Down Expand Up @@ -144,9 +144,9 @@ def __init__(self, coordinator: Coordinator, name: str, model: str, kind: str) -
self._warn_value = description[ATTR_WARN_VALUE]

if self._has_total:
self._attr_unit_of_measurement = PERCENTAGE
self._attr_native_unit_of_measurement = PERCENTAGE
else:
self._attr_unit_of_measurement = TIME_HOURS
self._attr_native_unit_of_measurement = TIME_HOURS

self._attr_name = f"{name} {kind.replace('_', ' ').title()}"
try:
Expand All @@ -158,7 +158,7 @@ def __init__(self, coordinator: Coordinator, name: str, model: str, kind: str) -
self._attrs: dict[str, Any] = {}

@property
def state(self) -> StateType:
def native_value(self) -> StateType:
if self._has_total:
return self._percentage
else:
Expand Down Expand Up @@ -196,7 +196,7 @@ def _total(self) -> int:

@property
def icon(self) -> str:
if self._warn_value and self._warn_value >= int(self.state):
if self._warn_value and self._warn_value >= int(self.native_value):
return self._warn_icon
else:
return self._norm_icon

0 comments on commit 6a63b50

Please sign in to comment.