python-duco-connectivity 0.17.0__tar.gz → 0.19.0__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 (26) hide show
  1. {python_duco_connectivity-0.17.0/src/python_duco_connectivity.egg-info → python_duco_connectivity-0.19.0}/PKG-INFO +12 -4
  2. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/README.md +11 -3
  3. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/pyproject.toml +1 -1
  4. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/duco_connectivity/client.py +100 -7
  5. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0/src/python_duco_connectivity.egg-info}/PKG-INFO +12 -4
  6. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_client.py +162 -0
  7. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/LICENSE +0 -0
  8. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/setup.cfg +0 -0
  9. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/duco_connectivity/__init__.py +0 -0
  10. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/duco_connectivity/__main__.py +0 -0
  11. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/duco_connectivity/cli.py +0 -0
  12. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/duco_connectivity/exceptions.py +0 -0
  13. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/duco_connectivity/models.py +0 -0
  14. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/duco_connectivity/py.typed +0 -0
  15. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/python_duco_connectivity.egg-info/SOURCES.txt +0 -0
  16. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/python_duco_connectivity.egg-info/dependency_links.txt +0 -0
  17. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/python_duco_connectivity.egg-info/entry_points.txt +0 -0
  18. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/python_duco_connectivity.egg-info/requires.txt +0 -0
  19. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/src/python_duco_connectivity.egg-info/top_level.txt +0 -0
  20. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_api_reference.py +0 -0
  21. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_cli.py +0 -0
  22. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_exceptions.py +0 -0
  23. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_local_sample_validation.py +0 -0
  24. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_models.py +0 -0
  25. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_pytest_live_support.py +0 -0
  26. {python_duco_connectivity-0.17.0 → python_duco_connectivity-0.19.0}/tests/test_replay_helpers.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-duco-connectivity
3
- Version: 0.17.0
3
+ Version: 0.19.0
4
4
  Summary: Async HTTP client for the local Duco Connectivity API
5
5
  Author: Ronald van der Meer
6
6
  License-Expression: MIT
@@ -73,9 +73,9 @@ in the development examples below.
73
73
  ## Error handling
74
74
 
75
75
  Discovery-style helpers use their natural empty result when a Duco box reports
76
- an optional capability as unsupported: filter time returns `None`, ventilation
77
- temperatures return an empty `VentilationTemperatureInfo`, and bulk bypass
78
- targets return `{}`. Malformed responses and operational failures remain
76
+ an optional capability as unsupported: filter time and the write budget return
77
+ `None`, ventilation temperatures return an empty `VentilationTemperatureInfo`,
78
+ and bulk bypass targets return `{}`. Malformed responses and operational failures remain
79
79
  exceptions. The strict parameter-specific bypass helper raises
80
80
  `DucoUnsupportedCapabilityError` for an unsupported target; this
81
81
  `DucoResponseError` subclass preserves the HTTP status, path, and response body.
@@ -109,6 +109,14 @@ Wi-Fi access point key.
109
109
  action with an explicit Boolean state. The helper raises `DucoActionError` when
110
110
  the box returns an unsuccessful action result.
111
111
 
112
+ `async_set_node_identify_timed(node_id)` turns identification on and returns
113
+ after the write succeeds. The client turns it off after 15 minutes using the
114
+ running event loop. Calling the method again for the same node restarts the
115
+ 15-minute period; nodes are tracked independently. An explicit
116
+ `async_set_node_identify()` call cancels the managed timeout for that node.
117
+ Failed automatic off-writes are logged and retried when a later API request is made.
118
+ Because the timer is in process, it does not survive application restarts.
119
+
112
120
  ## Getting started
113
121
 
114
122
  ```python
@@ -41,9 +41,9 @@ in the development examples below.
41
41
  ## Error handling
42
42
 
43
43
  Discovery-style helpers use their natural empty result when a Duco box reports
44
- an optional capability as unsupported: filter time returns `None`, ventilation
45
- temperatures return an empty `VentilationTemperatureInfo`, and bulk bypass
46
- targets return `{}`. Malformed responses and operational failures remain
44
+ an optional capability as unsupported: filter time and the write budget return
45
+ `None`, ventilation temperatures return an empty `VentilationTemperatureInfo`,
46
+ and bulk bypass targets return `{}`. Malformed responses and operational failures remain
47
47
  exceptions. The strict parameter-specific bypass helper raises
48
48
  `DucoUnsupportedCapabilityError` for an unsupported target; this
49
49
  `DucoResponseError` subclass preserves the HTTP status, path, and response body.
@@ -77,6 +77,14 @@ Wi-Fi access point key.
77
77
  action with an explicit Boolean state. The helper raises `DucoActionError` when
78
78
  the box returns an unsuccessful action result.
79
79
 
80
+ `async_set_node_identify_timed(node_id)` turns identification on and returns
81
+ after the write succeeds. The client turns it off after 15 minutes using the
82
+ running event loop. Calling the method again for the same node restarts the
83
+ 15-minute period; nodes are tracked independently. An explicit
84
+ `async_set_node_identify()` call cancels the managed timeout for that node.
85
+ Failed automatic off-writes are logged and retried when a later API request is made.
86
+ Because the timer is in process, it does not survive application restarts.
87
+
80
88
  ## Getting started
81
89
 
82
90
  ```python
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-duco-connectivity"
7
- version = "0.17.0"
7
+ version = "0.19.0"
8
8
  description = "Async HTTP client for the local Duco Connectivity API"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,5 +1,6 @@
1
1
  """Async client for the local Duco HTTP API."""
2
2
 
3
+ import asyncio
3
4
  import json
4
5
  import logging
5
6
  import math
@@ -96,6 +97,8 @@ from .models import (
96
97
 
97
98
  _LOGGER = logging.getLogger(__name__)
98
99
 
100
+ _NODE_IDENTIFY_DURATION = 15 * 60
101
+
99
102
 
100
103
  def _compat_caller() -> str | None:
101
104
  """Return the first external caller that reached a compatibility path."""
@@ -140,6 +143,11 @@ class DucoClient:
140
143
  ) -> None:
141
144
  self._session = session
142
145
  self._timeout = aiohttp.ClientTimeout(total=request_timeout)
146
+ self._identify_deadlines: dict[int, float] = {}
147
+ self._identify_timers: dict[int, asyncio.TimerHandle] = {}
148
+ self._identify_locks: dict[int, asyncio.Lock] = {}
149
+ self._identify_cleanup_nodes: set[int] = set()
150
+ self._identify_cleanup_tasks: set[asyncio.Task[None]] = set()
143
151
 
144
152
  raw_host = host.rstrip("/")
145
153
  authority = raw_host.split("://", 1)[1] if "://" in raw_host else raw_host
@@ -228,6 +236,8 @@ class DucoClient:
228
236
  return parsed_path.path
229
237
 
230
238
  async def _request_json(self, method: str, path: str, **kwargs: Any) -> Any:
239
+ self._schedule_expired_node_identify_cleanup()
240
+
231
241
  allow_empty_response = kwargs.pop("allow_empty_response", False)
232
242
  json_payload = None
233
243
  if "json" in kwargs:
@@ -2288,12 +2298,17 @@ class DucoClient:
2288
2298
 
2289
2299
  return self._parse_node(payload)
2290
2300
 
2291
- async def async_get_write_requests_remaining(self) -> int:
2292
- """Return the remaining write budget reported by the box."""
2293
- payload = await self.async_get_info(
2294
- module="General",
2295
- submodule="PublicApi",
2296
- )
2301
+ async def async_get_write_requests_remaining(self) -> int | None:
2302
+ """Return the remaining write budget, or None if the box does not support it."""
2303
+ try:
2304
+ payload = await self.async_get_info(
2305
+ module="General",
2306
+ submodule="PublicApi",
2307
+ )
2308
+ except DucoResponseError as err:
2309
+ if _is_unsupported_optional_endpoint_error(err, "/info"):
2310
+ return None
2311
+ raise
2297
2312
  return int(self._read_wrapped_value(payload["General"]["PublicApi"], "WriteReqCntRemain"))
