From 2a9dcd5e9eddffc4f82875688c64fe1ddd44ec88 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 14 Aug 2025 09:33:54 +0200 Subject: [PATCH 1/3] Rerun fixtures to test userdata --- .pre-commit-config.yaml | 6 ++++++ script/mashumaro-step-debug.py | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 095343f..286272a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -82,6 +82,12 @@ repos: - id: markdownlint - repo: local hooks: + - id: parsetest + name: "parsetest" + entry: script/run-in-env.sh python script/generate_ha_fixture.py + language: script + types: [python] + pass_filenames: false - id: pytest name: "pytest" entry: script/run-in-env.sh pytest diff --git a/script/mashumaro-step-debug.py b/script/mashumaro-step-debug.py index 33f816e..b79a5f3 100644 --- a/script/mashumaro-step-debug.py +++ b/script/mashumaro-step-debug.py @@ -12,6 +12,7 @@ if _project_root_dir not in sys.path: sys.path.append(_project_root_dir) +from airos.airos8 import AirOS # noqa: E402 from airos.data import AirOS8Data, Interface, Remote, Station, Wireless # noqa: E402 logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) @@ -71,14 +72,17 @@ def main() -> None: interface_obj = Interface.from_dict(interface_data) # noqa: F841 _LOGGER.info(" Success! Interface is valid.") + _LOGGER.info("Deriving AirOS8Data from object...") + derived_data = AirOS.derived_data(None, data) # type: ignore[arg-type] + _LOGGER.info("Attempting to deserialize full AirOS8Data object...") - airos_data_obj = AirOS8Data.from_dict(data) # noqa: F841 + airos_data_obj = AirOS8Data.from_dict(derived_data) # noqa: F841 _LOGGER.info("Success! Full AirOS8Data object is valid.") - except Exception as e: + except Exception: _LOGGER.info("\n------------------") _LOGGER.info("CRITICAL ERROR FOUND!") - _LOGGER.info("The program failed at: %s", e) + _LOGGER.exception("The program failed") _LOGGER.info("------------------\n") From d4d31446d1612f732ddc9a132cb8021a8de29fc6 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 14 Aug 2025 09:49:00 +0200 Subject: [PATCH 2/3] Add CRAI suggestion --- .pre-commit-config.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 286272a..0b632e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -83,10 +83,12 @@ repos: - repo: local hooks: - id: parsetest - name: "parsetest" + name: "Generate AirOS Fixtures" entry: script/run-in-env.sh python script/generate_ha_fixture.py language: script types: [python] + # Run when Python changes (to refresh against code changes) and when userdata JSON changes + files: ^(airos|tests|script)/.+\.py$|^fixtures/userdata/.+\.json$ pass_filenames: false - id: pytest name: "pytest" From 3880dad33c2b54f7f08949b06e8518a1bc9ddf37 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 14 Aug 2025 09:52:14 +0200 Subject: [PATCH 3/3] More CRAI suggestions --- airos/airos8.py | 3 ++- script/generate_ha_fixture.py | 2 +- script/mashumaro-step-debug.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/airos/airos8.py b/airos/airos8.py index 6afbd8e..18beeae 100644 --- a/airos/airos8.py +++ b/airos/airos8.py @@ -193,7 +193,8 @@ async def login(self) -> bool: _LOGGER.info("Login task was cancelled") raise - def derived_data(self, response: dict[str, Any]) -> dict[str, Any]: + @staticmethod + def derived_data(response: dict[str, Any]) -> dict[str, Any]: """Add derived data to the device response.""" derived: dict[str, Any] = { "station": False, diff --git a/script/generate_ha_fixture.py b/script/generate_ha_fixture.py index 60276de..74efc5a 100644 --- a/script/generate_ha_fixture.py +++ b/script/generate_ha_fixture.py @@ -45,7 +45,7 @@ def generate_airos_fixtures() -> None: with open(base_fixture_path, encoding="utf-8") as source: source_data = json.loads(source.read()) - derived_data = AirOS.derived_data(None, source_data) # type: ignore[arg-type] + derived_data = AirOS.derived_data(source_data) new_data = AirOSData.from_dict(derived_data) with open(new_fixture_path, "w", encoding="utf-8") as new: diff --git a/script/mashumaro-step-debug.py b/script/mashumaro-step-debug.py index b79a5f3..8f201be 100644 --- a/script/mashumaro-step-debug.py +++ b/script/mashumaro-step-debug.py @@ -73,7 +73,7 @@ def main() -> None: _LOGGER.info(" Success! Interface is valid.") _LOGGER.info("Deriving AirOS8Data from object...") - derived_data = AirOS.derived_data(None, data) # type: ignore[arg-type] + derived_data = AirOS.derived_data(data) _LOGGER.info("Attempting to deserialize full AirOS8Data object...") airos_data_obj = AirOS8Data.from_dict(derived_data) # noqa: F841