Centralize bond update state logic (#38093)

* Refactor bond integration to centralize update state logic in single superclass

* Refactor bond integration to centralize update state logic in single superclass
This commit is contained in:
Eugene Prystupa authored and GitHub committed 2020-07-23 04:15:27 +02:00
1 parent 3480fb6996
commit a756d1e637
5 files changed
+31 -30

No files matched your search

+7 -11
View File
@@ -50,16 +50,14 @@ class BondLight(BondEntity, LightEntity):
self._light: Optional[int] = None
def _apply_state(self, state: dict):
self._light = state.get("light")
@property
def is_on(self) -> bool:
"""Return if light is currently on."""
return self._light == 1
async def async_update(self):
"""Fetch assumed state of the light from the hub using API."""
state: dict = await self._hub.bond.device_state(self._device.device_id)
self._light = state.get("light")
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
await self._hub.bond.action(self._device.device_id, Action.turn_light_on())
@@ -80,6 +78,10 @@ class BondFireplace(BondEntity, LightEntity):
# Bond flame level, 0-100
self._flame: Optional[int] = None
def _apply_state(self, state: dict):
self._power = state.get("power")
self._flame = state.get("flame")
@property
def supported_features(self) -> Optional[int]:
"""Flag brightness as supported feature to represent flame level."""
@@ -112,9 +114,3 @@ class BondFireplace(BondEntity, LightEntity):
def icon(self) -> Optional[str]:
"""Show fireplace icon for the entity."""
return "mdi:fireplace" if self._power == 1 else "mdi:fireplace-off"
async def async_update(self):
"""Fetch assumed state of the device from the hub using API."""
state: dict = await self._hub.bond.device_state(self._device.device_id)
self._power = state.get("power")
self._flame = state.get("flame")