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
|
@ -13,7 +13,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, CONF_COMMAND, CONF_HOST, CONF_PORT,
|
||||
EVENT_HOMEASSISTANT_STOP)
|
||||
STATE_ON, EVENT_HOMEASSISTANT_STOP)
|
||||
from homeassistant.core import CoreState, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -21,7 +21,7 @@ from homeassistant.helpers.deprecation import get_deprecated
|
|||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_send, async_dispatcher_connect)
|
||||
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
REQUIREMENTS = ['rflink==0.0.37']
|
||||
|
||||
|
@ -499,9 +499,17 @@ class RflinkCommand(RflinkDevice):
|
|||
self._async_send_command(cmd, repetitions - 1))
|
||||
|
||||
|
||||
class SwitchableRflinkDevice(RflinkCommand):
|
||||
class SwitchableRflinkDevice(RflinkCommand, RestoreEntity):
|
||||
"""Rflink entity which can switch on/off (eg: light, switch)."""
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Restore RFLink device state (ON/OFF)."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None:
|
||||
self._state = old_state.state == STATE_ON
|
||||
|
||||
def _handle_event(self, event):
|
||||
"""Adjust state if Rflink picks up a remote command for this device."""
|
||||
self.cancel_queued_send_commands()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue