Restore states for RFLink devices (#18816)
* Merge branch 'master' of https://github.com/home-assistant/home-assistant into dev # Conflicts: # homeassistant/components/binary_sensor/point.py # homeassistant/components/cloud/__init__.py # homeassistant/components/cloud/prefs.py # homeassistant/components/frontend/__init__.py # homeassistant/components/light/fibaro.py # homeassistant/components/logbook.py # homeassistant/components/point/__init__.py # homeassistant/config_entries.py # homeassistant/const.py # homeassistant/helpers/service.py # requirements_all.txt # requirements_test_all.txt * one 'async_get_last_state' refactor left behind * Remove RestoreEntity inheritance (already in parent class) * # pylint: disable=too-many-ancestors * code predictor can be a bitch * lint corrections * # pylint: disable=too-many-ancestors * recover from dict[key] * Remove all 'coroutine' decorator, replace for 'async def' Replace all 'yield from' for 'await' Replace 'hass.async_add_job' for 'hass.async_create_task'
This commit is contained in:
parent
3e7b908a61
commit
61ca9bb8e4
7 changed files with 649 additions and 16 deletions
|
@ -148,17 +148,29 @@ async def async_setup_platform(hass, config, async_add_entities,
|
|||
hass.data[DATA_DEVICE_REGISTER][EVENT_KEY_COMMAND] = add_new_device
|
||||
|
||||
|
||||
# pylint: disable=too-many-ancestors
|
||||
class RflinkLight(SwitchableRflinkDevice, Light):
|
||||
"""Representation of a Rflink light."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# pylint: disable=too-many-ancestors
|
||||
class DimmableRflinkLight(SwitchableRflinkDevice, Light):
|
||||
"""Rflink light device that support dimming."""
|
||||
|
||||
_brightness = 255
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Restore RFLink light brightness attribute."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None and \
|
||||
old_state.attributes.get(ATTR_BRIGHTNESS) is not None:
|
||||
# restore also brightness in dimmables devices
|
||||
self._brightness = int(old_state.attributes[ATTR_BRIGHTNESS])
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
|
@ -179,6 +191,7 @@ class DimmableRflinkLight(SwitchableRflinkDevice, Light):
|
|||
return SUPPORT_BRIGHTNESS
|
||||
|
||||
|
||||
# pylint: disable=too-many-ancestors
|
||||
class HybridRflinkLight(SwitchableRflinkDevice, Light):
|
||||
"""Rflink light device that sends out both dim and on/off commands.
|
||||
|
||||
|
@ -196,6 +209,16 @@ class HybridRflinkLight(SwitchableRflinkDevice, Light):
|
|||
|
||||
_brightness = 255
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Restore RFLink light brightness attribute."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None and \
|
||||
old_state.attributes.get(ATTR_BRIGHTNESS) is not None:
|
||||
# restore also brightness in dimmables devices
|
||||
self._brightness = int(old_state.attributes[ATTR_BRIGHTNESS])
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on and set dim level."""
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
|
@ -222,6 +245,7 @@ class HybridRflinkLight(SwitchableRflinkDevice, Light):
|
|||
return SUPPORT_BRIGHTNESS
|
||||
|
||||
|
||||
# pylint: disable=too-many-ancestors
|
||||
class ToggleRflinkLight(SwitchableRflinkDevice, Light):
|
||||
"""Rflink light device which sends out only 'on' commands.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue