motion_blinds: Fix slow startup and interface detection on multi-NIC setups#169695
motion_blinds: Fix slow startup and interface detection on multi-NIC setups#169695kvanbiesen wants to merge 2 commits intohome-assistant:devfrom
Conversation
Refactor tests for Motion Gateway interface detection, adding tests for dual and single NIC scenarios, interface timeout handling, and fallback mechanisms.
There was a problem hiding this comment.
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!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @starkillerOG, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
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. |
| # 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 |
| 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): |
Breaking change
Proposed change
Having multplece interfaces makes the motionsblinds intergration take up like 40 s
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: