Skip to content

Commit

Permalink
def state -> def native_value
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Sep 3, 2024
1 parent f73018e commit 0b5491b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion custom_components/tibber_local/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-tibber-pulse-local/issues",
"requirements": ["smllib==1.4"],
"version": "2024.8.0"
"version": "2024.9.0"
}
28 changes: 16 additions & 12 deletions custom_components/tibber_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import StateType
from homeassistant.util import slugify

from . import TibberLocalDataUpdateCoordinator, TibberLocalEntity
from .const import (
DOMAIN,
Expand Down Expand Up @@ -77,14 +77,18 @@ def __init__(
self._attr_suggested_display_precision = 2

@property
def state(self):
"""Return the current state."""
value = getattr(self.coordinator.bridge, 'attr' + self.entity_description.key)
if type(value) != type(False):
try:
rounded_value = round(float(value), self._attr_suggested_display_precision)
return rounded_value
except (ValueError, TypeError):
return value
else:
return value
def native_value(self) -> StateType:
return getattr(self.coordinator.bridge, 'attr' + self.entity_description.key)

# @property
# def state(self):
# """Return the current state."""
# value = getattr(self.coordinator.bridge, 'attr' + self.entity_description.key)
# if type(value) != type(False):
# try:
# rounded_value = round(float(value), self._attr_suggested_display_precision)
# return rounded_value
# except (ValueError, TypeError):
# return value
# else:
# return value
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
homeassistant>=2024.8.2
smllib>=1.4
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest-homeassistant-custom-component>=0.13.154

0 comments on commit 0b5491b

Please sign in to comment.