Skip to content

Commit

Permalink
Clean up new parent device detection a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
uzlonewolf committed Mar 9, 2023
1 parent 64de5b4 commit 9846a2e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tinytuya/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,22 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False):
tuyadevices = cloud.filter_devices( json_data['result'] )

for dev in tuyadevices:
if 'sub' in dev and dev['sub'] and 'id' in dev and 'key' in dev and dev['key']:
found = False
for parent in tuyadevices:
if 'id' not in parent or parent['id'] == dev['id']:
continue
# the local key seems to be the only way of identifying the parent device
if 'key' in parent and parent['key'] and dev['key'] == parent['key'] and ( 'sub' not in parent or not parent['sub']):
found = parent
break
dev['parent'] = found['id'] if found else ''
if 'sub' in dev and dev['sub']:
if 'parent' not in dev:
dev['parent'] = ''
if 'key' in dev and dev['key']:
if 'id' not in dev:
dev['id'] = ''
found = False
for parent in tuyadevices:
if 'id' not in parent or parent['id'] == dev['id']:
continue
# the local key seems to be the only way of identifying the parent device
if 'key' in parent and parent['key'] and dev['key'] == parent['key'] and ( 'sub' not in parent or not parent['sub']):
found = parent
break
if found:
dev['parent'] = found['id']

# Display device list
print("\n\n" + bold + "Device Listing\n" + dim)
Expand Down

0 comments on commit 9846a2e

Please sign in to comment.