Stabilize the operation if multicast traffic isn't available or lossy
See original GitHub issue- Check if multicast messages was received in the past (“iam” discovery response / heartbeats) and log a warning.
- Recovery from “Invalid key” by retrieval of a new token (get_id_list)
- If every executed command needs a “token recovery” report a degraded performance because of the lack of multicast traffic.
- Implement an indicator if a command execution was successful (without invalid key response) to be sure a valid encryption key is used.
cp. https://community.home-assistant.io/t/pyxiaomigateway-problem-error-invalid-key/28168 https://community.home-assistant.io/t/xiaomi-gateway-integration-help-needed/28563/10 https://community.home-assistant.io/t/new-xiaomi-gateway-firmware-xiaomi-aqara-component/27637/30 https://community.home-assistant.io/t/xiaomi-gateway-not-discovered/25030/158 https://community.home-assistant.io/t/xiaomi-sensors-not-working-after-0-57-update-solved/31693/6 https://community.home-assistant.io/t/xiaomi-gateway-is-recognized-but-does-not-take-any-commands-or-brings-data-help-needed/28725
This is my explanation of the “invalid key” error:
Some responses (get_id_list (direct message), heartbeat (multicast)) of the gateway contains a “token” which is valid for a short period of time. The combination of the token plus the encryption key of the android app is used to calculate the “key” value of a “write” command:
{"cmd": "write", "sid": "34ce00909ed1", "data": {"rgb": 3036676095, "key": "5059aeccf37f66b5cfec0cdfaab76e29"}}
I don’t know the behavior of the gateway exactly but if you miss one (or multiple) of the temporary tokens a old/invalid token is used and the misleading “Invalid key” error pops up although your encryption key (android key) is fine.
We will implement a safeguard for the “Invalid key” error so a new token will be requested and a retry of the failed command wil be sent. Do not forget: The cause of the issue is packet loss. 😦
cp. https://github.com/Danielhiversen/PyXiaomiGateway/issues/21
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
No, it’s just fixing some minor issues with communication between client and hub.
That’s because their network is misconfigured. Aqara hub doesn’t provide another pushing communication method, except multicasting.
I will use your code as basis and try to provide some iptable rules for testing.