fix(esphome): allow saving unreachable reconfigure host#169707
Draft
Komzpa wants to merge 2 commits intohome-assistant:devfrom
Draft
fix(esphome): allow saving unreachable reconfigure host#169707Komzpa wants to merge 2 commits intohome-assistant:devfrom
Komzpa wants to merge 2 commits intohome-assistant:devfrom
Conversation
Contributor
|
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
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the ESPHome reconfiguration flow so users can explicitly save a new host/port even when the device cannot currently be reached, while still preserving the existing config entry identity and keeping the stricter validation path for reachable devices.
Changes:
- Add a new reconfigure confirmation step when the updated ESPHome host/port cannot be resolved or reached.
- Update the unreachable-confirmation path to save only host and port on the existing config entry.
- Add translations and config-flow tests for the new unreachable reconfigure behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
homeassistant/components/esphome/config_flow.py |
Adds the unreachable reconfigure confirmation branch and updates the entry with only host/port after confirmation. |
homeassistant/components/esphome/strings.json |
Adds the user-facing confirmation text for unreachable ESPHome address changes. |
tests/components/esphome/test_config_flow.py |
Adds config-flow tests covering saving a changed unreachable host and rejecting unchanged unreachable details. |
Comment on lines
+275
to
+282
| and self._async_reconfigure_host_changed() | ||
| ): | ||
| return await self.async_step_reconfigure_confirm_unreachable() | ||
| return await self._async_step_user_base(error=response) | ||
| return await self._async_authenticate_or_add() | ||
|
|
||
| @callback | ||
| def _async_reconfigure_host_changed(self) -> bool: |
Comment on lines
+311
to
+313
| "name": self._reconfig_entry.data.get( | ||
| CONF_DEVICE_NAME, self._reconfig_entry.title | ||
| ), |
| "description": "The ESPHome device `{name}` disabled transport encryption. Please confirm that you want to remove the encryption key and allow unencrypted connections." | ||
| }, | ||
| "reconfigure_confirm_unreachable": { | ||
| "description": "Home Assistant could not validate `{host}:{port}` for `{name}` because the device is currently unreachable.\n\nOnly continue if you are sure this is the correct new address. Home Assistant will keep the existing device identity and update only the host and port.", |
Comment on lines
+273
to
+275
| self.source == SOURCE_RECONFIGURE | ||
| and response in ("connection_error", "resolve_error") | ||
| and self._async_reconfigure_host_changed() |
3f1563a to
72fc863
Compare
| ("2001:db8::2", ResolveAPIError, "[2001:db8::2]"), | ||
| ], | ||
| ) | ||
| async def test_reconfig_can_save_changed_unreachable_connection( |
Comment on lines
+74
to
+75
| "description": "Home Assistant could not validate `{host}:{port}` for `{name}` because the device is currently unreachable.\n\nOnly continue if you are sure this is the correct new address. Home Assistant will keep the existing device identity and update only the host and port.", | ||
| "title": "Confirm unreachable ESPHome address" |
| assert result["step_id"] == "reconfigure_confirm_unreachable" | ||
| assert result["description_placeholders"] == { | ||
| "host": placeholder_host, | ||
| "name": "Kitchen Sensor", |
Comment on lines
+285
to
+287
| self.source == SOURCE_RECONFIGURE | ||
| and response in ("connection_error", "resolve_error") | ||
| and self._async_reconfigure_connection_changed() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Context
This covers stale-address reconfigure cases where the previously saved ESPHome address is no longer useful, or the old address is now occupied by another device. Reconfigure should let the user save a known new address without requiring the device to be online at that moment, but only after an explicit confirmation and without changing identity data that could belong to a different ESPHome node.
Validation
Using Python 3.14.4, matching the current
requires-python >=3.14.2constraint:venv/bin/python -m py_compile homeassistant/components/esphome/config_flow.py tests/components/esphome/test_config_flow.pyvenv/bin/python -m json.tool homeassistant/components/esphome/strings.json >/tmp/esphome_strings.jsonvenv/bin/python -m ruff check homeassistant/components/esphome/config_flow.py tests/components/esphome/test_config_flow.pyvenv/bin/python -m script.translations develop --allvenv/bin/python -m pytest tests/components/esphome/test_config_flow.py -k 'reconfig_can_save_changed_unreachable_host or reconfig_same_unreachable_host_shows_error or reconfig_attempt_to_change_mac_aborts or reconfig_success_with_new_ip_new_name' -q(4 passed, 73 deselected)git diff --check