jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
879 stars 159 forks source link

Cloud getdevices() bug #381

Closed jasonacox closed 1 year ago

jasonacox commented 1 year ago

Running wizard with an older devices.json that is missing some of the newer keys (e.g. model) causes an error:

Traceback (most recent call last):
  File "/Users/jason/miniconda3/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/jason/miniconda3/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/jason/Code/tinytuya/tinytuya/__main__.py", line 76, in <module>
    wizard.wizard(color=color, retries=retries, forcescan=force, quicklist=assume_yes)
  File "/Users/jason/Code/tinytuya/tinytuya/wizard.py", line 174, in wizard
    tuyadevices = cloud.getdevices( False, oldlist=old_devices, include_map=include_map )
  File "/Users/jason/Code/tinytuya/tinytuya/Cloud.py", line 490, in getdevices
    if k in dev and k != 'icon' and k != 'last_ip' and old[k] != dev[k]:
KeyError: 'model'

This is due to the older devices.json not having the model key for some devices. Easy fix for line 490 -

            for k in DEVICEFILE_SAVE_VALUES:
                if k in dev and k != 'icon' and k != 'last_ip' and (k not in old or old[k] != dev[k]):
                    is_same = False
                    break