jasonacox / tinytuya

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

Tinytuya server command /sync is deleting mappings in #439

Open JRB202 opened 6 months ago

JRB202 commented 6 months ago

Hi Jason,

I also discovered an other problem with mapping readings :

The tinytuya server command /sync is purging mapping descriptions in devices.json ! Obviously, following command /status/ are missing these dps_mapping.

To reproduce the problem : On machine running tinytuya server 1° Stop server : docker stop tinytuya 2) python3 -m tinytuya wizard with correct Tuya Cloud credentials 3) nano devices.json (as just updated by wizard) and see "mapping" field containing all devices mappings 4) docker start tinytuya

5) Open url like : http://192.168.xx.xx:8888/status/ and see the mapping codes and values correctly displayed as last field of screen 6) Execute http://192.168.xx.xx:8888/sync Result is Ok But ... 7) Reopen same url as step 5 and see that mappings are not displayed anymore 8) nano devices.json and see that mappings have been deleted from device definition which is cause of http://192.168.xx.xx:8888/status/ failure to display mappings

To restore correct mapping displays by server /status , rerun steps from 1 to 4 and do NOT execute http://192.168.xx.xx:8888/sync again !

The problem is probably localized in def getdevices from cloud.py between lines 396 and 513

JRB202 commented 6 months ago

As temporary workaround, this bash script could be used to regenerate correct mappings in devices.json instead of using tinyserver command /sync

!/bin/bash

cd ~/tinytuya docker stop tinytuya printf 'Y\nY\n\N\n' | python3 -m tinytuya wizard docker start tinytuya sleep 3 # Wait 3 seconds to let server be started before following commands exit