python-izone 2.0.0__tar.gz → 2.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {python_izone-2.0.0 → python_izone-2.0.1}/PKG-INFO +1 -1
  2. python_izone-2.0.1/docs/release-notes/v2.0.1.md +17 -0
  3. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/controller.py +2 -1
  4. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/discovery.py +58 -4
  5. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/power.py +8 -3
  6. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/version.py +2 -2
  7. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_controller.py +4 -1
  8. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_discovery_api.py +189 -0
  9. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_hardware_hosts.py +30 -0
  10. {python_izone-2.0.0 → python_izone-2.0.1}/.gitattributes +0 -0
  11. {python_izone-2.0.0 → python_izone-2.0.1}/.github/workflows/main.yml +0 -0
  12. {python_izone-2.0.0 → python_izone-2.0.1}/.gitignore +0 -0
  13. {python_izone-2.0.0 → python_izone-2.0.1}/.pre-commit-config.yaml +0 -0
  14. {python_izone-2.0.0 → python_izone-2.0.1}/.python-version +0 -0
  15. {python_izone-2.0.0 → python_izone-2.0.1}/.vscode/.ropeproject/config.py +0 -0
  16. {python_izone-2.0.0 → python_izone-2.0.1}/.vscode/extensions.json +0 -0
  17. {python_izone-2.0.0 → python_izone-2.0.1}/.vscode/launch.json +0 -0
  18. {python_izone-2.0.0 → python_izone-2.0.1}/.vscode/settings.json +0 -0
  19. {python_izone-2.0.0 → python_izone-2.0.1}/README.md +0 -0
  20. {python_izone-2.0.0 → python_izone-2.0.1}/api_docs/AC-DOC-1401-11_iZoneEthernetInterface.pdf +0 -0
  21. {python_izone-2.0.0 → python_izone-2.0.1}/api_docs/iPower_JSON_datastrings_Out.h +0 -0
  22. {python_izone-2.0.0 → python_izone-2.0.1}/api_docs/iZone_JSON_datastrings.h +0 -0
  23. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.10.md +0 -0
  24. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.11.md +0 -0
  25. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.12.md +0 -0
  26. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.4.md +0 -0
  27. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.5.md +0 -0
  28. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.6.md +0 -0
  29. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.7.md +0 -0
  30. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.8.md +0 -0
  31. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v1.3.9.md +0 -0
  32. {python_izone-2.0.0 → python_izone-2.0.1}/docs/release-notes/v2.0.0.md +0 -0
  33. {python_izone-2.0.0 → python_izone-2.0.1}/docs/v2-confirmation.md +0 -0
  34. {python_izone-2.0.0 → python_izone-2.0.1}/licence.txt +0 -0
  35. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/__init__.py +0 -0
  36. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/const.py +0 -0
  37. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/exceptions.py +0 -0
  38. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/py.typed +0 -0
  39. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/types.py +0 -0
  40. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/v2.py +0 -0
  41. {python_izone-2.0.0 → python_izone-2.0.1}/pizone/zone.py +0 -0
  42. {python_izone-2.0.0 → python_izone-2.0.1}/pyproject.toml +0 -0
  43. {python_izone-2.0.0 → python_izone-2.0.1}/scripts/check +0 -0
  44. {python_izone-2.0.0 → python_izone-2.0.1}/scripts/coverage +0 -0
  45. {python_izone-2.0.0 → python_izone-2.0.1}/scripts/izone_v1_probe.py +0 -0
  46. {python_izone-2.0.0 → python_izone-2.0.1}/tests/__init__.py +0 -0
  47. {python_izone-2.0.0 → python_izone-2.0.1}/tests/conftest.py +0 -0
  48. {python_izone-2.0.0 → python_izone-2.0.1}/tests/http_fakes.py +0 -0
  49. {python_izone-2.0.0 → python_izone-2.0.1}/tests/power_data.py +0 -0
  50. {python_izone-2.0.0 → python_izone-2.0.1}/tests/resources.py +0 -0
  51. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_control_zone.py +0 -0
  52. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_discovery.py +0 -0
  53. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_discovery_close_timeout.py +0 -0
  54. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_dump_state.py +0 -0
  55. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_hardware_controller.py +0 -0
  56. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_http.py +0 -0
  57. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_power.py +0 -0
  58. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_v2.py +0 -0
  59. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_v2_confirmation.py +0 -0
  60. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_v2_fan_capability.py +0 -0
  61. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_v2_vendor_enums.py +0 -0
  62. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_v2_zone_validation.py +0 -0
  63. {python_izone-2.0.0 → python_izone-2.0.1}/tests/test_zone.py +0 -0
  64. {python_izone-2.0.0 → python_izone-2.0.1}/tests/v2_fixtures.py +0 -0
  65. {python_izone-2.0.0 → python_izone-2.0.1}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-izone
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: A python interface to the iZone airconditioner controller
5
5
  Project-URL: Homepage, https://github.com/Swamp-Ig/pizone
