Skip to content

Commit 9040cf6

Browse files
CopilotiMicknl
andauthored
Fix linting, type errors, use asyncio.gather, and improve test assertions
Agent-Logs-Url: https://github.com/iMicknl/python-overkiz-api/sessions/780a5262-1b4d-44e0-86b6-7720038d3cb7 Co-authored-by: iMicknl <1424596+iMicknl@users.noreply.github.com>
1 parent 7cf2e5c commit 9040cf6

4 files changed

Lines changed: 59 additions & 17 deletions

File tree

docs/superpowers/plans/2026-04-24-diagnostics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
**Goal:** Expand `get_diagnostic_data()` to return a structured dict containing both setup and action group data, with per-section obfuscation.
66

7-
**Architecture:** The method fetches two API endpoints (`setup` and `actionGroups`) concurrently, wraps them in a `{"setup": ..., "action_groups": [...]}` dict, and applies `obfuscate_sensitive_data` to each section individually. The obfuscation function is extended to accept lists of dicts in addition to plain dicts.
7+
**Architecture:** The method fetches two API endpoints (`setup` and `actionGroups`) concurrently using `asyncio.gather`, wraps them in a `{"setup": ..., "action_groups": [...]}` dict, and applies `obfuscate_sensitive_data` to each section individually. The obfuscation function is extended to accept lists of dicts in addition to plain dicts.
88

99
**Tech Stack:** Python 3.12+, aiohttp, pytest, pytest-asyncio
1010

pyoverkiz/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import asyncio
56
import logging
67
import ssl
78
import urllib.parse
@@ -329,7 +330,9 @@ async def get_setup(self, refresh: bool = False) -> Setup:
329330
return setup
330331

331332
@retry_on_auth_error
332-
async def get_diagnostic_data(self, mask_sensitive_data: bool = True) -> dict[str, Any]:
333+
async def get_diagnostic_data(
334+
self, mask_sensitive_data: bool = True
335+
) -> dict[str, Any]:
333336
"""Get diagnostic data for the connected user setup.
334337
335338
-> gateways data (serial number, activation state, ...): <gateways/gateway>
@@ -341,8 +344,10 @@ async def get_diagnostic_data(self, mask_sensitive_data: bool = True) -> dict[st
341344
By default, this data is masked to not return confidential or PII data.
342345
Set `mask_sensitive_data` to `False` to return the raw payloads.
343346
"""
344-
setup = await self._get("setup")
345-
action_groups = await self._get("actionGroups")
347+
setup, action_groups = await asyncio.gather(
348+
self._get("setup"),
349+
self._get("actionGroups"),
350+
)
346351

347352
if mask_sensitive_data:
348353
setup = obfuscate_sensitive_data(setup)

pyoverkiz/obfuscate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import re
6-
from typing import Any
6+
from typing import Any, cast
77

88

99
def obfuscate_id(id: str | None) -> str:
@@ -27,7 +27,9 @@ def obfuscate_sensitive_data(
2727
) -> dict[str, Any] | list[dict[str, Any]]:
2828
"""Mask Overkiz JSON data to remove sensitive data."""
2929
if isinstance(data, list):
30-
return [obfuscate_sensitive_data(item) for item in data]
30+
return cast(
31+
list[dict[str, Any]], [obfuscate_sensitive_data(item) for item in data]
32+
)
3133

3234
mask_next_value = False
3335

tests/test_client.py

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,21 @@ async def test_get_diagnostic_data(self, client: OverkizClient, fixture_name: st
305305
) as setup_mock:
306306
setup_resp = MockResponse(setup_mock.read())
307307

