Skip to content

Commit

Permalink
Subdevices: use CID rather than parent device id for device "id"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
make-all committed Sep 24, 2024
1 parent a597cca commit 3eceaa9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/tuya_local/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"]

0 comments on commit 3eceaa9

Please sign in to comment.