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 KeyError: 'has_more' #342

Closed Liborsaf closed 1 year ago

Liborsaf commented 1 year ago

Trying to request cloud with just one device throwing me:

Traceback (most recent call last):
  File "F:\Development\Workspace Python\tuya-local-stuff\main.py", line 28, in <module>
    main()
  File "F:\Development\Workspace Python\tuya-local-stuff\main.py", line 11, in main
    devices = cloud.getdevices()
  File "F:\Development\Workspace Python\tuya-local-stuff\venv\lib\site-packages\tinytuya\Cloud.py", line 434, in getdevices
    json_data = self._get_all_devices()
  File "F:\Development\Workspace Python\tuya-local-stuff\venv\lib\site-packages\tinytuya\Cloud.py", line 381, in _get_all_devices
    has_more = result[i]['has_more']
KeyError: 'has_more'

So I have added check if the key 'has_more' is in the result.

uzlonewolf commented 1 year ago

Thanks @Liborsaf !

jasonacox commented 1 year ago

https://pypi.org/project/tinytuya/1.12.6/