2298
2313
 
2299
2314
  async def async_get_time_filter_remaining(self) -> int | None:
@@ -2460,7 +2475,7 @@ class DucoClient:
2460
2475
  raise DucoError(msg)
2461
2476
  return updated_target
2462
2477
 
2463
- async def async_get_write_req_remaining(self) -> int:
2478
+ async def async_get_write_req_remaining(self) -> int | None:
2464
2479
  """Backward-compatible alias for the old write budget method name."""
2465
2480
  caller = _compat_caller()
2466
2481
  if caller is None:
@@ -2506,6 +2521,27 @@ class DucoClient:
2506
2521
 
2507
2522
  async def async_set_node_identify(self, node_id: int, identify: bool) -> None:
2508
2523
  """Set the identify state for a node."""
2524
+ async with self._identify_locks.setdefault(node_id, asyncio.Lock()):
2525
+ await self._async_set_node_identify_value(node_id, identify)
2526
+ self._cancel_node_identify_timer(node_id)
2527
+
2528
+ async def async_set_node_identify_timed(self, node_id: int) -> None:
2529
+ """Start node identification for 15 minutes."""
2530
+ async with self._identify_locks.setdefault(node_id, asyncio.Lock()):
2531
+ await self._async_set_node_identify_value(node_id, True)
2532
+ self._cancel_node_identify_timer(node_id)
2533
+
2534
+ loop = asyncio.get_running_loop()
2535
+ deadline = loop.time() + _NODE_IDENTIFY_DURATION
2536
+ self._identify_deadlines[node_id] = deadline
2537
+ self._identify_timers[node_id] = loop.call_at(
2538
+ deadline,
2539
+ self._start_node_identify_cleanup,
2540
+ node_id,
2541
+ deadline,
2542
+ )
2543
+
2544
+ async def _async_set_node_identify_value(self, node_id: int, identify: bool) -> None:
2509
2545
  action = KnownActionName.SET_IDENTIFY
2510
2546
  result = await self.async_set_node_action(
2511
2547
  node_id=node_id,
@@ -2520,6 +2556,63 @@ class DucoClient:
2520
2556
  message=result.message,
2521
2557
  )
2522
2558
 
