Skip to content

fix(esphome): allow saving unreachable reconfigure host#169707

Draft
Komzpa wants to merge 2 commits intohome-assistant:devfrom
Komzpa:codex/esphome-reconfigure-offline-host
Draft

fix(esphome): allow saving unreachable reconfigure host#169707
Komzpa wants to merge 2 commits intohome-assistant:devfrom
Komzpa:codex/esphome-reconfigure-offline-host

Conversation

@Komzpa
Copy link
Copy Markdown

@Komzpa Komzpa commented May 4, 2026

Summary

  • add a confirmation step for ESPHome reconfigure when the changed host/port cannot be resolved or reached
  • update only the saved host and port from that confirmation path, preserving the existing entry identity, device name, password, and noise key
  • keep the existing validation path for reachable devices, so MAC/unique_id changes still abort instead of silently retargeting the entry

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.2 constraint:

  • venv/bin/python -m py_compile homeassistant/components/esphome/config_flow.py tests/components/esphome/test_config_flow.py
  • venv/bin/python -m json.tool homeassistant/components/esphome/strings.json >/tmp/esphome_strings.json
  • venv/bin/python -m ruff check homeassistant/components/esphome/config_flow.py tests/components/esphome/test_config_flow.py
  • venv/bin/python -m script.translations develop --all
  • venv/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

Copilot AI review requested due to automatic review settings May 4, 2026 00:53
@home-assistant home-assistant Bot added cla-signed has-tests integration: esphome Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage Top 50 Integration is ranked within the top 50 by usage labels May 4, 2026
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 4, 2026

Hey there @jesserockz, @kbx81, @bdraco, mind taking a look at this pull request as it has been labeled with an integration (esphome) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of esphome can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign esphome Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
@Komzpa Komzpa force-pushed the codex/esphome-reconfigure-offline-host branch from 3f1563a to 72fc863 Compare May 4, 2026 01:12
Copilot AI review requested due to automatic review settings May 4, 2026 01:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

("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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed has-tests integration: esphome Quality Scale: platinum Top 50 Integration is ranked within the top 50 by usage Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants