Skip to content

motion_blinds: Fix slow startup and interface detection on multi-NIC setups#169695

Draft
kvanbiesen wants to merge 2 commits intohome-assistant:devfrom
kvanbiesen:dev
Draft

motion_blinds: Fix slow startup and interface detection on multi-NIC setups#169695
kvanbiesen wants to merge 2 commits intohome-assistant:devfrom
kvanbiesen:dev

Conversation

@kvanbiesen
Copy link
Copy Markdown

Breaking change

Proposed change

Having multplece interfaces makes the motionsblinds intergration take up like 40 s

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

  • 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

  • [x ] I understand the code I am submitting and can explain how it works.
  • [x ] The code change is tested and works locally.
  • [ x] 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)
  • [ x] Tests have been added to verify that the new code works.
  • [x ] 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:

kvanbiesen added 2 commits May 3, 2026 18:16
Refactor tests for Motion Gateway interface detection, adding tests for dual and single NIC scenarios, interface timeout handling, and fallback mechanisms.
Copilot AI review requested due to automatic review settings May 3, 2026 16:20
@kvanbiesen kvanbiesen requested a review from starkillerOG as a code owner May 3, 2026 16:20
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

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

Hi @kvanbiesen

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 3, 2026

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 3, 2026

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

Code owner commands

Code owners of motion_blinds 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 motion_blinds 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 Motion Blinds integration’s gateway interface selection logic to reduce slow startup on hosts with multiple network interfaces, and adds tests intended to cover the new interface-detection behavior.

Changes:

  • Prioritizes the detected default NIC when building the candidate multicast interface list.
  • Adds a per-interface timeout while probing multicast support to avoid waiting on long socket timeouts.
  • Replaces the old gateway unit test file content with new tests for interface ordering and fallback behavior.

Reviewed changes

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

File Description
homeassistant/components/motion_blinds/gateway.py Changes interface discovery order and adds timeout-wrapped multicast interface probing.
tests/components/motion_blinds/test_gateway.py Replaces prior gateway tests with new interface-detection and timeout behavior tests.

Comment on lines +127 to 135
# Fail fast per interface instead of waiting for full socket timeout
try:
async with asyncio.timeout(5):
result = await self._hass.async_add_executor_job(self.check_interface)
except TimeoutError:
result = False

try:
check_multicast.Stop_listen()
import pytest

from motionblinds import DEVICE_TYPES_WIFI, BlindType
from homeassistant.components.motion_blindds.gateway import ConnectMotionGateway
Comment on lines +80 to +92
async def check_interface_side_effect():
nonlocal call_count
call_count += 1
# First interface times out, second succeeds
if call_count == 1:
await asyncio.sleep(10) # Will be cancelled by timeout
return True

with patch.object(
gateway,
"check_interface",
side_effect=check_interface_side_effect,
):

blind.device_type = DEVICE_TYPES_WIFI[0]
assert device_name(blind) == "RollerBlind"
async def test_get_interfaces_dual_nic_default_prioritized(hass):
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.

3 participants