|
|
@@ -225,8 +225,11 @@ class TuyaLocalDevice(object):
|
|
|
self._children.clear()
|
|
|
self._force_dps.clear()
|
|
|
if self._refresh_task:
|
|
|
+ # Prevent any internal tinytuya retries
|
|
|
+ self._api.set_socketRetryLimit(0)
|
|
|
self._api.set_socketPersistent(False)
|
|
|
if self._api.parent:
|
|
|
+ self._api.parent.set_socketRetryLimit(0)
|
|
|
self._api.parent.set_socketPersistent(False)
|
|
|
await self._refresh_task
|
|
|
_LOGGER.debug("Monitor loop for %s stopped", self.name)
|
|
|
@@ -406,7 +409,8 @@ class TuyaLocalDevice(object):
|
|
|
force_backoff = True
|
|
|
poll = None
|
|
|
|
|
|
- if poll:
|
|
|
+ # Skip processing any response if the device has been stopped while waiting for the response.
|
|
|
+ if poll and self._running:
|
|
|
if "Err" in poll:
|
|
|
# Limit disconnects to the errors that are caused low level
|
|
|
# communication problems
|
|
|
@@ -464,7 +468,8 @@ class TuyaLocalDevice(object):
|
|
|
|
|
|
if not self.has_returned_state or wifi_api.socket is None:
|
|
|
force_backoff = True
|
|
|
- await asyncio.sleep(5 if force_backoff else 0.1)
|
|
|
+ if self.running:
|
|
|
+ await asyncio.sleep(5 if force_backoff else 0.1)
|
|
|
|
|
|
# Close the persistent connection when exiting the loop
|
|
|
self._api.set_socketPersistent(False)
|