Skip to content

Commit

Permalink
Merge pull request #22 from xZetsubou/fix_devices_setup_connection
Browse files Browse the repository at this point in the history
Fix devices setup connect [Sub Devices takes 1mins to connect]
  • Loading branch information
xZetsubou authored Sep 1, 2023
2 parents 4c514f7 + 6557fb7 commit e8ad6d4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions custom_components/localtuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ def _device_discovered(device: TuyaDevice):
# device = hass.data[DOMAIN][TUYA_DEVICES][device_id]
# if not device.connected:
# hass.create_task(device.async_connect())
elif device_id in hass.data[DOMAIN][TUYA_DEVICES]:
device = hass.data[DOMAIN][TUYA_DEVICES][device_id]
if not device.connected:
hass.create_task(device.async_connect())
# elif device_id in hass.data[DOMAIN][TUYA_DEVICES]:
# device = hass.data[DOMAIN][TUYA_DEVICES][device_id]
# if not device.connected:
# hass.create_task(device.async_connect())

def _shutdown(event):
"""Clean up resources when shutting down."""
Expand Down Expand Up @@ -285,6 +285,8 @@ async def setup_entities(device_ids):

await async_remove_orphan_entities(hass, entry)
await hass.config_entries.async_forward_entry_setups(entry, platforms)
for dev_id in device_ids:
hass.create_task(hass.data[DOMAIN][TUYA_DEVICES][dev_id].async_connect())

await setup_entities(entry.data[CONF_DEVICES].keys())
unsub_listener = entry.add_update_listener(update_listener)
Expand Down

0 comments on commit e8ad6d4

Please sign in to comment.