Update Lutron in callback (#108779)

* Update Lutron in callback

* Update Lutron in callback

* Remove abstractmethod

* Don't do IO in constructor

* Split fetching and setting
This commit is contained in:
Joost Lekkerkerker 2024-01-25 12:54:31 +01:00 committed by GitHub
parent 0c9a30ab69
commit 114bf0da34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 64 deletions

View file

@ -53,16 +53,6 @@ class LutronCover(LutronDevice, CoverEntity):
_lutron_device: Output
_attr_name = None
@property
def is_closed(self) -> bool:
"""Return if the cover is closed."""
return self._lutron_device.last_level() < 1
@property
def current_cover_position(self) -> int:
"""Return the current position of cover."""
return self._lutron_device.last_level()
def close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
self._lutron_device.level = 0
@ -77,10 +67,15 @@ class LutronCover(LutronDevice, CoverEntity):
position = kwargs[ATTR_POSITION]
self._lutron_device.level = position
def update(self) -> None:
"""Call when forcing a refresh of the device."""
# Reading the property (rather than last_level()) fetches value
level = self._lutron_device.level
def _request_state(self) -> None:
"""Request the state from the device."""
self._lutron_device.level # pylint: disable=pointless-statement
def _update_attrs(self) -> None:
"""Update the state attributes."""
level = self._lutron_device.last_level()
self._attr_is_closed = level < 1
self._attr_current_cover_position = level
_LOGGER.debug("Lutron ID: %d updated to %f", self._lutron_device.id, level)
@property