Register a stub transport for ESPHome serial proxies via USB#169308
Conversation
|
Hey there @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
Hey there @jesserockz, @kbx81, @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR ensures esphome-hass:// serialx URLs fail gracefully (with ConfigEntryNotReady) when ESPHome hasn’t loaded yet, by registering a low-priority stub transport from the USB integration.
Changes:
- Add a USB-owned stub
esphome-hass://serialx URI handler that raisesConfigEntryNotReadyon open. - Adjust ESPHome’s
register_uri_handlerregistration to use a distinctunique_schemeso multiple handlers can coexist. - Add a USB integration test that validates the stub handler is selected and raises the expected exception.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/usb/serial_proxy_stub.py |
New stub serialx URI handler/transport that raises ConfigEntryNotReady until ESPHome loads. |
homeassistant/components/usb/__init__.py |
Imports the stub module to register the URI handler during USB integration import. |
homeassistant/components/esphome/serial_proxy.py |
Updates handler registration to use a different unique_scheme to allow parallel registrations. |
tests/components/usb/test_init.py |
Adds a test ensuring the stub handler is registered and raises ConfigEntryNotReady when opened. |
|
we have bluetooth_adapters integration for similar load order problems to make sure components needed for bluetooth load before. Not sure if thats better or worse for this case |
|
It's a bit of a weird situation here because integrations that rely on USB now have an implicit runtime dependency on ESPHome but only if an ESPHome serial proxy is actually used. These integrations typically only have I see a few options:
|
0a5c18a to
69f1889
Compare
bdraco
left a comment
There was a problem hiding this comment.
This works, its not as architecturally pure as I'd like, but the other options aren't particularly better so its pragmatic.
Proposed change
Integrations that depend on
usbbut notesphomecan load earlier than the ESPHome integration, before theesphome-hass://URI handler is registered with serialx. This causes them to fail withserialx.common.UnknownUriScheme.This PR registers a second handler for
esphome-hass://with a lower weight. Integrations that try to connect before ESPHome has loaded will immediately fail withConfigEntryNotReady. Once ESPHome loads, the real implementation of this serial transport will take over.Type of change
Additional information
Checklist
ruff format 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.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: