rytilahti / python-miio

Python library & console tool for controlling Xiaomi smart appliances

Home Page:https://python-miio.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mi Smart Power Plug 2 (chuangmi.plug.212a01) requires real did for multirequests

LZY-SPCA opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.
I want to use genericmiot to control Mi Smart Power Plug 2 (Wi-Fi and Bluetooth Gateway), but when I use 'status' parameter it said did need. And when I use 'actions' it return nothing.

Version information (please complete the following information):

  • OS: Ubuntu 22.04
  • python-miio: miiocli, version 0.6.0.dev0

Device information:
Running command info
Model: chuangmi.plug.212a01
Hardware version: esp32
Firmware version: 2.1.8_0044
Supported using: GenericMiot
Command: miiocli genericmiot --ip 192.168.10.245 --token
Supported by genericmiot: True

To Reproduce
Steps to reproduce the behavior:
1.

Expected behavior
A clear and concise description of what you expected to happen.

Console output
DEBUG:miio.miioprotocol:192.168.10.245:54321 (ts: 1970-01-01 07:41:19+00:00, id: 2) << {'error': {'code': -32602, 'message': 'need did'}, 'exe_time': 10, 'id': 2}
ERROR:miio.click_common:Exception: {'code': -32602, 'message': 'need did'}

This error is coming from the device and one could only guess that this device/firmware doesn't like the way this library is using the did in the requests. At the moment, this is used to store a simplified name, but perhaps this device requires a real did of the device?

You could try to use raw_command command of the tool with a payload you see in your debug logs, but replacing the did part with the real device id. You can find that id in the debug output of protocol responses, there's a field called device_id which has it as a hex-encoded string:

device_id = unhexlify('02f2abba')

For the raw payload, you want to convert this to an integer, for example using python:

python -c 'print(int("02f2abba", 16))'
49458106

Let me know if that helps!

I change all the did to real device id and it works, but when I run each property separately it can run without changing the did. I also use API to get single property from the device without did and it also works. However, if I get more than one property without changing the 'did' it just failed and say that I need 'did' .I'm confused.
QQ图片20240216163933

Yeah, that's a firmware bug. Let's keep this issue open, we need to add some type of quirk handling for such cases, likely by passing the real did for listed models.

Thank you so much!