home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.02k stars 31.05k forks source link

Xiaomi Miio Cloud login Results in Unknown error occurred. #127015

Open korruptcow opened 2 months ago

korruptcow commented 2 months ago

The problem

I am trying to get my zhimi.airpurifier.m2 back online after a wifi ssid reset and now when I used the login to the cloud option and select SG which is where my account is from it says "Unknown error occurred".

Nothing comes up in the log with it either at the moment. Wondering if theres anything else to try.

What version of Home Assistant Core has the issue?

2024.4.4

What was the last working version of Home Assistant Core?

2024.4.4

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Xiaomi Miio

Link to integration documentation on our website

https://www.home-assistant.io/integrations/xiaomi_miio

Diagnostics information

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper result = await method(view, request, data, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post result = await self._flow_mgr.async_configure(flow_id, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 356, in async_configure result = await self._async_configure(flow_id, user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 402, in _async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 506, in _async_handle_step result: _FlowResultT = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/config_flow.py", line 240, in async_step_cloud miio_cloud = MiCloud(cloud_username, cloud_password) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/micloud/micloud.py", line 38, in init timezone = datetime.datetime.now(tzlocal.get_localzone()).strftime('%z') ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/tzlocal/unix.py", line 219, in get_localzone _cache_tz = _get_localzone() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/tzlocal/unix.py", line 176, in _get_localzone tzenv = utils._tz_from_env() ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/tzlocal/utils.py", line 109, in _tz_from_env raise zoneinfo.ZoneInfoNotFoundError( zoneinfo._common.ZoneInfoNotFoundError: 'tzlocal() does not support non-zoneinfo timezones like Melbourne/Australia. \nPlease use a timezone in the form of Continent/City'

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 2 months ago

Hey there @rytilahti, @syssi, @starkillerog, mind taking a look at this issue as it has been labeled with an integration (xiaomi_miio) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `xiaomi_miio` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign xiaomi_miio` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


xiaomi_miio documentation xiaomi_miio source (message by IssueLinks)

syssi commented 2 months ago

Please change the timezone to Australia/Melbourne to fix the issue.

korruptcow commented 1 month ago

Where do we do that sorry? I did it in Ha and I tried to change the micloud.py but all i get after that is

"Could not login to Xiaomi Miio Cloud, check the credentials."

I followed this from another thread with the same issue.

I have a workaround as follows:

docker exec -it your_homeassistant_container_id bash

cd /usr/local/lib/python3.9/site-packages/micloud

vi micloud.py

comment out line 38, 39, modify line 40 directly to your timezone, in my case is:

self.timezone = 'Asia/Shanghai’

save the file, exit the docker

docker restart your_homeassistant_container_id

korruptcow commented 1 month ago

I am getting this error after updating HA to newest version it still either says unknown error or wrong credentials.

2024-09-30 05:35:14.171 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('tzdata.zoneinfo.Melbourne',) inside the event loop by integration 'xiaomi_miio' at homeassistant/components/xiaomi_miio/config_flow.py, line 240: miio_cloud = MiCloud(cloud_username, cloud_password) (offender: /usr/local/lib/python3.12/importlib/resources/_common.py, line 82: return importlib.import_module(cand)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+xiaomi_miio%22 For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module

If i set the TZ in the micloud.py i get wrong credentials but nothing else shows up in the logs. So i cant tell why it fails..

HomeAssistantPim commented 1 month ago

Any solution yet, this seems to be blocking any first use of Xiaomi integration, not being able to install it. I also tried a token extractor, same issue. Tomorrow I will get an E12, not sure if this can still be integrated into home assistant since even manual setup of the integration seems no longer possible.

korruptcow commented 1 month ago

No solution yet i have tried multiple different options. Even the token extractors don't seem to work either for me.

HomeAssistantPim commented 1 month ago

Ok. After some investigation on my own I suspect that Xiaomi is moving towards OAuth2 managed security tokens. For sure is that the token is being refreshed when the device connects with a different WiFi network and afterwards no longer responds to UDP packets (lacking a valid token?). My guess: Xiaomi is moved towards a scenario were to use such Xiaomi devices within HA you would require to buy some Xiaomi hub/gateway or some cloud service that can be integrated to colaborate with other smart home systems :(

korruptcow commented 1 month ago

So even it wont work with local with the token like it used to?

syssi commented 1 month ago

If you change your WiFi (SSID/credentials) your Xiaomi device gets provisioned as receives a new token. It has always been this way. As long you know the valid token of your device you should be able to talk to the device locally.

Only the automatic retrieval of the token per device from the Xiaomi Cloud looks broken at the moment.