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
71.11k stars 29.79k forks source link

Xiaomi Miio - Unable to add more than one humidifier: "Re-authentication was successful" abort. #57547

Closed nvsnkv closed 2 years ago

nvsnkv commented 2 years ago

The problem

I have 3 zhimi.humidifier.cb1 devices that were previously configured in configuration file and worked fine. This year I decided to reconnect them and use UI for configuration. There was no issue when I added first humidifier, but all my attempt to add remaining 2 failed with "Re-authentication was successful" error.

I tried both cloud and "manual" configuration - results are the same. I did not find anything suspicious in a logs, but I have no idea what to search for.

What is version of Home Assistant Core has the issue?

core-2021.10.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Xiaomi Miio

Link to integration documentation on our website

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

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

I'm not an expirienced HA developer, but I think my issue may be caused by the way how integration assigns unique_id:


        unique_id = self.mac
        existing_entry = await self.async_set_unique_id(
            unique_id, raise_on_progress=False
        )

I believe, AsusWRT may also do the same when it creates a tracker. As a result, Miio integration can no longer create new device Can this code be updated to add some integration-unique part to unique_id to avoid possible clashes? unique_id = self.mac + XIAOMI_MIIO_INTEGRATION_ID

probot-home-assistant[bot] commented 2 years ago

Hey there @rytilahti, @syssi, @starkillerog, @bieniu, 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! (message by CodeOwnersMention)


xiaomi_miio documentation xiaomi_miio source (message by IssueLinks)

nvsnkv commented 2 years ago

Okay, after few our of digging here and there I don't think that issue is related to fact that I'm adding devices of the same type. It looks like I have duplicate entry in device registry for one of my humidifiers. I'm closing this issue since the problem statement is incorrect

jbouwh commented 2 years ago

As far as I can see the mac address is the base of the unique_id already. A second device should have a different mac_address. You need to add the xiao_miio integration for a second time. The entry id from the entity registry should be unique. This is used address and to store the device specific properties and data in home assistant.

https://github.com/home-assistant/core/blob/8ec38ef034f4d09686076ae3616e7c29f06706d0/homeassistant/components/xiaomi_miio/__init__.py#L339-L342

A DataCoordinator data_class is used to transfer the data to all the device entities. Per haps your old humidifier still has an entity registry entry that that need to be cleaned up first.

nvsnkv commented 2 years ago

Thanks @jbouwh ! Glad to see that I'm on a right track. The problem is I don't see any other mention of my humidifier neither in entities nor in devices in HA. It was previously mentioned as a device added by AsusWRT (device tracker), but I removed AsusWRT integration and still can't add my humidifier :( What would be the right way to find and clean it up?

nvsnkv commented 2 years ago

just to close this chain: I finally was able to add my last humidifier after I cleaned up mentions of this device in core.device_registry and core.entity_registry files in /config/.storage.