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

Use {DeviceName} instead of {DeviceID} alternatively for API commands #352

Closed mschlenstedt closed 1 year ago

mschlenstedt commented 1 year ago

I added the possibility to use {DeviceName} instead of {DeviceID} in API commands for a more convinient way to set up API calls. If one uses {DeviceName} the Device Names must be absolutely unique, of course.

jasonacox commented 1 year ago

Thanks, @mschlenstedt ! Nice addition.

# by DeviceID
$ curl http://localhost:8888/status/xxxxxxxxxxxxxxxxxx01
{"devId": "xxxxxxxxxxxxxxxxxx01", "dps": {"1": true, "9": 0}}

# by DeviceName
$ curl http://localhost:8888/status/Kitchen%20Light
{"devId": "xxxxxxxxxxxxxxxxxx01", "dps": {"1": true, "9": 0}}
$ curl http://localhost:8888/status/SmartBulb                                
{"devId": "xxxxxxxxxxxxxxxxxx02", "dps": {"20": true, "21": "white", "22": 1000, "24": "000003e803e8", "25":"07464602000003e803e800000000464602007803e803e80000000046460200f003e803e800000000464602003d03e803e80000000046460200ae03e803e800000000464602011303e803e800000000", "26": 0}}

I updated the build to t7 and will push it to dockerhub.