Add support for unique_id and available
This commit is contained in:
@@ -29,7 +29,7 @@ from homeassistant.components.cover import (
|
||||
)
|
||||
|
||||
"""from . import DATA_TUYA, TuyaDevice"""
|
||||
from homeassistant.components.cover import ENTITY_ID_FORMAT, CoverEntity, PLATFORM_SCHEMA
|
||||
from homeassistant.components.cover import CoverEntity, PLATFORM_SCHEMA
|
||||
from homeassistant.const import (CONF_HOST, CONF_ID, CONF_FRIENDLY_NAME, CONF_ICON, CONF_NAME)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from time import time, sleep
|
||||
@@ -88,7 +88,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
print('Setup localtuya cover [{}] with device ID [{}] '.format(config.get(CONF_FRIENDLY_NAME), config.get(CONF_ID)))
|
||||
_LOGGER.info("Setup localtuya cover %s with device ID %s ", config.get(CONF_FRIENDLY_NAME), config.get(CONF_ID) )
|
||||
|
||||
add_entities(covers)
|
||||
add_entities(covers, True)
|
||||
|
||||
|
||||
class TuyaCoverCache:
|
||||
@@ -101,6 +101,11 @@ class TuyaCoverCache:
|
||||
self._device = device
|
||||
self._lock = Lock()
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return unique device identifier."""
|
||||
return self._device.id
|
||||
|
||||
def __get_status(self):
|
||||
for i in range(5):
|
||||
try:
|
||||
@@ -146,7 +151,7 @@ class TuyaDevice(CoverEntity):
|
||||
|
||||
def __init__(self, device, name, friendly_name, icon, switchid):
|
||||
self._device = device
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(name)
|
||||
self._available = False
|
||||
self._name = friendly_name
|
||||
self._friendly_name = friendly_name
|
||||
self._icon = icon
|
||||
@@ -161,6 +166,16 @@ class TuyaDevice(CoverEntity):
|
||||
"""Get name of Tuya switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return unique device identifier."""
|
||||
return self._device.unique_id
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return if device is available or not."""
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
@@ -252,6 +267,11 @@ class TuyaDevice(CoverEntity):
|
||||
|
||||
def update(self):
|
||||
"""Get state of Tuya switch."""
|
||||
self._status = self._device.status()
|
||||
self._state = self._status['dps'][self._switch_id]
|
||||
#print('update() : state [{}]'.format(self._state))
|
||||
try:
|
||||
self._status = self._device.status()
|
||||
self._state = self._status['dps'][self._switch_id]
|
||||
#print('update() : state [{}]'.format(self._state))
|
||||
except Exception:
|
||||
self._available = False
|
||||
else:
|
||||
self._available = True
|
||||
|
Reference in New Issue
Block a user