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

Require pyca/cryptography >= 3.1, and add tools/fake-v35-device.py #424

Closed uzlonewolf closed 7 months ago

uzlonewolf commented 7 months ago

An interesting use of fake-v35-device.py is setting bcast_to to the IP of either a SmartLife-running device or a gateway/hub device and changing gwId/real_key to that of one of your devices - doing this will cause said device to send v3.5 commands to this script, which you can then inspect and reverse engineer. This is basically how I got v3.5 support working despite not having any v3.5 devices.

ttcorefunc.py is a "known good" copy of tinytuya/core.py (with most of the device stuff stripped out). By forcing it to use PyCryptodome I was able to use fake-v35-device.py to test the pyca/cryptography functions in the real tinytuya/core.py.

jasonacox commented 7 months ago

✅ Worked for my use case from #423 ...

Was

DEBUG:TinyTuya [1.13.0]

DEBUG:Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
[GCC 8.4.0] on linux
DEBUG:Using pyca/cryptography 2.1.4 for crypto, GCM is supported

This PR

DEBUG:TinyTuya [1.13.0]

DEBUG:Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
[GCC 8.4.0] on linux
DEBUG:Using PyCryptodome 3.18.0 for crypto, GCM is supported

Testing others...

✅ Linux ✅ Win11 ✅ MacOS ✅ RPi

jasonacox commented 7 months ago

Thanks @uzlonewolf ! I've pushed v1.13.1.