6
6
  Author-email: Penny Wood <pypl@ninjateaparty.com>
@@ -0,0 +1,17 @@
1
+ # Release notes — v2.0.1
2
+
3
+ **Compare range:** https://github.com/Swamp-Ig/pizone/compare/v2.0.0...v2.0.1
4
+
5
+ ## Since v2.0.0
6
+
7
+ ### Name re-resolved after a connection loss
8
+
9
+ - A controller created from a name with `create_controller(uid, "bridge.lan")` now remembers the name. When an HTTP refresh fails, the name is resolved again in the background, alongside the existing UDP scan.
10
+ - If the controller's UID answers at a new address, the controller is repointed and `on_address_changed` fires, the same as for a move found over UDP. This finds a bridge that changed address where UDP discovery can't reach it, such as on another VLAN.
11
+ - The check is cooled down per controller. It's skipped when the name still resolves to the current address, or when a UDP verify of that address is already in progress. Failures are logged at debug level only.
12
+ - Controllers created from an IP address are unchanged. No API changes.
13
+
14
+ ### Typing
15
+
16
+ - `DiscoveryService.discover_by_host()` is now annotated as always returning a `ControllerEndpoint`. It has raised `EndpointVerifyError` instead of returning `None` since v2.0.0. Callers can drop their `None` handling.
17
+ - `PowerGroup.group_number` returns the number the group was built from, instead of falling back to `-1`, which would also have reported a group 0 as `-1`. `PowerGroup` now takes the group number as a constructor argument; it's built only by `Power`.
@@ -211,10 +211,11 @@ class Controller:
211
211
  self._set_bridge_ok(True)
212
212
 
213
213
  def _nudge_scan(self) -> None:
214
- """Non-blocking cooled-down IASD scan after HTTP transport failure."""
214
+ """Non-blocking cooled-down rediscovery after HTTP transport failure."""
215
215
  if self._closed:
216
216
  return
217
217
  self._discovery_service.schedule_cooled_scan()
218
+ self._discovery_service.schedule_name_check(self._device_uid)
218
219
 
219
220
  @classmethod
220
221
  async def create(
@@ -119,6 +119,15 @@ _FAILURE_RANK = {
119
119
  type _VerifyResult = ControllerEndpoint | UnverifiedEndpoint | None
120
120
 
121
121
 
122
+ def _is_ipv4(host: str) -> bool:
123
+ """Return whether *host* is an IPv4 address rather than a name."""
124
+ try:
125
+ IPv4Address(host)
126
+ except ValueError:
127
+ return False
128
+ return True
129
+
130
+
122
131
  @dataclass(slots=True)
123
132
  class _Entry:
124
133
  state: _State
@@ -128,6 +137,10 @@ class _Entry:
128
137
  # for KNOWN/CLAIMED a move that applies only once it answers.
129
138
  candidate: ControllerEndpoint | None = None
130
139
  verify: Task[_VerifyResult] | None = None
140
+ # CLAIMED only: the name the controller was created from, re-resolved
141
+ # after a transport failure since UDP discovery may not reach the bridge.
142
+ host_name: str | None = None
143
+ last_name_check: float = float("-inf")
131
144
 
132
145
 
133
146
  class DiscoveryService:
@@ -295,6 +308,43 @@ class DiscoveryService:
295
308
 
296
309
  asyncio.get_running_loop().create_task(_run())
297
310
 
311
+ def schedule_name_check(self, uid: str) -> None:
312
+ """Re-resolve a claimed controller's name in the background, if it has one.
313
+
314
+ Repoints the controller when its UID answers at a new address. Cooled
315
+ down per UID.
316
+ """
317
+ if self.is_closed:
318
+ return
319
+ entry = self._entry(uid, _State.CLAIMED)
320
+ if entry is None or (name := entry.host_name) is None:
321
+ return
322
+ now = asyncio.get_running_loop().time()
323
+ if now - entry.last_name_check < RESCAN_COOLDOWN:
324
+ return
325
+ entry.last_name_check = now
326
+
327
+ async def _run() -> None:
328
+ try:
329
+ addresses = await self._resolve(name)
330
+ if entry.endpoint.host in addresses:
331
+ return
332
+ if entry.candidate is not None and entry.candidate.host in addresses:
333
+ return # A UDP verify of that address is already in flight.
334
+ probed = await self._probe_first(addresses, expected_uid=uid)
335
+ if isinstance(probed, _ProbeFailed):
336
+ _LOG.debug(
337
+ "Name %s for %s did not verify: %s", name, uid, probed.failure
338
+ )
339
+ return
340
+ if self.is_closed or self._endpoints.get(uid) is not entry:
341
+ return
342
+ self._apply_verified(probed.endpoint)
343
+ except Exception: # noqa: BLE001
344
+ _LOG.debug("Name check for %s failed", uid, exc_info=True)
345
+
346
+ self.create_task(_run())
347
+
298
348
  def _entry(self, uid: str, *states: _State) -> _Entry | None:
299
349
  """Return the entry for *uid* when it is in one of *states*."""
300
350
  entry = self._endpoints.get(uid)
@@ -429,7 +479,7 @@ class DiscoveryService:
429
479
  if self._discover_all_notified is not None:
430
480
  self._discover_all_notified.add(endpoint.uid)
431
481
 
432
- async def discover_by_host(self, host: str) -> ControllerEndpoint | None:
482
+ async def discover_by_host(self, host: str) -> ControllerEndpoint:
433
483
  """Return the controller endpoint at *host*, an IPv4 address or a name.
434
484
 
435
485
  A name is resolved to IPv4 addresses first; the returned endpoint always
@@ -604,9 +654,10 @@ class DiscoveryService:
604
654
 
605
655
  Preferred entry point after :func:`create_discovery`. One-shot per
606
656
  UID. *host* may be an IPv4 address or a name; a name is resolved and
607
- the controller runs on the IP that answers. HTTP probe is the trust
608
- boundary; callers must handle the device being unreachable even after a
609
- recent discovery notify.
657
+ the controller runs on the IP that answers. The name is resolved again
658
+ after a transport failure, in case the bridge moved. HTTP probe is the
659
+ trust boundary; callers must handle the device being unreachable even
660
+ after a recent discovery notify.
610
661
 
611
662
  Raises:
612
663
  UnpairedBridgeError: If *uid* is the unpaired placeholder (no I/O).
@@ -657,6 +708,9 @@ class DiscoveryService:
657
708
  del self._endpoints[uid]
658
709
  raise
659
710
 
711
+ if not _is_ipv4(host) and (claimed := self._entry(uid, _State.CLAIMED)):
712
+ claimed.host_name = host
713
+
660
714
  if pending_address_changed is not None and on_address_changed is not None:
661
715
  self.schedule_address_changed(on_address_changed, pending_address_changed)
662
716
  return controller
@@ -148,8 +148,11 @@ class PowerDevice:
148
148
  class PowerGroup:
149
149
  """Grouped power channels."""
150
150
 
151
- def __init__(self, power: Power, channels: Iterable[PowerChannel]) -> None:
151
+ def __init__(
152
+ self, power: Power, group_number: int, channels: Iterable[PowerChannel]
153
+ ) -> None:
152
154
  self._power = power
155
+ self._group_number = group_number
153
156
  self._channels = tuple(channels)
154
157
  devices: set[PowerDevice] = set()
155
158
  for chan in channels:
@@ -159,7 +162,7 @@ class PowerGroup:
159
162
  @property
160
163
  def group_number(self) -> int:
161
164
  """The group id."""
162
- return self._channels[0].group_number or -1
165
+ return self._group_number
163
166
 
164
167
  @property
165
168
  def name(self) -> str:
@@ -218,7 +221,9 @@ class Power:
218
221
  for chan in dev.channels:
219
222
  if chan.group_number is not None:
220
223
  gdict.setdefault(chan.group_number, []).append(chan)
221
- self._groups = tuple(PowerGroup(self, gl) for gl in gdict.values())
224
+ self._groups = tuple(
225
+ PowerGroup(self, number, chans) for number, chans in gdict.items()
226
+ )
222
227
 
223
228
  async def refresh(self) -> bool:
224
229
  """Refresh power usage data from the device.
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.0.0'
22
- __version_tuple__ = version_tuple = (2, 0, 0)
21
+ __version__ = version = '2.0.1'
22
+ __version_tuple__ = version_tuple = (2, 0, 1)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -5,7 +5,7 @@ from collections.abc import Awaitable, Callable
5
5
  from copy import deepcopy
6
6
  import logging
7
7
  from typing import cast
8
- from unittest.mock import AsyncMock
8
+ from unittest.mock import AsyncMock, Mock
9
9
 
10
10
  import pytest
11
11
 
@@ -733,12 +733,15 @@ async def test_refresh_transport_failure_nudges_scan() -> None:
733
733
  controller._connected = False
734
734
  scan = AsyncMock()
735
735
  service.scan = scan # type: ignore[method-assign]
736
+ name_check = Mock()
737
+ service.schedule_name_check = name_check # type: ignore[method-assign]
736
738
 
737
739
  with pytest.raises(ConnectionError):
738
740
  await controller.refresh_all()
739
741
 
740
742
  await asyncio.sleep(0)
741
743
  scan.assert_awaited_once()
744
+ name_check.assert_called_once_with("000000001")
742
745
  assert controller.bridge_connected is False
743
746
  await service.close()
744
747
 
@@ -1778,6 +1778,195 @@ async def test_create_controller_resolves_name_to_ip() -> None:
1778
1778
  await service.close()
1779
1779
 
1780
1780
 
1781
+ async def _probe_expected(
1782
+ host: str, *, expected_uid: str | None = None
1783
+ ) -> ControllerProbe | _ProbeFailed:
1784
+ """Answer as *expected_uid* at any host."""
1785
+ assert expected_uid is not None
1786
+ return _probe_result(expected_uid, host)
1787
+
1788
+
1789
+ async def _create_at(
1790
+ service: DiscoveryService,
1791
+ uid: str,
1792
+ host: str,
1793
+ *,
1794
+ resolves_to: str,
1795
+ on_address_changed: list[ControllerEndpoint] | None = None,
1796
+ ) -> Controller:
1797
+ """Create a controller from *host*, which resolves to *resolves_to*."""
1798
+ with (
1799
+ patch.object(service, "_resolve", AsyncMock(return_value=[resolves_to])),
1800
+ patch.object(service, "_probe", side_effect=_probe_expected),
1801
+ patch.object(MockController, "_initialize", AsyncMock()),
1802
+ ):
1803
+ return await service.create_controller(
1804
+ uid,
1805
+ host,
1806
+ on_address_changed=(
1807
+ on_address_changed.append if on_address_changed is not None else None
1808
+ ),
1809
+ )
1810
+
1811
+
1812
+ async def _settle_tasks(service: DiscoveryService) -> None:
1813
+ await asyncio.gather(*(task for task in service._tasks if not task.done()))
1814
+ await asyncio.sleep(0)
1815
+
1816
+
1817
+ @pytest.mark.asyncio
1818
+ async def test_name_check_repoints_moved_controller() -> None:
1819
+ """A name that now resolves to another IP repoints the controller there."""
1820
+ service = MockDiscoveryService()
1821
+ seen: list[ControllerEndpoint] = []
1822
+ controller = await _create_at(
1823
+ service,
1824
+ "000025841",
1825
+ "izone.lan",
1826
+ resolves_to="10.0.0.90",
1827
+ on_address_changed=seen,
1828
+ )
1829
+ moved = ControllerEndpoint(uid="000025841", host="10.0.0.91")
1830
+
1831
+ with (
1832
+ patch.object(service, "_resolve", AsyncMock(return_value=[moved.host])),
1833
+ patch.object(service, "_probe", side_effect=_probe_expected),
1834
+ ):
1835
+ service.schedule_name_check(moved.uid)
1836
+ await _settle_tasks(service)
1837
+
1838
+ assert controller.device_ip == moved.host
1839
+ assert service._endpoints_in(_State.CLAIMED) == {moved.uid: moved}
1840
+ assert seen == [moved]
1841
+ await service.close()
1842
+
1843
+
1844
+ @pytest.mark.asyncio
1845
+ async def test_name_check_current_ip_skips_probe() -> None:
1846
+ """When the name still resolves to the current IP, the bridge is just down."""
1847
+ service = MockDiscoveryService()
1848
+ controller = await _create_at(
1849
+ service, "000025841", "izone.lan", resolves_to="10.0.0.90"
1850
+ )
1851
+ probe = AsyncMock()
1852
+
1853
+ with (
1854
+ patch.object(service, "_resolve", AsyncMock(return_value=["10.0.0.90"])),
1855
+ patch.object(service, "_probe", probe),
1856
+ ):
1857
+ service.schedule_name_check("000025841")
1858
+ await _settle_tasks(service)
1859
+
1860
+ probe.assert_not_awaited()
1861
+ assert controller.device_ip == "10.0.0.90"
1862
+ await service.close()
1863
+
1864
+
1865
+ @pytest.mark.asyncio
1866
+ async def test_name_check_defers_to_udp_verify_in_flight() -> None:
1867
+ """A UDP verify already checking the resolved address isn't probed again."""
1868
+ service = MockDiscoveryService()
1869
+ await _create_at(service, "000025841", "izone.lan", resolves_to="10.0.0.90")
1870
+ service._endpoints["000025841"].candidate = ControllerEndpoint(
1871
+ uid="000025841", host="10.0.0.91"
1872
+ )
1873
+ probe = AsyncMock()
1874
+
1875
+ with (
1876
+ patch.object(service, "_resolve", AsyncMock(return_value=["10.0.0.91"])),
1877
+ patch.object(service, "_probe", probe),
1878
+ ):
1879
+ service.schedule_name_check("000025841")
1880
+ await _settle_tasks(service)
1881
+
1882
+ probe.assert_not_awaited()
1883
+ await service.close()
1884
+
1885
+
1886
+ @pytest.mark.asyncio
1887
+ async def test_name_check_other_uid_does_not_repoint() -> None:
1888
+ """A different controller answering at the new address is ignored."""
1889
+ service = MockDiscoveryService()
1890
+ seen: list[ControllerEndpoint] = []
1891
+ controller = await _create_at(
1892
+ service,
1893
+ "000025841",
1894
+ "izone.lan",
1895
+ resolves_to="10.0.0.90",
1896
+ on_address_changed=seen,
1897
+ )
1898
+
1899
+ with (
1900
+ patch.object(service, "_resolve", AsyncMock(return_value=["10.0.0.91"])),
1901
+ patch.object(
1902
+ service,
1903
+ "_probe",
1904
+ AsyncMock(return_value=_ProbeFailed(VerifyFailure.OTHER_UID, "000099999")),
1905
+ ),
1906
+ ):
1907
+ service.schedule_name_check("000025841")
1908
+ await _settle_tasks(service)
1909
+
1910
+ assert controller.device_ip == "10.0.0.90"
1911
+ assert seen == []
1912
+ await service.close()
1913
+
1914
+
1915
+ @pytest.mark.asyncio
1916
+ async def test_name_check_skips_ip_literal() -> None:
1917
+ """A controller created from an IPv4 address has no name to re-resolve."""
1918
+ service = MockDiscoveryService()
1919
+ await _create_at(service, "000025841", "10.0.0.90", resolves_to="10.0.0.90")
1920
+ resolve = AsyncMock()
1921
+
1922
+ with patch.object(service, "_resolve", resolve):
1923
+ service.schedule_name_check("000025841")
1924
+ await _settle_tasks(service)
1925
+
1926
+ resolve.assert_not_awaited()
1927
+ await service.close()
1928
+
1929
+
1930
+ @pytest.mark.asyncio
1931
+ async def test_name_check_cooldown_is_per_controller() -> None:
1932
+ """A second check inside the cooldown is skipped, without blocking others."""
1933
+ service = MockDiscoveryService()
1934
+ await _create_at(service, "000025841", "first.lan", resolves_to="10.0.0.90")
1935
+ await _create_at(service, "000025842", "second.lan", resolves_to="10.0.0.92")
1936
+ resolve = AsyncMock(return_value=[])
1937
+
1938
+ with patch.object(service, "_resolve", resolve):
1939
+ service.schedule_name_check("000025841")
1940
+ service.schedule_name_check("000025841")
1941
+ service.schedule_name_check("000025842")
1942
+ await _settle_tasks(service)
1943
+
1944
+ assert [call.args for call in resolve.await_args_list] == [
1945
+ ("first.lan",),
1946
+ ("second.lan",),
1947
+ ]
1948
+ await service.close()
1949
+
1950
+
1951
+ @pytest.mark.asyncio
1952
+ async def test_name_check_skips_closed_controller() -> None:
1953
+ """Closing a controller drops its name with the claim."""
1954
+ service = MockDiscoveryService()
1955
+ controller = await _create_at(
1956
+ service, "000025841", "izone.lan", resolves_to="10.0.0.90"
1957
+ )
1958
+ await controller.close()
1959
+ resolve = AsyncMock()
1960
+
1961
+ with patch.object(service, "_resolve", resolve):
1962
+ service.schedule_name_check("000025841")
1963
+ await _settle_tasks(service)
1964
+
1965
+ resolve.assert_not_awaited()
1966
+ assert service._endpoints["000025841"].host_name is None
1967
+ await service.close()
1968
+
1969
+
1781
1970
  @pytest.mark.asyncio
1782
1971
  async def test_create_controller_unresolvable_name_falls_back_to_scan() -> None:
1783
1972
  service = MockDiscoveryService()
@@ -159,3 +159,33 @@ async def test_passive_reply_from_same_ip_is_not_a_move(
159
159
  assert live_service._endpoints[bridge.uid].verify is None
160
160
  assert controller.device_ip == bridge.host
161
161
  assert seen == []
162
+
163
+
164
+ @pytest.mark.hardware
165
+ async def test_name_re_resolve_repoints_moved_controller(
166
+ live_service: DiscoveryService, bridge: ControllerEndpoint
167
+ ) -> None:
168
+ """A refresh failure re-resolves the name and finds the bridge again."""
169
+ seen: list[ControllerEndpoint] = []
170
+ with _name_resolves_to(bridge.host):
171
+ controller = await live_service.create_controller(
172
+ bridge.uid, BRIDGE_NAME, on_address_changed=seen.append
173
+ )
174
+ # Simulate the bridge having moved while UDP was blocked.
175
+ controller._ip = WRONG_HOST
176
+ live_service._endpoints[bridge.uid].endpoint = ControllerEndpoint(
177
+ uid=bridge.uid, host=WRONG_HOST
178
+ )
179
+
180
+ # Only the name check may find it, not a UDP scan.
181
+ with patch.object(live_service, "schedule_cooled_scan"):
182
+ with pytest.raises(ConnectionError):
183
+ await controller.refresh_all()
184
+ async with asyncio.timeout(Controller.REQUEST_TIMEOUT * 2):
185
+ while controller.device_ip != bridge.host:
186
+ await asyncio.sleep(0.05)
187
+ await asyncio.sleep(0)
188
+
189
+ assert seen == [bridge]
190
+ await controller.refresh_all()
191
+ assert controller.connected
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes