Skip to content

Commit 137563c

Browse files
authored
Fix Python model for Local API (id = None) (#1974)
Fixes #1183
1 parent 3b714ee commit 137563c

4 files changed

Lines changed: 44 additions & 3 deletions

File tree

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Use a cloud server when you want to connect through the vendor’s public API. U
7272

7373
async def main() -> None:
7474
async with OverkizClient(
75-
server=create_local_server_config(host="gateway-xxxx-xxxx-xxxx.local"),
75+
server=create_local_server_config(host="gateway-xxxx-xxxx-xxxx.local:8443"),
7676
credentials=LocalTokenCredentials("token-from-your-mobile-app"),
7777
verify_ssl=True, # disable if you connect via IP
7878
) as client:

pyoverkiz/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Setup:
4646

4747
creation_time: int | None = None
4848
last_update_time: int | None = None
49-
id: str = field(repr=obfuscate_id, default=None)
49+
id: str | None = field(repr=obfuscate_id, default=None)
5050
location: Location | None = None
5151
gateways: list[Gateway]
5252
devices: list[Device]
@@ -61,7 +61,7 @@ def __init__(
6161
*,
6262
creation_time: int | None = None,
6363
last_update_time: int | None = None,
64-
id: str = field(repr=obfuscate_id, default=None),
64+
id: str | None = None,
6565
location: dict[str, Any] | None = None,
6666
gateways: list[dict[str, Any]],
6767
devices: list[dict[str, Any]],

tests/test_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ async def test_get_setup(
275275
assert len(setup.devices) == device_count
276276
assert len(setup.gateways) == gateway_count
277277

278+
if fixture_name.startswith("setup_local"):
279+
assert setup.id is None
280+
278281
for device in setup.devices:
279282
assert device.identifier.gateway_id
280283
assert device.identifier.device_address

tests/test_models.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from __future__ import annotations
44

5+
import json
6+
from pathlib import Path
7+
58
import humps
69
import pytest
710

@@ -11,10 +14,12 @@
1114
Definition,
1215
Device,
1316
EventState,
17+
Setup,
1418
State,
1519
StateDefinition,
1620
States,
1721
)
22+
from pyoverkiz.obfuscate import obfuscate_id
1823

1924
RAW_STATES = [
2025
{"name": "core:NameState", "type": 3, "value": "alarm name"},
@@ -71,6 +76,39 @@
7176
}
7277

7378
STATE = "core:NameState"
79+
FIXTURES_DIR = Path(__file__).resolve().parent / "fixtures" / "setup"
80+
81+
82+
class TestSetup:
83+
"""Tests for setup-level ID parsing and redaction behavior."""
84+
85+
def test_id_is_raw_but_repr_is_redacted_when_present(self):
86+
"""When API provides `id`, keep raw value but redact it in repr output."""
87+
raw_setup = json.loads(
88+
(FIXTURES_DIR / "setup_tahoma_1.json").read_text(encoding="utf-8")
89+
)
90+
setup = Setup(**humps.decamelize(raw_setup))
91+
raw_id = "SETUP-1234-1234-8044"
92+
redacted_id = obfuscate_id(raw_id)
93+
94+
assert setup.id == raw_id
95+
assert redacted_id in repr(setup)
96+
assert raw_id not in repr(setup)
97+
98+
def test_id_is_none_when_missing(self):
99+
"""When API omits `id`, setup.id should stay None."""
100+
raw_setup = json.loads(
101+
(FIXTURES_DIR / "setup_local.json").read_text(encoding="utf-8")
102+
)
103+
setup = Setup(**humps.decamelize(raw_setup))
104+
105+
assert setup.id is None
106+
107+
def test_id_is_none_without_input_id(self):
108+
"""Constructing setup without an id keeps setup.id as None."""
109+
setup = Setup(gateways=[], devices=[])
110+
111+
assert setup.id is None
74112

75113

76114
class TestDevice:

0 commit comments

Comments
 (0)