jasonacox / tinytuya

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

python3 -m tinytuya wizard getting error KeyError: 'local_key' #292

Closed tlees1611 closed 1 year ago

tlees1611 commented 1 year ago

Hi, i have foloowed all the guides, tried upgrading, reinstalling etc, but still cant get "python3 -m tinytuya wizard" to work. I have the Tuya app in Homeassistant working no problem. trying to get it running with python scripts for something else i want to build but it keeps coming up with

TinyTuya Setup Wizard [1.10.3]

Existing settings:
    API Key=xxxxxxxxxxxxxxxxxxxx 
    Secret=xxxxxxxxxxxxxxxxxxxxxxxxx
    DeviceID=bf0a96aeaxxx8c08uijg
    Region=eu

Use existing credentials (Y/n): y

Traceback (most recent call last): File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/pi/.local/lib/python3.7/site-packages/tinytuya/main.py", line 76, in wizard.wizard(color=color, retries=retries, forcescan=force) File "/home/pi/.local/lib/python3.7/site-packages/tinytuya/wizard.py", line 156, in wizard tuyadevices = cloud.filter_devices( json_data['result'] ) File "/home/pi/.local/lib/python3.7/site-packages/tinytuya/Cloud.py", line 350, in filter_devices item['key'] = i['local_key'] KeyError: 'local_key'

please help....

jasonacox commented 1 year ago

Can you try again but with debug mode?

python3 -m tinytuya wizard -d
uzlonewolf commented 1 year ago

The device fetching rework in PR #289 should keep it from blowing up even if local_key is missing, though it sounds like there's a problem elsewhere if that's happening.

uzlonewolf commented 1 year ago

@tlees1611 Please update tinytuya to 1.11.0 and try again and let us know what it outputs. I'm interested in knowing what devices do not have a local key.

tlees1611 commented 1 year ago

That worked perfectly, the devices that didnt have keys are:- { "name": "Wi-Fi Socket", "id": "bf5f512b10d83b7acfqmls", "key": "", "mac": "", "category": "cz", "product_name": "Wi-Fi Socket", "product_id": "hzsl8cxxtpd0x56b", "biz_type": 0, "model": "EmateSocket", "sub": true, "icon": "https://images.tuyaeu.com/smart/icon/ay1556838860681oKmdO/a475d09a86f87279a5fb63d3e8bcba84.png", "uuid": "bf5f512b10d83b7acfqmls", "parent": "bf5f512b10d83b7acfqmls" }, { "name": "WX1 Tap Timer", "id": "bf9a5ab8f30f74d28cz0sn", "key": "", "mac": "", "category": "kg", "product_name": "WX1 Tap Timer", "product_id": "zrsgzc8jktsricjj", "biz_type": 0, "model": "EMateWTT", "sub": true, "icon": "https://images.tuyaeu.com/smart/icon/ay1556838860681oKmdO/ab17f6e4e677bba7d3868a7a57cfe5b7.png", "uuid": "bf9a5ab8f30f74d28cz0sn", }, { "name": "Smart Hub", "id": "bf0298c7bd7031a63et36q", "key": "", "mac": "48:3f:da:6d:b6:ff", "uuid": "64240413483fda6db6ff", "sn": "100003551000C5", "category": "wfcon", "product_name": "Bluetooth hub", "product_id": "bkjsfuzu", "biz_type": 0, "model": "SGS01HA", "sub": true, "icon": "https://images.tuyaeu.com/smart/icon/ay1536534747810ekKBj/1566277572ce48af53c29.png", "parent": "bf5f512b10d83b7acfqmls" }, { "name": "Contact Sensor", "id": "bf0725399c77ca4db6flao", "key": "", "mac": "DC:23:4D:16:0E:44", "uuid": "3c0fac6b9f017144", "sn": "1000061820024B", "category": "mcs", "product_name": "Contact Sensor", "product_id": "kadfkbvr", "biz_type": 0, "model": "YIDONG", "sub": true, "icon": "https://images.tuyaeu.com/smart/icon/ay1536534747810ekKBj/156584136047cd8f7c1a2.png", "parent": "bf5f512b10d83b7acfqmls" }, { "name": "Climate Sensor", "id": "bf337460946126ce4afpzq", "key": "", "mac": "DC:23:4D:16:02:D0", "uuid": "7836067e1bfae33a", "sn": "10000618100103", "category": "wsdcg", "product_name": "Climate Sensor", "product_id": "3ubxbto1", "biz_type": 0, "model": "YIDONG", "sub": true, "icon": "https://images.tuyaeu.com/smart/icon/ay1536534747810ekKBj/156584130076b224f5a50.png", "parent": "bf5f512b10d83b7acfqmls" }, { "name": "Motion Sensor", "id": "bfd251f2088aa6b6bbxb3a", "key": "", "mac": "DC:23:4D:16:18:2E", "uuid": "6f6a59b3639c8f79", "sn": "10000618300400", "category": "pir", "product_name": "Motion Sensor", "product_id": "6xcrb0jp", "biz_type": 0, "model": "YIDONG", "sub": true, "icon": "https://images.tuyaeu.com/smart/icon/ay1536534747810ekKBj/1565841334dae0a2029d5.png", "parent": "bf5f512b10d83b7acfqmls" },

uzlonewolf commented 1 year ago

Hmm, that's interesting. I'm assuming what happened is the devices were claimed by a smart hub and because of that the local keys are either hidden or were not uploaded to the cloud. It also looks like the Wizard's parent detection fails when the local key is missing (when it was written the assumption was devices would always have a local key). Interesting.