Restore state for Rfxtrx devices (#30309)

* Restore state rfxtrx switch

* Restore state RFXtrx lights

* Restore state RFXtrx covers

* Restore comment

* Remove line

* Remove logging

* fix black

* Fix typo
This commit is contained in:
Ernst Klamer
2020-01-02 07:59:13 +01:00
committed by Daniel Høyer Iversen
parent 769cf19052
commit 77978a979b
3 changed files with 48 additions and 6 deletions

View File

@@ -3,8 +3,9 @@ import RFXtrx as rfxtrxmod
import voluptuous as vol
from homeassistant.components.cover import PLATFORM_SCHEMA, CoverDevice
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_NAME, STATE_OPEN
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
from . import (
CONF_AUTOMATIC_ADD,
@@ -62,9 +63,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
RECEIVED_EVT_SUBSCRIBERS.append(cover_update)
class RfxtrxCover(RfxtrxDevice, CoverDevice):
class RfxtrxCover(RfxtrxDevice, CoverDevice, RestoreEntity):
"""Representation of a RFXtrx cover."""
async def async_added_to_hass(self):
"""Restore RFXtrx cover device state (OPEN/CLOSE)."""
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_OPEN
@property
def should_poll(self):
"""Return the polling state. No polling available in RFXtrx cover."""