python-duco-connectivity 0.16.0__tar.gz → 0.17.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.16.0/src/python_duco_connectivity.egg-info → python_duco_connectivity-0.17.0}/PKG-INFO +5 -1
  2. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/README.md +4 -0
  3. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/pyproject.toml +1 -1
  4. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/duco_connectivity/__init__.py +2 -0
  5. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/duco_connectivity/client.py +18 -0
  6. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/duco_connectivity/exceptions.py +22 -0
  7. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0/src/python_duco_connectivity.egg-info}/PKG-INFO +5 -1
  8. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/tests/test_api_reference.py +1 -0
  9. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/tests/test_client.py +72 -0
  10. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/tests/test_exceptions.py +20 -0
  11. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/LICENSE +0 -0
  12. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/setup.cfg +0 -0
  13. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/duco_connectivity/__main__.py +0 -0
  14. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/duco_connectivity/cli.py +0 -0
  15. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/duco_connectivity/models.py +0 -0
  16. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/duco_connectivity/py.typed +0 -0
  17. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/python_duco_connectivity.egg-info/SOURCES.txt +0 -0
  18. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/python_duco_connectivity.egg-info/dependency_links.txt +0 -0
  19. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/python_duco_connectivity.egg-info/entry_points.txt +0 -0
  20. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/python_duco_connectivity.egg-info/requires.txt +0 -0
  21. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/src/python_duco_connectivity.egg-info/top_level.txt +0 -0
  22. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/tests/test_cli.py +0 -0
  23. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/tests/test_local_sample_validation.py +0 -0
  24. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/tests/test_models.py +0 -0
  25. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.0}/tests/test_pytest_live_support.py +0 -0
  26. {python_duco_connectivity-0.16.0 → python_duco_connectivity-0.17.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.16.0
3
+ Version: 0.17.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
@@ -105,6 +105,10 @@ models, `InfoOverview` does not retain the broad response or the LAN raw
105
105
  payload, because that response can contain network credentials such as the
106
106
  Wi-Fi access point key.
107
107
 
108
+ `async_set_node_identify(node_id, identify)` exposes the node `SetIdentify`
109
+ action with an explicit Boolean state. The helper raises `DucoActionError` when
110
+ the box returns an unsuccessful action result.
111
+
108
112
  ## Getting started
109
113
 
110
114
  ```python
@@ -73,6 +73,10 @@ models, `InfoOverview` does not retain the broad response or the LAN raw
73
73
  payload, because that response can contain network credentials such as the
74
74
  Wi-Fi access point key.
75
75
 
76
+ `async_set_node_identify(node_id, identify)` exposes the node `SetIdentify`
77
+ action with an explicit Boolean state. The helper raises `DucoActionError` when
78
+ the box returns an unsuccessful action result.
79
+
76
80
  ## Getting started
77
81
 
78
82
  ```python
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-duco-connectivity"
7
- version = "0.16.0"
7
+ version = "0.17.0"
8
8
  description = "Async HTTP client for the local Duco Connectivity API"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -4,6 +4,7 @@ from importlib.metadata import PackageNotFoundError, version
4
4
 
5
5
  from .client import DucoClient
6
6
  from .exceptions import (
7
+ DucoActionError,
7
8
  DucoConnectionError,
8
9
  DucoError,
9
10
  DucoRateLimitError,
@@ -170,6 +171,7 @@ __all__ = [
170
171
  "DiagComponent",
171
172
  "DiagInfo",
172
173
  "DiagStatus",
174
+ "DucoActionError",
173
175
  "DucoClient",
174
176
  "DucoConnectionError",
175
177
  "DucoError",
@@ -13,6 +13,7 @@ from urllib.parse import urlsplit
13
13
  import aiohttp
14
14
 
15
15
  from .exceptions import (
16
+ DucoActionError,
16
17
  DucoConnectionError,
17
18
  DucoError,
18
19
  DucoResponseError,
@@ -68,6 +69,7 @@ from .models import (
68
69
  InfoZoneGroup,
69
70
  InfoZonesOverview,
70
71
  InfoZoneStruct,
72
+ KnownActionName,
71
73
  LanInfo,
72
74
  NetworkType,
73
75
  Node,
@@ -2502,6 +2504,22 @@ class DucoClient:
2502
2504
  val=state_value,
2503
2505
  )
2504
2506
 
2507
+ async def async_set_node_identify(self, node_id: int, identify: bool) -> None:
2508
+ """Set the identify state for a node."""
2509
+ action = KnownActionName.SET_IDENTIFY
2510
+ result = await self.async_set_node_action(
2511
+ node_id=node_id,
2512
+ action=action,
2513
+ val=identify,
2514
+ )
2515
+ if result.result is not ActionResultStatus.SUCCESS:
2516
+ raise DucoActionError(
2517
+ action=action,
2518
+ result=result.result,
2519
+ code=result.code,
2520
+ message=result.message,
2521
+ )
2522
+
2505
2523
  async def async_set_node_action(
2506
2524
  self,
2507
2525
  node_id: int,
@@ -5,6 +5,28 @@ class DucoError(Exception):
5
5
  """Base class for client errors."""
6
6
 
7
7
 
8
+ class DucoActionError(DucoError):
9
+ """Raised when the box reports an unsuccessful action result."""
10
+
11
+ def __init__(
12
+ self,
13
+ action: str,
14
+ result: str,
15
+ code: int | None = None,
16
+ message: str | None = None,
17
+ ) -> None:
18
+ self.action = action
19
+ self.result = result
20
+ self.code = code
21
+ self.message = message
22
+ detail = f"Duco action {action} returned {result}"
23
+ if code is not None:
24
+ detail = f"{detail} (code {code})"
25
+ if message:
26
+ detail = f"{detail}: {message}"
27
+ super().__init__(detail)
28
+
29
+
8
30
  class DucoConnectionError(DucoError):
9
31
  """Raised when the client cannot reach the box."""
10
32
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-duco-connectivity
3
- Version: 0.16.0
3
+ Version: 0.17.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
@@ -105,6 +105,10 @@ models, `InfoOverview` does not retain the broad response or the LAN raw
105
105
  payload, because that response can contain network credentials such as the
106
106
  Wi-Fi access point key.
107
107
 
108
+ `async_set_node_identify(node_id, identify)` exposes the node `SetIdentify`
109
+ action with an explicit Boolean state. The helper raises `DucoActionError` when
110
+ the box returns an unsuccessful action result.
111
+
108
112
  ## Getting started
109
113
 
110
114
  ```python
@@ -56,6 +56,7 @@ def test_collect_public_symbols_groups_known_exports() -> None:
56
56
  assert "VentilationState" in symbols["Enums"]
57
57
  assert "InfoModuleSelector" in symbols["Enums"]
58
58
  assert "ConfigZone" in symbols["Models"]
59
+ assert "DucoActionError" in symbols["Exceptions"]
59
60
  assert "DucoWriteLimitError" in symbols["Exceptions"]
60
61
  assert symbols["Compatibility exports"] == ["ApiEndpointInfo", "DucoRateLimitError"]
61
62
  assert symbols["Other"] == ["__version__"]
@@ -13,6 +13,7 @@ from duco_connectivity import (
13
13
  ActionEnumValue,
14
14
  ActionItem,
15
15
  ActionName,
16
+ ActionResult,
16
17
  ActionResultStatus,
17
18
  ActionValueType,
18
19
  BoardName,
@@ -43,6 +44,7 @@ from duco_connectivity import (
43
44
  DiagComponent,
44
45
  DiagInfo,
45
46
  DiagStatus,
47
+ DucoActionError,
46
48
  DucoClient,
47
49
  DucoConnectionError,
48
50
  DucoError,
@@ -60,6 +62,7 @@ from duco_connectivity import (
60
62
  InfoZoneGroup,
61
63
  InfoZonesOverview,
62
64
  IpAddress,
65
+ KnownActionName,
63
66
  KnownBoardName,
64
67
  KnownLanMode,
65
68
  LanMode,
@@ -5233,6 +5236,75 @@ async def test_set_ventilation_state_delegates_to_generic_node_action() -> None:
5233
5236
  )
5234
5237
 
5235
5238
 
5239
+ @pytest.mark.parametrize("identify", [True, False])
5240
+ async def test_set_node_identify_delegates_to_generic_node_action(
5241
+ identify: bool,
5242
+ ) -> None:
5243
+ """Identify writes should use the typed Boolean node action contract."""
5244
+ async with aiohttp.ClientSession() as session:
5245
+ client = DucoClient(session=session, host="192.0.2.94")
5246
+ with patch.object(
5247
+ client,
5248
+ "async_set_node_action",
5249
+ AsyncMock(return_value=ActionResult(result=ActionResultStatus.SUCCESS)),
5250
+ ) as set_node_action:
5251
+ await client.async_set_node_identify(1, identify)
5252
+
5253
+ set_node_action.assert_awaited_once_with(
5254
+ node_id=1,
5255
+ action=KnownActionName.SET_IDENTIFY,
5256
+ val=identify,
5257
+ )
5258
+
5259
+
5260
+ async def test_set_node_identify_uses_boolean_json_body() -> None:
5261
+ """Identify writes should send an explicit JSON Boolean value."""
5262
+ mock_response = _response(json_payload={"Result": "SUCCESS"})
5263
+
5264
+ async with aiohttp.ClientSession() as session:
5265
+ client = DucoClient(session=session, host="192.0.2.94")
5266
+ request = MagicMock(return_value=_request_context(mock_response))
5267
+ with patch.object(session, "request", request):
5268
+ await client.async_set_node_identify(1, True)
5269
+
5270
+ _, kwargs = request.call_args
5271
+ assert kwargs["data"] == b'{"Action":"SetIdentify","Val":true}'
5272
+ assert kwargs["headers"] == {"Content-Type": "application/json"}
5273
+
5274
+
5275
+ @pytest.mark.parametrize(
5276
+ "result_status",
5277
+ [ActionResultStatus.FAILED, ActionResultStatus.UNKNOWN],
5278
+ )
5279
+ async def test_set_node_identify_raises_for_unsuccessful_result(
5280
+ result_status: ActionResultStatus,
5281
+ ) -> None:
5282
+ """Identify writes should raise when the API does not report success."""
5283
+ async with aiohttp.ClientSession() as session:
5284
+ client = DucoClient(session=session, host="192.0.2.94")
5285
+ with (
5286
+ patch.object(
5287
+ client,
5288
+ "async_set_node_action",
5289
+ AsyncMock(
5290
+ return_value=ActionResult(
5291
+ result=result_status,
5292
+ code=12,
5293
+ message="Action is not performed",
5294
+ )
5295
+ ),
5296
+ ),
5297
+ pytest.raises(
5298
+ DucoActionError,
5299
+ match=(
5300
+ rf"Duco action SetIdentify returned {result_status} "
5301
+ r"\(code 12\): Action is not performed"
5302
+ ),
5303
+ ),
5304
+ ):
5305
+ await client.async_set_node_identify(1, True)
5306
+
5307
+
5236
5308
  async def test_set_ventilation_state_uses_compact_json_body() -> None:
5237
5309
  """Write requests should use compact JSON with explicit content type."""
5238
5310
  mock_response = _response(json_payload={"Result": "SUCCESS"})
@@ -3,6 +3,7 @@
3
3
  import pytest
4
4
 
5
5
  from duco_connectivity import (
6
+ DucoActionError,
6
7
  DucoConnectionError,
7
8
  DucoError,
8
9
  DucoRateLimitError,
@@ -12,6 +13,25 @@ from duco_connectivity import (
12
13
  )
13
14
 
14
15
 
16
+ def test_action_error_exposes_result_context() -> None:
17
+ """DucoActionError should expose the unsuccessful action result."""
18
+ err = DucoActionError(
19
+ action="SetIdentify",
20
+ result="FAILED",
21
+ code=12,
22
+ message="Action is not performed",
23
+ )
24
+
25
+ assert err.action == "SetIdentify"
26
+ assert err.result == "FAILED"
27
+ assert err.code == 12
28
+ assert err.message == "Action is not performed"
29
+ assert str(err) == (
30
+ "Duco action SetIdentify returned FAILED (code 12): Action is not performed"
31
+ )
32
+ assert isinstance(err, DucoError)
33
+
34
+
15
35
  def test_connection_error_inherits_from_base_error() -> None:
16
36
  """DucoConnectionError should remain catchable as DucoError."""
17
37
  err = DucoConnectionError("unreachable")