|
48 | 48 | TCPTIMEOUT = tinytuya.TCPTIMEOUT # Seconds to wait for socket open for scanning |
49 | 49 | TCPPORT = tinytuya.TCPPORT # Tuya TCP Local Port |
50 | 50 |
|
51 | | -def wizard(color=True, retries=None, forcescan=False, nocloud=False): |
| 51 | +def wizard(color=True, retries=None, forcescan=False, nocloud=False, quicklist=False): |
52 | 52 | """ |
53 | 53 | TinyTuya Setup Wizard Tuya based WiFi smart devices |
54 | 54 |
|
@@ -94,16 +94,18 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False): |
94 | 94 | if (config['apiKey'] != '' and config['apiSecret'] != '' and |
95 | 95 | config['apiRegion'] != ''): |
96 | 96 | 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'] |
98 | 98 | print(" " + subbold + "Existing settings:" + dim + |
99 | 99 | "\n API Key=%s \n Secret=%s\n DeviceID=%s\n Region=%s" % |
100 | 100 | (config['apiKey'], config['apiSecret'], apiDeviceID, |
101 | 101 | config['apiRegion'])) |
102 | 102 | print('') |
103 | | - answer = input(subbold + ' Use existing credentials ' + |
104 | | - normal + '(Y/n): ') |
105 | | - if answer[0:1].lower() == 'n': |
| 103 | + if quicklist: |
106 | 104 | needconfigs = True |
| 105 | + else: |
| 106 | + answer = input(subbold + ' Use existing credentials ' + normal + '(Y/n): ') |
| 107 | + if answer[0:1].lower() == 'n': |
| 108 | + needconfigs = True |
107 | 109 |
|
108 | 110 | if needconfigs: |
109 | 111 | # Ask user for config settings |
@@ -166,14 +168,19 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False): |
166 | 168 | # if device['parent'] == '': device is a sub-device with an unknown parent |
167 | 169 | # else: device['parent'] == device_id of parent |
168 | 170 | for dev in tuyadevices: |
169 | | - if 'gateway_id' in dev and dev['gateway_id']: |
| 171 | + if 'gateway_id' in dev: |
170 | 172 | # 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']: |
173 | 178 | # 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'] = '' |
177 | 184 |
|
178 | 185 | # Only try to find the parent if the device has a local key |
179 | 186 | if 'key' in dev and dev['key']: |
@@ -219,7 +226,10 @@ def wizard(color=True, retries=None, forcescan=False, nocloud=False): |
219 | 226 | print('\n\n' + bold + 'Unable to save raw file' + dim ) |
220 | 227 |
|
221 | 228 | # 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): ') |
223 | 233 | if answer.lower().find('n') < 0: |
224 | 234 | result = tinytuya.scanner.poll_and_display( tuyadevices, color=color, scantime=retries, snapshot=True, forcescan=forcescan ) |
225 | 235 | iplist = {} |
|
0 commit comments