mattsaxon / pysonofflan

Python interface for controlling Sonoff smart switches/plugs running original Itead firmware, locally, in "LAN mode".
MIT License
32 stars 23 forks source link

422 When Sending State Change #218

Open animaxcg opened 3 years ago

animaxcg commented 3 years ago

Description

I know this is unsupported now but I am getting 422 when trying to set state

What I Did

pysonofflanr3 --host someip --device_id id --api_key wouldnt_u_like_to_know -l DEBUG state
returns state
pysonofflanr3 --host someip --device_id id --api_key wouldnt_u_like_to_know -l DEBUG on
2020-12-11 00:10:55,765 - warning: error received: id, b'{"seq":37,"sequence":"1607667055588","error":422}'

looking at http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html I see that - 422: The operation failed and the request parameters are invalid. For example, the device does not support setting specific device information. this is a TH16 with firmware 3.4.1

I even modified the code to make sure the data was being sent correctly by passing the data from format_encryption_msg to decrypt and getting the unencrypted byte data that was passed into encrypt. Does this just mean that the TH16 on 3.4.1 isn't supported? Should I try to set up home assistant and sniff my traffic to see if it is the device or this api? That seems like a ton of work

dauheeIRL commented 3 years ago

Hi, what results do you get when you run discover? Also can you look at mDNS output (i.e. use bonjour browser or similar application) and see what TH16 presents. Just looking at type field is normally "plug". I forked this project recently to pass outlet to the cli, as outlet is required for multi-gang wall switch (TX3C) which is "strip" type which luckily was handled by the code already, just not with the cli. I would guess the TH16 is different hence the error you get

dauheeIRL commented 3 years ago

you can see pull request here - someone has already put in on/off support for TH16 https://github.com/mattsaxon/pysonofflan/pull/151