From 3eceaa9ebb6017d3c8c73450a61ab50d31771110 Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Tue, 24 Sep 2024 19:08:50 +0900 Subject: [PATCH] Subdevices: use CID rather than parent device id for device "id" tinytuya requires this to be unique, but it does not appear to matter what it is. This should help with streaming updates from multiple devices, though probably there is more work required for this. Issue #1054, #2289 --- custom_components/tuya_local/device.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/tuya_local/device.py b/custom_components/tuya_local/device.py index b83acef544..2da67441dc 100644 --- a/custom_components/tuya_local/device.py +++ b/custom_components/tuya_local/device.py @@ -76,7 +76,7 @@ def __init__( parent = tinytuya.Device(dev_id, address, local_key) hass.data[DOMAIN][dev_id] = {"tuyadevice": parent} self._api = tinytuya.Device( - dev_id, + dev_cid, cid=dev_cid, parent=parent, ) @@ -99,7 +99,6 @@ def __init__( self._api.set_socketRetryLimit(1) if self._api.parent: # Retries cause problems for other children of the parent device - # Currently, we only support polling for child devices self._api.parent.set_socketRetryLimit(1) self._refresh_task = None @@ -157,7 +156,8 @@ def actually_start(self, event=None): self._shutdown_listener = self._hass.bus.async_listen_once( EVENT_HOMEASSISTANT_STOP, self.async_stop ) - self._refresh_task = self._hass.async_create_task(self.receive_loop()) + if not self._refresh_task: + self._refresh_task = self._hass.async_create_task(self.receive_loop()) def start(self): if self._hass.is_stopping: @@ -675,3 +675,4 @@ async def async_delete_device(hass: HomeAssistant, config: dict): _LOGGER.info("Deleting device: %s", device_id) await hass.data[DOMAIN][device_id]["device"].async_stop() del hass.data[DOMAIN][device_id]["device"] + del hass.data[DOMAIN][device_id]["tuyadevice"]