Skip to content

[Core] USB unplug flow abort disallowing 1-port migration with ZHA discovery #70

@TheJulianJES

Description

@TheJulianJES

It's enough to just read the parts with "❗" for the crucial information.
Do note that this is a very small edge-case, only becoming important when we formally allow a 1-port migration at some point in the future.

"Action item" / possible solution for issue below

❗ We should take a look at adding a method to config flows that allows them to override the removal for cases like mention below.
Here, it would make sense to "abort the abort" if the migration has been started by the user and we can expect that they're unplugging the new adapter temporarily.

Background

Proper USB unplugging support has finally been merged in Core with home-assistant/core#156303, so that when a USB device is unplugged, the discovery flow gets aborted, thus disappearing from the integration page. If it's plugged in again, the flow also correctly re-appears now.

"New issue" after USB unplugging abort

TL;DR: start migration through ZHA discovery flow + unplug adapter during migration to attempt 1-port migration => migration fails

However, there's one very small edge-case. Whilst it's not really an issue for now, as we do not call out that a 1-port migration is possible for ZHA, this is the issue:
When a ZHA discovered adapter is unplugged during the migration, the config flow breaks with an "Invalid flow specified" message. This is expected for now, as unplugging the USB adapter aborts the config flow entirely.

Why would they even unplug their new adapter during the migration in the first place?

Users can theoretically unplug their new adapter after starting the migration at a very specific step, plug in their old one, swap back, and finish the migration. We prompt the user to plug the correct adapter back in throughout the config flow if it's needed and missing.

Some users want/need to do a 1-port migration, as there are limited systems with only 2 USB ports available, so one might be used for ZWA-2 and another for ZBT-1/ZBT-2. If no USB hub is available, a 1-port migration is good to have.

Workaround

For now, you can just use the "Migrate adapter" option if you need to do a 1-port migration. This is recommended way anyway, as a proper backup will be taken of the old adapter. Starting the migration through a discovery ZHA flow (only possible for non-HA Connect adapters) does not allow taking a fresh backup of the old adapter IF it is not plugged in.

  • Using the "Migrate adapter" option, you can leave the old adapter plugged in (to take a fresh backup) (optional step).
  • Then swap to the new adapter before getting to the serial port selector screen (for probing and configuring ZHA).
  • Then swapping adapters to the old when prompted again (to reset).
  • Finally swapping back to the new one when prompted (to restore the backup).

This is a stupid way of doing a 1-port migration anyway (but it works). We'll look at changing this and possibly making it more similar to the Z-Wave flow. On the other side, a migration is only done every few years (if at all) by most users. Most users should also have 2 ports available, making this a non-issue in the first place.

Notes

❗ The above mentioned issue doesn't apply to ZBT-1/ZBT-2 due to the config flow chaining and a discovery flow only being created for the hardware integrations, not directly for the ZHA integration (by the USB integration).
It's also really nothing most users do at the moment, as we never mention a 1-port migration was/is possible somehow.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements of existing functionality

    Type

    No type

    Projects

    Status

    Later

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions