Fixed and improved logging
This commit is contained in:
@@ -80,6 +80,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)
|
||||
|
||||
@@ -95,24 +96,31 @@ class TuyaCoverCache:
|
||||
self._lock = Lock()
|
||||
|
||||
def __get_status(self):
|
||||
for i in range(20):
|
||||
for i in range(5):
|
||||
try:
|
||||
status = self._device.status()
|
||||
return status
|
||||
except ConnectionError:
|
||||
except Exception:
|
||||
print('Failed to update status of device [{}]'.format(self._device.address))
|
||||
sleep(1.0)
|
||||
if i+1 == 3:
|
||||
raise ConnectionError("Failed to update status.")
|
||||
_LOGGER.error("Failed to update status of device %s", self._device.address )
|
||||
# return None
|
||||
raise ConnectionError("Failed to update status .")
|
||||
|
||||
def set_status(self, state, switchid):
|
||||
"""Change the Tuya switch status and clear the cache."""
|
||||
self._cached_status = ''
|
||||
self._cached_status_time = 0
|
||||
for i in range(20):
|
||||
for i in range(5):
|
||||
try:
|
||||
return self._device.set_status(state, switchid)
|
||||
except ConnectionError:
|
||||
if i+1 == 5:
|
||||
raise ConnectionError("Failed to set status.")
|
||||
except Exception:
|
||||
print('Failed to set status of device [{}]'.format(self._device.address))
|
||||
if i+1 == 3:
|
||||
_LOGGER.error("Failed to set status of device %s", self._device.address )
|
||||
return
|
||||
# raise ConnectionError("Failed to set status.")
|
||||
|
||||
def status(self):
|
||||
"""Get state of Tuya switch and cache the results."""
|
||||
|
Reference in New Issue
Block a user