Cover fake position persistent (#213)

* Introduced read/store to JSON file of cover's last position for fake positioning
* renamed "fake" positioning to "timed"; introduced timed movement timeout equal to full opening time
* Made waiting for timeout for stopping non-blocking
* Introduced status storing using RestoreEntity
* Fixed postlund's remarks
* Updated cover samples in README and info.md
This commit is contained in:
rospogrigio
2020-12-30 22:47:45 +01:00
committed by GitHub
parent 94d1c93510
commit 9bfeb107f5
6 changed files with 65 additions and 25 deletions

View File

@@ -15,7 +15,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.restore_state import RestoreEntity
from . import pytuya
from .const import (
@@ -209,7 +209,7 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
self.debug("Disconnected - waiting for discovery broadcast")
class LocalTuyaEntity(Entity, pytuya.ContextualLogger):
class LocalTuyaEntity(RestoreEntity, pytuya.ContextualLogger):
"""Representation of a Tuya entity."""
def __init__(self, device, config_entry, dp_id, logger, **kwargs):
@@ -228,6 +228,10 @@ class LocalTuyaEntity(Entity, pytuya.ContextualLogger):
self.debug("Adding %s with configuration: %s", self.entity_id, self._config)
state = await self.async_get_last_state()
if state:
self.status_restored(state)
def _update_handler(status):
"""Update entity state when status was updated."""
if status is not None:
@@ -314,3 +318,9 @@ class LocalTuyaEntity(Entity, pytuya.ContextualLogger):
Override in subclasses and update entity specific state.
"""
def status_restored(self, stored_state):
"""Device status was restored.
Override in subclasses and update entity specific state.
"""