Add unique_id for Xiaomi Vacuums#34225
Add unique_id for Xiaomi Vacuums#34225shbatm wants to merge 3 commits intohome-assistant:devfrom shbatm:xiaomi_vacuum_uid
Conversation
|
This pull request needs to be manually signed off by @home-assistant/core before it can get merged. |
|
Hey there @rytilahti, @syssi, mind taking a look at this pull request as its been labeled with a integration ( |
Co-Authored-By: J. Nick Koston <nick@koston.org>
| unique_id = None | ||
|
|
||
| try: | ||
| vacuum = Vacuum(host, token) |
There was a problem hiding this comment.
Only wrap the line where an error could occur.
There was a problem hiding this comment.
That would be the info call in this case.
There was a problem hiding this comment.
This should be cleaned up in the other platforms as well when changes discussed in #32091 (comment) are implemented. They are all inconsistent.
There was a problem hiding this comment.
The integration needs refactoring before this can happen. The common code should not be spread around each platform file like it currently is, see #32091 (comment) (and the comments from Martin above) as well as the linked commentary on what should be done.
Now, the second point why this has not been added already is that this will break it for users who do not allow the vacuum to the internet (at least for gen1 users, I have no access to other devices), so there needs to be a solution for those users to configure the unique ID somehow.
Why would the info call need to be routed through the internet? I have my Roborock S5 Max blocked from external communications, but can call
Bowing out of that. I'll leave this PR request open for now just in case Martin want's to approve the small-pr in the meantime. If not, feel free to close--this was needed for me so I could actually rename the devices in the UI. |
It is not routed through the internet, gen1 vacuums just simply respond with an empty payload if they have no cloud connectivity. However, you are right, this could be fixed in python-miio by handing out a surrogate info when this happens. I'll make a todo to do just that, but no matter whether it's acceptable to merge this before refactoring the integration, it should not be done before a new python-miio version with that fix is released. |
|
Just a question, or a note for the future, @rytilahti and @shbatm,
|
|
@azogue I'm not sure I'm following, could you elaborate? The proper way to my understanding would be to use the mac address obtained from |
|
I think he's referring to the Home Assistant device_info which is used when you have a config flow (as opposed to YAML), so device information can be added into the HA Device Registry. I think what he's hinting at is the setup function should save the full result of the https://developers.home-assistant.io/docs/device_registry_index/#device-properties |
As @shbatm pointed out much better than me, I was talking about HA concepts around the config_flow :) About expanding a physical device like the vacuum into multiple entities in HA related to 1 device, the usual approach is to use the unique id as
I think the current approach is to use the generated ConfigEntry uuid as device_id/unique_id if there is no way to extract something unique like the MAC, but in this case that could add an extra problem to identify an existent device (the config flow has to avoid multiple configs around the same device!). Another path to explore in those cases could be the access token? or as you say, something linked to the handshake data I may be able to help you @rytilahti, I have a gen1 vacuum and time to spare :) |
|
@shbatm @azogue thanks for the clarifications! Yes, I think the whole info object should be passed (it contains also information like hw, firmware versions etc. - https://github.com/rytilahti/python-miio/blob/master/miio/device.py#L25) Back to the problematic cases; as far as I know this info problem is only happening with non-cloud-connected gen1 vacuums, but there may be also other devices behaving similarly. That being said, I think the best way is to go around this limitation is to create a surrogate info objects when the information fetching fails. This will make handling of these devices transparent to homeassistant, which can trust that there will always be an info object available. Ignoring rest of the data available in this object, the three potential "seeds" for the mac information are the following:
@azogue feel free to experiment on this, any help would be greatly appreciated :-) On the entity explosion, I agree that it (and other refactorings, e.g., the setups should be done using the edit: In case the device id in the header is really unique, this could obviously be used instead of the mac address. I checked all devices I have (gen1 vacuum, 2 yeelight color bulbs, yeelight bedside lamp, gosund plug and zhimi smartstrip) where that was the case. Nevertheless, I think we want to have a surrogate info just to simplify the implementation of device type detection. |
|
You can always make unique ID optional while figuring out unique ID for the non connected cases. You can use the config entry ID for devices that don't have a unique ID themselves. |
|
Okay, then I think the best approach is simply to modify python-miio to raise a new type of exception ( This integration can then be adapted to fallback to config entry id (or other means) while using the device information for devices which support it. |
…bleException Enables better control of error cases for downstream users: * PayloadDecodeException gets raised if the payload cannot be decoded even after all quirks are tried * DeviceInfoUnavailable gets raised by Device.info() if decoding the miIO.info payload fails Related: home-assistant/core#34225
* Add two new exceptions: PayloadDecodeException and DeviceInfoUnavailableException Enables better control of error cases for downstream users: * PayloadDecodeException gets raised if the payload cannot be decoded even after all quirks are tried * DeviceInfoUnavailable gets raised by Device.info() if decoding the miIO.info payload fails Related: home-assistant/core#34225 * add tests
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Requires upstream changes. |
|
The latest python-miio release from two weeks ago (https://github.com/rytilahti/python-miio/releases/tag/0.5.1) adds two more specific exceptions that should allow this PR to proceed? So basically wrapping the info call to catch |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
This feature is still a needed feature, right ? |
|
Yes, I just don't have the resources to implement. |
…hti#685) * Add two new exceptions: PayloadDecodeException and DeviceInfoUnavailableException Enables better control of error cases for downstream users: * PayloadDecodeException gets raised if the payload cannot be decoded even after all quirks are tried * DeviceInfoUnavailable gets raised by Device.info() if decoding the miIO.info payload fails Related: home-assistant/core#34225 * add tests
Proposed change
Add a unique_id property for Xiaomi Vacuums.
Type of change
Additional information
Implement the unique_id property for Xiaomi Miio Vacuum devices so they can be renamed and manipulated in the UI better. Unique ID used is the same format as the other Miio device domains (Model-MAC Address).
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt. N/AUpdated by running
python3 -m script.gen_requirements_all..coveragerc. N/AThe integration reached or maintains the following Integration Quality Scale: