Skip to content

Commit 7ec77ea

Browse files
committed
Cloud/wizard fixes
1 parent 74c0b19 commit 7ec77ea

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

tinytuya/Cloud.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
getfunctions(deviceid)
1919
getproperties(deviceid)
2020
getdps(deviceid)
21-
sendcommand(deviceid, commands)
21+
sendcommand(deviceid, commands [, uri])
2222
getconnectstatus(deviceid)
2323
getdevicelog(deviceid, start=[now - 1 day], end=[now], evtype="1,2,3,4,5,6,7,8,9,10", size=100, params={})
2424
-> when start or end are negative, they are the number of days before "right now"
@@ -472,6 +472,10 @@ def filter_devices( self, devs, ip_list=None ):
472472
else:
473473
item[k] = i[k]
474474

475+
if 'gateway_id' in i:
476+
k = 'gateway_id'
477+
item[k] = i[k]
478+
475479
tuyadevices.append(item)
476480

477481
return tuyadevices

tinytuya/wizard.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
TCPTIMEOUT = tinytuya.TCPTIMEOUT # Seconds to wait for socket open for scanning
4949
TCPPORT = tinytuya.TCPPORT # Tuya TCP Local Port
5050

51-
def wizard(color=True, retries=None, forcescan=False, nocloud=False):
51+
def wizard(color=True, retries=None, forcescan=False, nocloud=False, quicklist=False):
5252
"""
5353
TinyTuya Setup Wizard Tuya based WiFi smart devices
5454
@@ -94,16 +94,18 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False):
9494
if (config['apiKey'] != '' and config['apiSecret'] != '' and
9595
config['apiRegion'] != ''):
9696
needconfigs = False
97-
apiDeviceID = '<None>' if not config['apiDeviceID'] else config['apiDeviceID']
97+
apiDeviceID = '<None>' if ('apiDeviceID' not in config or not config['apiDeviceID']) else config['apiDeviceID']
9898
print(" " + subbold + "Existing settings:" + dim +
9999
"\n API Key=%s \n Secret=%s\n DeviceID=%s\n Region=%s" %
100100
(config['apiKey'], config['apiSecret'], apiDeviceID,
101101
config['apiRegion']))
102102
print('')
103-
answer = input(subbold + ' Use existing credentials ' +
104-
normal + '(Y/n): ')
105-
if answer[0:1].lower() == 'n':
103+
if quicklist:
106104
needconfigs = True
105+
else:
106+
answer = input(subbold + ' Use existing credentials ' + normal + '(Y/n): ')
107+
if answer[0:1].lower() == 'n':
108+
needconfigs = True
107109

108110
if needconfigs:
109111
# Ask user for config settings
@@ -166,14 +168,19 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False):
166168
# if device['parent'] == '': device is a sub-device with an unknown parent
167169
# else: device['parent'] == device_id of parent
168170
for dev in tuyadevices:
169-
if 'gateway_id' in dev and dev['gateway_id']:
171+
if 'gateway_id' in dev:
170172
# if the Cloud gave us the parent then just use that
171-
dev['parent'] = dev['gateway_id']
172-
elif 'sub' in dev and dev['sub']:
173+
if dev['gateway_id']:
174+
dev['parent'] = dev['gateway_id']
175+
del dev['gateway_id']
176+
177+
if 'sub' in dev and dev['sub']:
173178
# no parent from cloud, try to find it via the local key
174-
if 'parent' not in dev:
175-
# Set 'parent' to an empty string in case we can't find it
176-
dev['parent'] = ''
179+
if 'parent' in dev and dev['parent']:
180+
continue
181+
182+
# Set 'parent' to an empty string in case we can't find it
183+
dev['parent'] = ''
177184

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

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

0 commit comments

Comments
 (0)