Skip to content

Commit

Permalink
Cloud/wizard fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
uzlonewolf committed Mar 20, 2023
1 parent 74c0b19 commit 7ec77ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
6 changes: 5 additions & 1 deletion tinytuya/Cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
getfunctions(deviceid)
getproperties(deviceid)
getdps(deviceid)
sendcommand(deviceid, commands)
sendcommand(deviceid, commands [, uri])
getconnectstatus(deviceid)
getdevicelog(deviceid, start=[now - 1 day], end=[now], evtype="1,2,3,4,5,6,7,8,9,10", size=100, params={})
-> when start or end are negative, they are the number of days before "right now"
Expand Down Expand Up @@ -472,6 +472,10 @@ def filter_devices( self, devs, ip_list=None ):
else:
item[k] = i[k]

if 'gateway_id' in i:
k = 'gateway_id'
item[k] = i[k]

tuyadevices.append(item)

return tuyadevices
Expand Down
34 changes: 22 additions & 12 deletions tinytuya/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
TCPTIMEOUT = tinytuya.TCPTIMEOUT # Seconds to wait for socket open for scanning
TCPPORT = tinytuya.TCPPORT # Tuya TCP Local Port

def wizard(color=True, retries=None, forcescan=False, nocloud=False):
def wizard(color=True, retries=None, forcescan=False, nocloud=False, quicklist=False):
"""
TinyTuya Setup Wizard Tuya based WiFi smart devices
Expand Down Expand Up @@ -94,16 +94,18 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False):
if (config['apiKey'] != '' and config['apiSecret'] != '' and
config['apiRegion'] != ''):
needconfigs = False
apiDeviceID = '<None>' if not config['apiDeviceID'] else config['apiDeviceID']
apiDeviceID = '<None>' if ('apiDeviceID' not in config or not config['apiDeviceID']) else config['apiDeviceID']
print(" " + subbold + "Existing settings:" + dim +
"\n API Key=%s \n Secret=%s\n DeviceID=%s\n Region=%s" %
(config['apiKey'], config['apiSecret'], apiDeviceID,
config['apiRegion']))
print('')
answer = input(subbold + ' Use existing credentials ' +
normal + '(Y/n): ')
if answer[0:1].lower() == 'n':
if quicklist:
needconfigs = True
else:
answer = input(subbold + ' Use existing credentials ' + normal + '(Y/n): ')
if answer[0:1].lower() == 'n':
needconfigs = True

if needconfigs:
# Ask user for config settings
Expand Down Expand Up @@ -166,14 +168,19 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False):
# if device['parent'] == '': device is a sub-device with an unknown parent
# else: device['parent'] == device_id of parent
for dev in tuyadevices:
if 'gateway_id' in dev and dev['gateway_id']:
if 'gateway_id' in dev:
# if the Cloud gave us the parent then just use that
dev['parent'] = dev['gateway_id']
elif 'sub' in dev and dev['sub']:
if dev['gateway_id']:
dev['parent'] = dev['gateway_id']
del dev['gateway_id']

if 'sub' in dev and dev['sub']:
# no parent from cloud, try to find it via the local key
if 'parent' not in dev:
# Set 'parent' to an empty string in case we can't find it
dev['parent'] = ''
if 'parent' in dev and dev['parent']:
continue

# Set 'parent' to an empty string in case we can't find it
dev['parent'] = ''

# Only try to find the parent if the device has a local key
if 'key' in dev and dev['key']:
Expand Down Expand Up @@ -219,7 +226,10 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False):
print('\n\n' + bold + 'Unable to save raw file' + dim )

# Find out if we should poll all devices
answer = input(subbold + '\nPoll local devices? ' + normal + '(Y/n): ')
if quicklist:
answer = 'n'
else:
answer = input(subbold + '\nPoll local devices? ' + normal + '(Y/n): ')
if answer.lower().find('n') < 0:
result = tinytuya.scanner.poll_and_display( tuyadevices, color=color, scantime=retries, snapshot=True, forcescan=forcescan )
iplist = {}
Expand Down

0 comments on commit 7ec77ea

Please sign in to comment.