308-
with (CURRENT_DIR / "fixtures" / "action_groups" / "action-group-tahoma-switch.json").open(
308+
with (
309+
CURRENT_DIR
310+
/ "fixtures"
311+
/ "action_groups"
312+
/ "action-group-tahoma-switch.json"
313+
).open(
309314
encoding="utf-8",
310315
) as ag_mock:
311316
ag_resp = MockResponse(ag_mock.read())
312317

313318
responses = iter([setup_resp, ag_resp])
314319

315-
with patch.object(aiohttp.ClientSession, "get", side_effect=lambda *a, **kw: next(responses)):
320+
with patch.object(
321+
aiohttp.ClientSession, "get", side_effect=lambda *a, **kw: next(responses)
322+
):
316323
diagnostics = await client.get_diagnostic_data()
317324
assert diagnostics
318325
assert "setup" in diagnostics
@@ -326,26 +333,36 @@ async def test_get_diagnostic_data_redacted_by_default(self, client: OverkizClie
326333
) as setup_mock:
327334
setup_resp = MockResponse(setup_mock.read())
328335

329-
with (CURRENT_DIR / "fixtures" / "action_groups" / "action-group-tahoma-switch.json").open(
336+
with (
337+
CURRENT_DIR
338+
/ "fixtures"
339+
/ "action_groups"
340+
/ "action-group-tahoma-switch.json"
341+
).open(
330342
encoding="utf-8",
331343
) as ag_mock:
332344
ag_resp = MockResponse(ag_mock.read())
333345

334346
responses = iter([setup_resp, ag_resp])
335347

336348
with (
337-
patch.object(aiohttp.ClientSession, "get", side_effect=lambda *a, **kw: next(responses)),
349+
patch.object(
350+
aiohttp.ClientSession,
351+
"get",
352+
side_effect=lambda *a, **kw: next(responses),
353+
),
338354
patch(
339355
"pyoverkiz.client.obfuscate_sensitive_data",
340-
return_value={"masked": True},
356+
side_effect=[{"masked": True}, [{"masked": True}]],
341357
) as obfuscate,
342358
):
343359
diagnostics = await client.get_diagnostic_data()
344360
assert diagnostics == {
345361
"setup": {"masked": True},
346-
"action_groups": {"masked": True},
362+
"action_groups": [{"masked": True}],
347363
}
348364
assert obfuscate.call_count == 2
365+
assert isinstance(diagnostics["action_groups"], list)
349366

350367
@pytest.mark.asyncio
351368
async def test_get_diagnostic_data_without_masking(self, client: OverkizClient):
@@ -356,7 +373,12 @@ async def test_get_diagnostic_data_without_masking(self, client: OverkizClient):
356373
raw_setup = setup_mock.read()
357374
setup_resp = MockResponse(raw_setup)
358375

359-
with (CURRENT_DIR / "fixtures" / "action_groups" / "action-group-tahoma-switch.json").open(
376+
with (
377+
CURRENT_DIR
378+
/ "fixtures"
379+
/ "action_groups"
380+
/ "action-group-tahoma-switch.json"
381+
).open(
360382
encoding="utf-8",
361383
) as ag_mock:
362384
raw_ag = ag_mock.read()
@@ -365,7 +387,11 @@ async def test_get_diagnostic_data_without_masking(self, client: OverkizClient):
365387
responses = iter([setup_resp, ag_resp])
366388

367389
with (
368-
patch.object(aiohttp.ClientSession, "get", side_effect=lambda *a, **kw: next(responses)),
390+
patch.object(
391+
aiohttp.ClientSession,
392+
"get",
393+
side_effect=lambda *a, **kw: next(responses),
394+
),
369395
patch("pyoverkiz.client.obfuscate_sensitive_data") as obfuscate,
370396
):
371397
diagnostics = await client.get_diagnostic_data(mask_sensitive_data=False)
@@ -376,21 +402,30 @@ async def test_get_diagnostic_data_without_masking(self, client: OverkizClient):
376402
obfuscate.assert_not_called()
377403

378404
@pytest.mark.asyncio
379-
async def test_get_diagnostic_data_returns_structured_dict(self, client: OverkizClient):
405+
async def test_get_diagnostic_data_returns_structured_dict(
406+
self, client: OverkizClient
407+
):
380408
"""Verify diagnostic data returns a dict with setup and action_groups sections."""
381409
with (CURRENT_DIR / "fixtures" / "setup" / "setup_tahoma_1.json").open(
382410
encoding="utf-8",
383411
) as setup_mock:
384412
setup_resp = MockResponse(setup_mock.read())
385413

386-
with (CURRENT_DIR / "fixtures" / "action_groups" / "action-group-tahoma-switch.json").open(
414+
with (
415+
CURRENT_DIR
416+
/ "fixtures"
417+
/ "action_groups"
418+
/ "action-group-tahoma-switch.json"
419+
).open(
387420
encoding="utf-8",
388421
) as ag_mock:
389422
ag_resp = MockResponse(ag_mock.read())
390423

391424
responses = iter([setup_resp, ag_resp])
392425

393-
with patch.object(aiohttp.ClientSession, "get", side_effect=lambda *a, **kw: next(responses)):
426+
with patch.object(
427+
aiohttp.ClientSession, "get", side_effect=lambda *a, **kw: next(responses)
428+
):
394429
diagnostics = await client.get_diagnostic_data(mask_sensitive_data=False)
395430

396431
assert "setup" in diagnostics

0 commit comments

Comments
 (0)