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:
parent
0c9a30ab69
commit
114bf0da34
6 changed files with 50 additions and 64 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue