python-duco-connectivity 0.12.0__tar.gz → 0.13.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 (26) hide show
  1. {python_duco_connectivity-0.12.0/src/python_duco_connectivity.egg-info → python_duco_connectivity-0.13.1}/PKG-INFO +9 -4
  2. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/README.md +8 -3
  3. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/pyproject.toml +1 -1
  4. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/duco_connectivity/__init__.py +2 -0
  5. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/duco_connectivity/client.py +3 -1
  6. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/duco_connectivity/models.py +56 -7
  7. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1/src/python_duco_connectivity.egg-info}/PKG-INFO +9 -4
  8. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/tests/test_client.py +23 -6
  9. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/tests/test_models.py +84 -0
  10. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/LICENSE +0 -0
  11. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/setup.cfg +0 -0
  12. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/duco_connectivity/__main__.py +0 -0
  13. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/duco_connectivity/cli.py +0 -0
  14. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/duco_connectivity/exceptions.py +0 -0
  15. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/duco_connectivity/py.typed +0 -0
  16. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/python_duco_connectivity.egg-info/SOURCES.txt +0 -0
  17. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/python_duco_connectivity.egg-info/dependency_links.txt +0 -0
  18. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/python_duco_connectivity.egg-info/entry_points.txt +0 -0
  19. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/python_duco_connectivity.egg-info/requires.txt +0 -0
  20. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/src/python_duco_connectivity.egg-info/top_level.txt +0 -0
  21. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/tests/test_api_reference.py +0 -0
  22. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/tests/test_cli.py +0 -0
  23. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/tests/test_exceptions.py +0 -0
  24. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/tests/test_local_sample_validation.py +0 -0
  25. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/tests/test_pytest_live_support.py +0 -0
  26. {python_duco_connectivity-0.12.0 → python_duco_connectivity-0.13.1}/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.12.0
3
+ Version: 0.13.1
4
4
  Summary: Async HTTP client for the local Duco Connectivity API
5
5
  Author: Ronald van der Meer
6
6
  License-Expression: MIT
@@ -80,9 +80,14 @@ bypass-target helper returns a typed target model for successful parameter-
80
80
  specific reads and raises `DucoError` if the requested target field is missing
81
81
  from an otherwise valid `/config` response.
82
82
 
83
- Diagnostic subsystem reads now keep raw component and status strings from
84
- `Diag.SubSystems`, so future subsystem names or status values remain available
85
- to downstream consumers without parse fallbacks or product-specific filtering.
83
+ Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
84
+ members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
85
+ API value in `raw_status`; an unrecognized future value produces `status=None`
86
+ without discarding the raw value. Subsystem names remain unfiltered so future
87
+ components are available to downstream consumers. Direct construction using a
88
+ pre-0.13 raw status string remains compatible and derives `raw_status`
89
+ automatically; callers using a normalized `DiagStatus` must provide
90
+ `raw_status` explicitly.
86
91
 
87
92
  ## Getting started
88
93
 
@@ -48,9 +48,14 @@ bypass-target helper returns a typed target model for successful parameter-
48
48
  specific reads and raises `DucoError` if the requested target field is missing
49
49
  from an otherwise valid `/config` response.
50
50
 
51
- Diagnostic subsystem reads now keep raw component and status strings from
52
- `Diag.SubSystems`, so future subsystem names or status values remain available
53
- to downstream consumers without parse fallbacks or product-specific filtering.
51
+ Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
52
+ members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
53
+ API value in `raw_status`; an unrecognized future value produces `status=None`
54
+ without discarding the raw value. Subsystem names remain unfiltered so future
55
+ components are available to downstream consumers. Direct construction using a
56
+ pre-0.13 raw status string remains compatible and derives `raw_status`
57
+ automatically; callers using a normalized `DiagStatus` must provide
58
+ `raw_status` explicitly.
54
59
 
55
60
  ## Getting started
56
61
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-duco-connectivity"
7
- version = "0.12.0"
7
+ version = "0.13.1"
8
8
  description = "Async HTTP client for the local Duco Connectivity API"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -54,6 +54,7 @@ from .models import (
54
54
  DeviceGroupConfigSubmoduleSelector,
55
55
  DiagComponent,
56
56
  DiagInfo,
57
+ DiagStatus,
57
58
  DucoSerialNumber,
58
59
  DucoVersion,
59
60
  HostName,
@@ -167,6 +168,7 @@ __all__ = [
167
168
  "DeviceGroupConfigSubmoduleSelector",
168
169
  "DiagComponent",
169
170
  "DiagInfo",
171
+ "DiagStatus",
170
172
  "DucoClient",
171
173
  "DucoConnectionError",
172
174
  "DucoError",
@@ -58,6 +58,7 @@ from .models import (
58
58
  DeviceGroupConfigSubmoduleSelector,
59
59
  DiagComponent,
60
60
  DiagInfo,
61
+ DiagStatus,
61
62
  InfoGeneralSubmoduleSelector,
62
63
  InfoGroup,
63
64
  InfoGroupStruct,
@@ -2067,7 +2068,8 @@ class DucoClient:
2067
2068
 
2068
2069
  return DiagComponent(
2069
2070
  component=component,
2070
- status=status,
2071
+ status=DiagStatus.from_api_value(status),
2072
+ raw_status=status,
2071
2073
  raw_payload=cls._preserve_raw_payload(payload),
2072
2074
  )
2073
2075
 
@@ -587,12 +587,20 @@ def _coerce_node_motor_position(value: NodeMotorPosition | int) -> NodeMotorPosi
587
587
 
588
588
 
589
589
  class DiagStatus(StrEnum):
590
- """Health states returned by the diagnostics API, plus a client-side fallback."""
590
+ """Known normalized health states returned by the diagnostics API."""
591
591
 
592
- OK = "Ok"
593
- DISABLE = "Disable"
594
- ERROR = "Error"
595
- UNKNOWN = "UNKNOWN"
592
+ OK = "ok"
593
+ DISABLED = "disabled"
594
+ ERROR = "error"
595
+
596
+ @classmethod
597
+ def from_api_value(cls, value: str) -> Self | None:
598
+ """Return the known normalized status for a raw API value."""
599
+ return {
600
+ "Ok": cls.OK,
601
+ "Disable": cls.DISABLED,
602
+ "Error": cls.ERROR,
603
+ }.get(value)
596
604
 
597
605
 
598
606
  class ActionResultStatus(StrEnum):
@@ -1567,14 +1575,55 @@ class NodeOverview:
1567
1575
  raw_payload: dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
1568
1576
 
1569
1577
 
1570
- @dataclass(frozen=True, slots=True)
1578
+ @dataclass(frozen=True, slots=True, init=False)
1571
1579
  class DiagComponent:
1572
1580
  """Health state for a diagnostic subsystem."""
1573
1581
 
1574
1582
  component: str
1575
- status: str
1583
+ status: DiagStatus | None
1584
+ raw_status: str
1576
1585
  raw_payload: dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
1577
1586
 
1587
+ def __init__(
1588
+ self,
1589
+ component: str,
1590
+ status: DiagStatus | str | None,
1591
+ raw_status: str | dict[str, Any] | None = None,
1592
+ raw_payload: dict[str, Any] | None = None,
1593
+ ) -> None:
1594
+ """Initialize a diagnostic subsystem with legacy argument compatibility."""
1595
+ if isinstance(raw_status, dict):
1596
+ if raw_payload is not None:
1597
+ raise TypeError("raw_payload was provided more than once")
1598
+ raw_payload = raw_status
1599
+ raw_status = None
1600
+ if raw_status is not None and not isinstance(raw_status, str):
1601
+ raise TypeError("raw_status must be a string")
1602
+ if (
1603
+ isinstance(status, str)
1604
+ and not isinstance(status, DiagStatus)
1605
+ and raw_status is not None
1606
+ and raw_status != status
1607
+ ):
1608
+ raise ValueError("raw_status must match status for raw API strings")
1609
+
1610
+ normalized_status: DiagStatus | None
1611
+ if isinstance(status, DiagStatus):
1612
+ normalized_status = status
1613
+ elif isinstance(status, str):
1614
+ normalized_status = DiagStatus.from_api_value(status)
1615
+ else:
1616
+ normalized_status = None
1617
+ if raw_status is None:
1618
+ if not isinstance(status, str) or isinstance(status, DiagStatus):
1619
+ raise TypeError("raw_status is required unless status is a raw API string")
1620
+ raw_status = status
1621
+
1622
+ object.__setattr__(self, "component", component)
1623
+ object.__setattr__(self, "status", normalized_status)
1624
+ object.__setattr__(self, "raw_status", raw_status)
1625
+ object.__setattr__(self, "raw_payload", {} if raw_payload is None else raw_payload)
1626
+
1578
1627
 
1579
1628
  @dataclass(frozen=True, slots=True)
1580
1629
  class DiagInfo:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-duco-connectivity
3
- Version: 0.12.0
3
+ Version: 0.13.1
4
4
  Summary: Async HTTP client for the local Duco Connectivity API
5
5
  Author: Ronald van der Meer
6
6
  License-Expression: MIT
@@ -80,9 +80,14 @@ bypass-target helper returns a typed target model for successful parameter-
80
80
  specific reads and raises `DucoError` if the requested target field is missing
81
81
  from an otherwise valid `/config` response.
82
82
 
83
- Diagnostic subsystem reads now keep raw component and status strings from
84
- `Diag.SubSystems`, so future subsystem names or status values remain available
85
- to downstream consumers without parse fallbacks or product-specific filtering.
83
+ Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
84
+ members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
85
+ API value in `raw_status`; an unrecognized future value produces `status=None`
86
+ without discarding the raw value. Subsystem names remain unfiltered so future
87
+ components are available to downstream consumers. Direct construction using a
88
+ pre-0.13 raw status string remains compatible and derives `raw_status`
89
+ automatically; callers using a normalized `DiagStatus` must provide
90
+ `raw_status` explicitly.
86
91
 
87
92
  ## Getting started
88
93
 
@@ -42,6 +42,7 @@ from duco_connectivity import (
42
42
  DeviceGroupConfigSubmoduleSelector,
43
43
  DiagComponent,
44
44
  DiagInfo,
45
+ DiagStatus,
45
46
  DucoClient,
46
47
  DucoConnectionError,
47
48
  DucoError,
@@ -2066,7 +2067,8 @@ async def test_get_diagnostics(diag_data: dict[str, object]) -> None:
2066
2067
 
2067
2068
  assert len(diags) == 3
2068
2069
  assert diags[0].component == "Ventilation"
2069
- assert diags[0].status == "Ok"
2070
+ assert diags[0].status is DiagStatus.OK
2071
+ assert diags[0].raw_status == "Ok"
2070
2072
  assert diags[0].raw_payload is diag_data["Diag"]["SubSystems"][0]
2071
2073
 
2072
2074
 
@@ -2085,13 +2087,19 @@ async def test_get_diagnostics_info_exposes_typed_subsystems(
2085
2087
  assert_type(diag_info, DiagInfo)
2086
2088
  assert_type(diag_info.diagnostic_subsystems, tuple[DiagComponent, ...])
2087
2089
  assert_type(diag_info.diagnostic_subsystems[0].component, str)
2088
- assert_type(diag_info.diagnostic_subsystems[0].status, str)
2090
+ assert_type(diag_info.diagnostic_subsystems[0].status, DiagStatus | None)
2091
+ assert_type(diag_info.diagnostic_subsystems[0].raw_status, str)
2089
2092
  assert tuple(item.component for item in diag_info.diagnostic_subsystems) == (
2090
2093
  "Ventilation",
2091
2094
  "VentCool",
2092
2095
  "SunCtrl",
2093
2096
  )
2094
2097
  assert tuple(item.status for item in diag_info.diagnostic_subsystems) == (
2098
+ DiagStatus.OK,
2099
+ DiagStatus.OK,
2100
+ DiagStatus.OK,
2101
+ )
2102
+ assert tuple(item.raw_status for item in diag_info.diagnostic_subsystems) == (
2095
2103
  "Ok",
2096
2104
  "Ok",
2097
2105
  "Ok",
@@ -2115,7 +2123,8 @@ async def test_get_diagnostics_preserves_unknown_status() -> None:
2115
2123
  diags = await client.async_get_diagnostics()
2116
2124
 
2117
2125
  assert len(diags) == 1
2118
- assert diags[0].status == "FutureState"
2126
+ assert diags[0].status is None
2127
+ assert diags[0].raw_status == "FutureState"
2119
2128
 
2120
2129
 
2121
2130
  async def test_get_diagnostics_preserves_unknown_component_name() -> None:
@@ -2182,9 +2191,11 @@ async def test_get_diagnostics_info_skips_partial_entries() -> None:
2182
2191
  with patch.object(session, "request", _request(mock_response)):
2183
2192
  diag_info = await client.async_get_diagnostics_info()
2184
2193
 
2185
- assert tuple((item.component, item.status) for item in diag_info.diagnostic_subsystems) == (
2186
- ("Ventilation", "Ok"),
2187
- ("SunCtrl", "FutureState"),
2194
+ assert tuple(
2195
+ (item.component, item.status, item.raw_status) for item in diag_info.diagnostic_subsystems
2196
+ ) == (
2197
+ ("Ventilation", DiagStatus.OK, "Ok"),
2198
+ ("SunCtrl", None, "FutureState"),
2188
2199
  )
2189
2200
 
2190
2201
 
@@ -2213,6 +2224,12 @@ async def test_get_diagnostics_info_does_not_filter_product_specific_subsystems(
2213
2224
  "SunCtrl",
2214
2225
  "FutureSubsystem",
2215
2226
  )
2227
+ assert tuple((item.status, item.raw_status) for item in diag_info.diagnostic_subsystems) == (
2228
+ (DiagStatus.ERROR, "Error"),
2229
+ (DiagStatus.OK, "Ok"),
2230
+ (DiagStatus.OK, "Ok"),
2231
+ (DiagStatus.DISABLED, "Disable"),
2232
+ )
2216
2233
 
2217
2234
 
2218
2235
  async def test_get_nodes_parses_full_payload(nodes_data: dict[str, object]) -> None:
@@ -2,6 +2,7 @@
2
2
 
3
3
  import inspect
4
4
  import logging
5
+ from typing import cast
5
6
 
6
7
  import pytest
7
8
 
@@ -41,6 +42,8 @@ from duco_connectivity import (
41
42
  ConfigZonesOverview,
42
43
  ConfigZoneStruct,
43
44
  DeviceGroupConfigSubmoduleSelector,
45
+ DiagComponent,
46
+ DiagStatus,
44
47
  DucoSerialNumber,
45
48
  DucoVersion,
46
49
  HostName,
@@ -275,6 +278,87 @@ def test_selector_enum_values() -> None:
275
278
  assert DeviceGroupConfigSubmoduleSelector.GENERAL.value == "General"
276
279
 
277
280
 
281
+ @pytest.mark.parametrize(
282
+ ("raw_status", "expected_status"),
283
+ [
284
+ pytest.param("Ok", DiagStatus.OK, id="ok"),
285
+ pytest.param("Disable", DiagStatus.DISABLED, id="disabled"),
286
+ pytest.param("Error", DiagStatus.ERROR, id="error"),
287
+ pytest.param("FutureState", None, id="unknown"),
288
+ ],
289
+ )
290
+ def test_diag_component_accepts_legacy_raw_status(
291
+ raw_status: str, expected_status: DiagStatus | None
292
+ ) -> None:
293
+ """DiagComponent should normalize status strings accepted before version 0.13."""
294
+ raw_payload = {"Status": raw_status}
295
+
296
+ component = DiagComponent(
297
+ component="Ventilation",
298
+ status=raw_status,
299
+ raw_payload=raw_payload,
300
+ )
301
+
302
+ assert component.status is expected_status
303
+ assert component.raw_status == raw_status
304
+ assert component.raw_payload is raw_payload
305
+
306
+
307
+ def test_diag_component_accepts_legacy_positional_raw_payload() -> None:
308
+ """DiagComponent should retain the legacy positional raw payload argument."""
309
+ raw_payload = {"Status": "Ok"}
310
+
311
+ component = DiagComponent("Ventilation", "Ok", raw_payload)
312
+
313
+ assert component.status is DiagStatus.OK
314
+ assert component.raw_status == "Ok"
315
+ assert component.raw_payload is raw_payload
316
+
317
+
318
+ def test_diag_component_accepts_normalized_status() -> None:
319
+ """DiagComponent should retain the explicit normalized status contract."""
320
+ component = DiagComponent(
321
+ component="Ventilation",
322
+ status=DiagStatus.OK,
323
+ raw_status="Ok",
324
+ )
325
+
326
+ assert component.status is DiagStatus.OK
327
+ assert component.raw_status == "Ok"
328
+
329
+
330
+ def test_diag_component_rejects_conflicting_legacy_raw_status() -> None:
331
+ """DiagComponent should reject conflicting legacy raw status values."""
332
+ with pytest.raises(ValueError, match="raw_status must match status"):
333
+ DiagComponent(
334
+ component="Ventilation",
335
+ status="Ok",
336
+ raw_status="Error",
337
+ )
338
+
339
+
340
+ def test_diag_component_accepts_matching_legacy_raw_status() -> None:
341
+ """DiagComponent should accept matching explicit legacy raw status values."""
342
+ component = DiagComponent(
343
+ component="Ventilation",
344
+ status="Ok",
345
+ raw_status="Ok",
346
+ )
347
+
348
+ assert component.status is DiagStatus.OK
349
+ assert component.raw_status == "Ok"
350
+
351
+
352
+ def test_diag_component_rejects_non_string_raw_status() -> None:
353
+ """DiagComponent should reject non-string raw status values."""
354
+ with pytest.raises(TypeError, match="raw_status must be a string"):
355
+ DiagComponent(
356
+ component="Ventilation",
357
+ status=DiagStatus.OK,
358
+ raw_status=cast(str, 42),
359
+ )
360
+
361
+
278
362
  def test_board_name_known_value() -> None:
279
363
  """BoardName should expose observed stable board identities."""
280
364
  board_name = BoardName("SILENT_CONNECT")