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

Fix Cloud getdevices() bug for devices.json #382

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 an older devices.json not having the model key for some devices. Updated to check for missing DEVICEFILE_SAVE_VALUES keys and update the device record.

Closes #381