Skip to content

Fix MotionMount zeroconf overwriting manually configured static IP#168627

Open
MohamedBarrak3 wants to merge 2 commits intohome-assistant:devfrom
MohamedBarrak3:fix/motionmount-preserve-static-ip
Open

Fix MotionMount zeroconf overwriting manually configured static IP#168627
MohamedBarrak3 wants to merge 2 commits intohome-assistant:devfrom
MohamedBarrak3:fix/motionmount-preserve-static-ip

Conversation

@MohamedBarrak3
Copy link
Copy Markdown

Breaking change

Proposed change

When a MotionMount is configured with a static IP address, zeroconf discovery
after a restart overwrites the stored host with the mDNS hostname
(e.g., MM3F9593.local). If the network does not resolve .local addresses
(e.g., custom local domain like .localdomain), the integration fails to
connect after every restart.
This PR fixes the issue by checking if the existing config entry has a
non-mDNS host (not ending in .local). If so, the host is not updated
during zeroconf discovery, preserving the manually configured static IP.

Type of change

  • Dependency upgrade
  • [x ] Bugfix (non-breaking change which fixes an issue)
  • 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

Checklist

  • [ x] I understand the code I am submitting and can explain how it works.
  • [ x] The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • [ x] 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)
  • [ x] Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings April 20, 2026 14:33
@home-assistant
Copy link
Copy Markdown

Hey there @laiho-vogels, mind taking a look at this pull request as it has been labeled with an integration (motionmount) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of motionmount 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 motionmount 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 addresses a MotionMount config flow issue where zeroconf rediscovery updates an existing config entry’s host to an mDNS hostname, breaking setups that rely on a manually configured static IP.

Changes:

  • Update MotionMount zeroconf flow to avoid overwriting the existing entry’s host when it appears to be manually configured (non-.local).
  • Add a regression test ensuring zeroconf does not overwrite a manually configured static IP.

Reviewed changes

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

File Description
homeassistant/components/motionmount/config_flow.py Adjusts zeroconf-driven config entry updates to preserve an existing “static” host.
tests/components/motionmount/test_config_flow.py Adds a test covering the “don’t overwrite static IP” behavior.

host_updates = {CONF_HOST: host, CONF_PORT: port}
else:
host_updates = {CONF_PORT: port}
self.connection_data[CONF_HOST] = existing_host
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Remove the self.connection_data[CONF_HOST] = existing_host assignment (this branch only runs when an entry with the same unique_id already exists and the flow immediately aborts, so mutating connection_data here is misleading and has no effect).

Suggested change
self.connection_data[CONF_HOST] = existing_host

Copilot uses AI. Check for mistakes.
Comment on lines +142 to +152
existing_entry = self._async_current_entries()
existing_host = next(
(e.data.get(CONF_HOST, "") for e in existing_entry if e.unique_id == unique_id),
"",
)
host_updates = (
{CONF_HOST: host, CONF_PORT: port}
if not existing_host or existing_host.endswith(".local")
else {CONF_PORT: port}
)
self._abort_if_unique_id_configured(updates=host_updates)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Apply the same mDNS-suffix normalization here as well (e.g., handle .local. with a trailing dot and case-insensitivity) so existing mDNS hosts aren’t misclassified as “static” and skipped for updates unintentionally.

Copilot uses AI. Check for mistakes.
(e.data.get(CONF_HOST, "") for e in existing_entry if e.unique_id == unique_id),
"",
)
if not existing_host or existing_host.endswith(".local"):
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Normalize the hostname before checking for an mDNS .local suffix (zeroconf hostnames in this integration include a trailing dot, e.g. MMF8A55F.local., so endswith(".local") will not match and may incorrectly treat an mDNS host as “static”).

Suggested change
if not existing_host or existing_host.endswith(".local"):
if not existing_host or existing_host.removesuffix(".").endswith(".local"):

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration: MotionMount overwrites manual IP with unreachable mDNS hostname after restart

2 participants