Skip to content

Commit

Permalink
Disconnect the sub devices if gateway dc'd
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Oct 19, 2023
1 parent 80c5458 commit 6243fa9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion custom_components/localtuya/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def __init__(
self._node_id: str = not gateway and self._dev_config_entry.get(CONF_NODE_ID)
self._gwateway: TuyaDevice = None
self._sub_devices = {}

self._status = {}
self.dps_to_request = {}
self._is_closing = False
Expand Down Expand Up @@ -466,14 +467,20 @@ def disconnected(self):
self._unsub_interval()
self._unsub_interval = None
self._interface = None

if self._sub_devices:
for sub_dev in self._sub_devices.values():
sub_dev._interface = None

if self._connect_task is not None:
# self._connect_task.cancel()
self._connect_task = None

# If it's disconnect by unexpected error.
if self._is_closing is not True:
self.warning("Disconnected - waiting for discovery broadcast")
self._is_closing = True
self._hass.create_task(self.async_connect())
self._hass.async_create_task(self.async_connect())


class LocalTuyaEntity(RestoreEntity, pytuya.ContextualLogger):
Expand Down

0 comments on commit 6243fa9

Please sign in to comment.