2559
+ def _cancel_node_identify_timer(self, node_id: int) -> None:
2560
+ """Cancel managed identify expiry for a node."""
2561
+ self._identify_deadlines.pop(node_id, None)
2562
+ if timer := self._identify_timers.pop(node_id, None):
2563
+ timer.cancel()
2564
+
2565
+ def _start_node_identify_cleanup(self, node_id: int, deadline: float) -> None:
2566
+ """Start asynchronous cleanup when a node identify deadline expires."""
2567
+ if (
2568
+ self._identify_deadlines.get(node_id) != deadline
2569
+ or node_id in self._identify_cleanup_nodes
2570
+ ):
2571
+ return
2572
+
2573
+ self._identify_cleanup_nodes.add(node_id)
2574
+ if timer := self._identify_timers.pop(node_id, None):
2575
+ timer.cancel()
2576
+ task = asyncio.create_task(self._async_disable_expired_node_identify(node_id, deadline))
2577
+ self._identify_cleanup_tasks.add(task)
2578
+ task.add_done_callback(self._identify_cleanup_tasks.discard)
2579
+
2580
+ def _schedule_expired_node_identify_cleanup(self) -> None:
2581
+ """Schedule overdue identify cleanup before another API request."""
2582
+ now = asyncio.get_running_loop().time()
2583
+ for node_id, deadline in tuple(self._identify_deadlines.items()):
2584
+ if deadline > now or node_id in self._identify_cleanup_nodes:
2585
+ continue
2586
+ self._start_node_identify_cleanup(node_id, deadline)
2587
+
2588
+ async def _async_disable_expired_node_identify(self, node_id: int, deadline: float) -> None:
2589
+ """Disable an identify state if its deadline is still current."""
2590
+ try:
2591
+ async with self._identify_locks.setdefault(node_id, asyncio.Lock()):
2592
+ if self._identify_deadlines.get(node_id) != deadline:
2593
+ return
2594
+ loop = asyncio.get_running_loop()
2595
+ if deadline > loop.time():
2596
+ self._identify_timers[node_id] = loop.call_at(
2597
+ deadline,
2598
+ self._start_node_identify_cleanup,
2599
+ node_id,
2600
+ deadline,
2601
+ )
2602
+ return
2603
+ try:
2604
+ await self._async_set_node_identify_value(node_id, False)
2605
+ except Exception as err:
2606
+ _LOGGER.warning(
2607
+ "Failed to disable identify for node %s after 15 minutes: %s",
2608
+ node_id,
2609
+ err,
2610
+ )
2611
+ return
2612
+ self._identify_deadlines.pop(node_id, None)
2613
+ finally:
2614
+ self._identify_cleanup_nodes.discard(node_id)
2615
+
2523
2616
  async def async_set_node_action(
2524
2617
  self,
2525
2618
  node_id: int,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-duco-connectivity
3
- Version: 0.17.0
3
+ Version: 0.19.0
4
4
  Summary: Async HTTP client for the local Duco Connectivity API
5
5
  Author: Ronald van der Meer
6
6
  License-Expression: MIT
@@ -73,9 +73,9 @@ in the development examples below.
73
73
  ## Error handling
74
74
 
75
75
  Discovery-style helpers use their natural empty result when a Duco box reports
76
- an optional capability as unsupported: filter time returns `None`, ventilation
77
- temperatures return an empty `VentilationTemperatureInfo`, and bulk bypass
78
- targets return `{}`. Malformed responses and operational failures remain
76
+ an optional capability as unsupported: filter time and the write budget return
77
+ `None`, ventilation temperatures return an empty `VentilationTemperatureInfo`,
78
+ and bulk bypass targets return `{}`. Malformed responses and operational failures remain
79
79
  exceptions. The strict parameter-specific bypass helper raises
80
80
  `DucoUnsupportedCapabilityError` for an unsupported target; this
81
81
  `DucoResponseError` subclass preserves the HTTP status, path, and response body.
@@ -109,6 +109,14 @@ Wi-Fi access point key.
109
109
  action with an explicit Boolean state. The helper raises `DucoActionError` when
110
110
  the box returns an unsuccessful action result.
111
111
 
112
+ `async_set_node_identify_timed(node_id)` turns identification on and returns
113
+ after the write succeeds. The client turns it off after 15 minutes using the
114
+ running event loop. Calling the method again for the same node restarts the
115
+ 15-minute period; nodes are tracked independently. An explicit
116
+ `async_set_node_identify()` call cancels the managed timeout for that node.
117
+ Failed automatic off-writes are logged and retried when a later API request is made.
118
+ Because the timer is in process, it does not survive application restarts.
119
+
112
120
  ## Getting started
113
121
 
114
122
  ```python
@@ -1,5 +1,6 @@
1
1
  """Tests for the HTTP-only Duco connectivity client."""
2
2
 
3
+ import asyncio
3
4
  import logging
4
5
  import re
5
6
  from dataclasses import dataclass, field
@@ -4293,6 +4294,31 @@ async def test_get_write_requests_remaining_is_parsed() -> None:
4293
4294
  assert remaining == 197
4294
4295
 
4295
4296
 
4297
+ async def test_get_write_requests_remaining_returns_none_when_unsupported() -> None:
4298
+ """An unsupported write budget should not be reported as exhausted."""
4299
+ mock_response = _response(status=400, text_payload='{"Code":3,"Result":"FAILED"}')
4300
+
4301
+ async with aiohttp.ClientSession() as session:
4302
+ client = DucoClient(session=session, host="192.0.2.94")
4303
+ with patch.object(session, "request", _request(mock_response)):
4304
+ assert await client.async_get_write_requests_remaining() is None
4305
+
4306
+
4307
+ async def test_get_write_requests_remaining_reraises_other_bad_requests() -> None:
4308
+ """A different bad request response is not an unsupported write budget."""
4309
+ mock_response = _response(status=400, text_payload='{"Code":4,"Result":"FAILED"}')
4310
+
4311
+ async with aiohttp.ClientSession() as session:
4312
+ client = DucoClient(session=session, host="192.0.2.94")
4313
+ with (
4314
+ patch.object(session, "request", _request(mock_response)),
4315
+ pytest.raises(DucoResponseError) as err,
4316
+ ):
4317
+ await client.async_get_write_requests_remaining()
4318
+
4319
+ assert err.value.status == 400
4320
+
4321
+
4296
4322
  async def test_get_time_filter_remaining_is_parsed() -> None:
4297
4323
  """Heat recovery filter time should be parsed when the box reports it."""
4298
4324
  payload: dict[str, object] = {"HeatRecovery": {"General": {"TimeFilterRemain": {"Val": 180}}}}
@@ -5272,6 +5298,142 @@ async def test_set_node_identify_uses_boolean_json_body() -> None:
5272
5298
  assert kwargs["headers"] == {"Content-Type": "application/json"}
5273
5299
 
5274
5300
 
5301
+ async def test_set_node_identify_timed_turns_off_at_deadline() -> None:
5302
+ """Timed identify should turn on immediately and off at its deadline."""
5303
+ async with aiohttp.ClientSession() as session:
5304
+ client = DucoClient(session=session, host="192.0.2.94")
5305
+ with patch.object(client, "_async_set_node_identify_value", AsyncMock()) as set_identify:
5306
+ started_at = asyncio.get_running_loop().time()
5307
+ await client.async_set_node_identify_timed(1)
5308
+ deadline = client._identify_deadlines[1]
5309
+ assert deadline == pytest.approx(started_at + 900, abs=0.1)
5310
+ with patch("asyncio.get_running_loop") as get_running_loop:
5311
+ get_running_loop.return_value.time.return_value = deadline
5312
+ client._start_node_identify_cleanup(1, deadline)
5313
+ await asyncio.gather(*client._identify_cleanup_tasks)
5314
+
5315
+ assert [call.args for call in set_identify.await_args_list] == [
5316
+ (1, True),
5317
+ (1, False),
5318
+ ]
5319
+
5320
+
5321
+ async def test_set_node_identify_timed_reschedules_early_cleanup() -> None:
5322
+ """Timed identify should reschedule cleanup if its timer runs early."""
5323
+ async with aiohttp.ClientSession() as session:
5324
+ client = DucoClient(session=session, host="192.0.2.94")
5325
+ with patch.object(client, "_async_set_node_identify_value", AsyncMock()):
5326
+ await client.async_set_node_identify_timed(1)
5327
+ deadline = client._identify_deadlines[1]
5328
+ with patch("duco_connectivity.client.asyncio.get_running_loop") as get_running_loop:
5329
+ loop = get_running_loop.return_value
5330
+ loop.time.return_value = deadline - 0.001
5331
+ client._start_node_identify_cleanup(1, deadline)
5332
+ await asyncio.gather(*client._identify_cleanup_tasks)
5333
+
5334
+ loop.call_at.assert_called_once_with(
5335
+ deadline,
5336
+ client._start_node_identify_cleanup,
5337
+ 1,
5338
+ deadline,
5339
+ )
5340
+ assert client._identify_deadlines[1] == deadline
5341
+ client._identify_timers[1].cancel()
5342
+
5343
+
5344
+ async def test_set_node_identify_timed_resets_deadline() -> None:
5345
+ """Starting identify again should supersede the previous deadline."""
5346
+ async with aiohttp.ClientSession() as session:
5347
+ client = DucoClient(session=session, host="192.0.2.94")
5348
+ with patch.object(client, "_async_set_node_identify_value", AsyncMock()) as set_identify:
5349
+ await client.async_set_node_identify_timed(1)
5350
+ previous_deadline = client._identify_deadlines[1]
5351
+ await client.async_set_node_identify_timed(1)
5352
+ client._start_node_identify_cleanup(1, previous_deadline)
5353
+ await client.async_set_node_identify(1, False)
5354
+
5355
+ assert [call.args for call in set_identify.await_args_list] == [
5356
+ (1, True),
5357
+ (1, True),
5358
+ (1, False),
5359
+ ]
5360
+
5361
+
5362
+ async def test_set_node_identify_timed_tracks_nodes_independently() -> None:
5363
+ """Timed identify should maintain a separate deadline for each node."""
5364
+ async with aiohttp.ClientSession() as session:
5365
+ client = DucoClient(session=session, host="192.0.2.94")
5366
+ with patch.object(client, "_async_set_node_identify_value", AsyncMock()):
5367
+ await client.async_set_node_identify_timed(1)
5368
+ await client.async_set_node_identify_timed(2)
5369
+ await client.async_set_node_identify(1, False)
5370
+
5371
+ assert set(client._identify_deadlines) == {2}
5372
+
5373
+ await client.async_set_node_identify(2, False)
5374
+
5375
+
5376
+ async def test_set_node_identify_timed_does_not_schedule_after_failure() -> None:
5377
+ """Timed identify should not schedule cleanup when enabling fails."""
5378
+ async with aiohttp.ClientSession() as session:
5379
+ client = DucoClient(session=session, host="192.0.2.94")
5380
+ with (
5381
+ patch.object(
5382
+ client,
5383
+ "_async_set_node_identify_value",
5384
+ AsyncMock(side_effect=DucoConnectionError("Connection failed")),
5385
+ ),
5386
+ pytest.raises(DucoConnectionError, match="Connection failed"),
5387
+ ):
5388
+ await client.async_set_node_identify_timed(1)
5389
+
5390
+ assert not client._identify_deadlines
5391
+ assert not client._identify_timers
5392
+
5393
+
5394
+ async def test_set_node_identify_cancels_timed_cleanup() -> None:
5395
+ """An explicit identify write should cancel managed cleanup."""
5396
+ async with aiohttp.ClientSession() as session:
5397
+ client = DucoClient(session=session, host="192.0.2.94")
5398
+ with patch.object(client, "_async_set_node_identify_value", AsyncMock()):
5399
+ await client.async_set_node_identify_timed(1)
5400
+ timer = client._identify_timers[1]
5401
+ await client.async_set_node_identify(1, False)
5402
+
5403
+ assert timer.cancelled()
5404
+ assert 1 not in client._identify_deadlines
5405
+ assert 1 not in client._identify_timers
5406
+
5407
+
5408
+ async def test_expired_node_identify_retries_on_next_request(
5409
+ caplog: pytest.LogCaptureFixture,
5410
+ ) -> None:
5411
+ """A later API request should retry failed identify cleanup."""
5412
+ mock_response = _response(json_payload={"ApiVersion": "2.5"})
5413
+
5414
+ async with aiohttp.ClientSession() as session:
5415
+ client = DucoClient(session=session, host="192.0.2.94")
5416
+ set_identify = AsyncMock(side_effect=[None, DucoConnectionError("Connection failed"), None])
5417
+ with patch.object(client, "_async_set_node_identify_value", set_identify):
5418
+ await client.async_set_node_identify_timed(1)
5419
+ deadline = asyncio.get_running_loop().time() - 1
5420
+ client._identify_deadlines[1] = deadline
5421
+ client._start_node_identify_cleanup(1, deadline)
5422
+ await asyncio.gather(*client._identify_cleanup_tasks)
5423
+
5424
+ with patch.object(session, "request", _request(mock_response)):
5425
+ await client.async_get_raw("/info")
5426
+ await asyncio.gather(*client._identify_cleanup_tasks)
5427
+
5428
+ assert [call.args for call in set_identify.await_args_list] == [
5429
+ (1, True),
5430
+ (1, False),
5431
+ (1, False),
5432
+ ]
5433
+ assert "Failed to disable identify for node 1 after 15 minutes" in caplog.text
5434
+ assert 1 not in client._identify_deadlines
5435
+
5436
+
5275
5437
  @pytest.mark.parametrize(
5276
5438
  "result_status",
5277
5439
  [ActionResultStatus.FAILED, ActionResultStatus.UNKNOWN],