Skip to content

Conversation

@bdraco
Copy link
Member

@bdraco bdraco commented Jul 30, 2025

Proposed change

Fix ESPHome integration unnecessarily probing devices on DHCP discovery events.

When ESPHome devices renew their DHCP lease or reconnect to the network, the integration was probing them even when the IP address hadn't changed. This was causing rapid connect/disconnect cycles visible in ESPHome logs:

[11:28:23][D][api:144]: Accept 192.168.107.8
[11:28:23][W][api.connection:164]: 192.168.107.8: Reading failed CONNECTION_CLOSED errno=11
[11:28:23][D][api:144]: Accept 192.168.107.8
[11:28:23][D][api.connection:1358]: Home Assistant 2025.8.0.dev0 (192.168.107.8) connected

The issue occurred because DHCP discovery passes port=None, but the code was comparing configured_port == port (e.g., 6053 == None), which always failed and triggered unnecessary probing.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • Dependency upgrade
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @jesserockz, @kbx81, 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 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 add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@bdraco bdraco marked this pull request as ready for review July 30, 2025 22:04
Copilot AI review requested due to automatic review settings July 30, 2025 22:04
@bdraco bdraco requested review from jesserockz and kbx81 as code owners July 30, 2025 22:04

This comment was marked as outdated.

@bdraco bdraco requested a review from Copilot July 30, 2025 22:11
Copy link
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 fixes an issue where the ESPHome integration was unnecessarily probing devices during DHCP discovery events, even when the IP address hadn't changed. The problem occurred because DHCP discovery passes port=None, but the code was comparing this against the configured port (e.g., 6053 == None), which always failed and triggered unnecessary device probing.

Key changes:

  • Modified the host/port comparison logic to handle None port values from DHCP discovery
  • Added a test case to verify the fix prevents unnecessary probing

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/esphome/config_flow.py Updated comparison logic to skip port matching when port is None from DHCP discovery
tests/components/esphome/test_config_flow.py Added test case to verify DHCP discovery doesn't probe when host matches and port is None

@joostlek joostlek merged commit f9e7459 into dev Jul 30, 2025
34 checks passed
@joostlek joostlek deleted the fix_unneeded_esphome_probing branch July 30, 2025 23:06
@bdraco
Copy link
Member Author

bdraco commented Jul 30, 2025

Thanks

@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants