Closed bongiozzo closed 2 years ago
Seems Xiaomi have completely changed their login api. There unfortunately does not seem to be an easy fix to this. I can't find any info or documentation about the change. The old method to login was basically reverse engineered from an old version of their app (that doesn't work anymore) that allowed debugging.
I'll keep looking for a solution but it does not look good atm.
Following
@Squachen we could look at what openhab is doing, I believe they also use the same cloud login so they schould be experiancing the same issues, maybe they found a solution.
I think the relevant code of openhab is here: https://github.com/openhab/openhab-addons/tree/main/bundles/org.openhab.binding.miio
I'm not sure whats going on with the API. It's seems like the login is successful most of the time now but sometimes it returns 403. Retrying again after a MiCloudAccessDenied
exception usually results in a completed login.
Reference https://github.com/al-one/hass-xiaomi-miot/commit/7fcc1f6da7abde3af10e6033bf1bb053ca683dba For me and others (https://github.com/home-assistant/core/issues/58991) the login always fails.
@Squachen apperently Xiaomi implemented rc4 encryption in their protocol. See https://github.com/home-assistant/core/issues/63180 for the discussion of the HomeAssistant issue. Xiaomi-cloud-tokens-extractor has already fixed its code by implementing this rc4 encryption: https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor/issues/50
I think the relevant commit is this one: https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor/commit/0e98bcae9aef525a7945e8c6a41df2c4e2d54ba5
@Squachen Could you implement this rc4 encryption with the example of the Xiaomi-cloud-tokens-extractor?
@starkillerOG Thank you for the references, I will try to make time to check it out and implement a fix tonight or tomorrow.
@starkillerOG I've released a new version with rc4 encryption. I've tested it against de/cn servers and it seems to be working now.
@Squachen greath, that is perfect! Thank you so much. I will make a PR for HomeAssistant to use the new version.
@starkillerOG : Any idea on when it is integrated in HA?
@Master-Mace it has already been merged to the dev branch of HomeAssistant, so it will be in the next HomeAssistant release. I don't exactly know when the next release will be, they skipped the januari release due to the hollidays, so I guess around 05-02-2022 there will be a next major release, that will have it for sure.
There may be another bugfix release in the mean time, which could already have it, but those are just beeing released whenever there are a significant number of bug fixes, so I don't know when that will happen.
see: https://developers.home-assistant.io/ Januari 26th will be the beta release and febuary 2nd will be the major release that will have it.
Bugfix releases are unpredictable.
Looks like it is already in https://github.com/home-assistant/core/releases/tag/2021.12.8 with pr https://github.com/home-assistant/core/pull/63348
Thanks, @starkillerOG for the fast response! @Schouwenburg : I'm on 2021.12.8 and although I indeed see the pr mentioned, I still get the "Retrying setup: DeviceException during setup of xiaomi gateway with host {self._host}" error.
So if it is in this release, apparently something is still not OK.
I was able to setup the integration yesterday. I did find out that I could not use the Roborock app credentials but needed to move to the mi home app and create a mi home cloud account which is something different (duh). Maybe not your issue.
Well, maybe I'm using wrong credentials. Mi Home Cloud Account credentials are the same as logging into the Mi Home App?
The error I get in the log after adding the integration: 2022-01-09 10:34:11 ERROR (SyncWorker_2) [xiaomi_gateway] The device with sid ########## isn't supported of the used gateway firmware. Please update the gateway firmware if possible! This is the only way the issue can be solved.
https://github.com/home-assistant/core/issues/58991
Downstream issue in home assistant