Skip to content

Commit 3df1d63

Browse files
authored
Merge pull request #64 from CoMPaTech/upd
## Chores Added a local pre-commit hook to automate fixture generation when relevant files change. ## Refactor Standardized how intermediate derived data is produced and consumed across tooling and scripts. ## Bug Fixes Improved error reporting to include full stack traces. Added clearer logging around data derivation and processing for easier troubleshooting.
2 parents 40ea0e2 + 3880dad commit 3df1d63

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ repos:
8282
- id: markdownlint
8383
- repo: local
8484
hooks:
85+
- id: parsetest
86+
name: "Generate AirOS Fixtures"
87+
entry: script/run-in-env.sh python script/generate_ha_fixture.py
88+
language: script
89+
types: [python]
90+
# Run when Python changes (to refresh against code changes) and when userdata JSON changes
91+
files: ^(airos|tests|script)/.+\.py$|^fixtures/userdata/.+\.json$
92+
pass_filenames: false
8593
- id: pytest
8694
name: "pytest"
8795
entry: script/run-in-env.sh pytest

airos/airos8.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ async def login(self) -> bool:
193193
_LOGGER.info("Login task was cancelled")
194194
raise
195195

196-
def derived_data(self, response: dict[str, Any]) -> dict[str, Any]:
196+
@staticmethod
197+
def derived_data(response: dict[str, Any]) -> dict[str, Any]:
197198
"""Add derived data to the device response."""
198199
derived: dict[str, Any] = {
199200
"station": False,

script/generate_ha_fixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def generate_airos_fixtures() -> None:
4545
with open(base_fixture_path, encoding="utf-8") as source:
4646
source_data = json.loads(source.read())
4747

48-
derived_data = AirOS.derived_data(None, source_data) # type: ignore[arg-type]
48+
derived_data = AirOS.derived_data(source_data)
4949
new_data = AirOSData.from_dict(derived_data)
5050

5151
with open(new_fixture_path, "w", encoding="utf-8") as new:

script/mashumaro-step-debug.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
if _project_root_dir not in sys.path:
1313
sys.path.append(_project_root_dir)
1414

15+
from airos.airos8 import AirOS # noqa: E402
1516
from airos.data import AirOS8Data, Interface, Remote, Station, Wireless # noqa: E402
1617

1718
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
@@ -71,14 +72,17 @@ def main() -> None:
7172
interface_obj = Interface.from_dict(interface_data) # noqa: F841
7273
_LOGGER.info(" Success! Interface is valid.")
7374

75+
_LOGGER.info("Deriving AirOS8Data from object...")
76+
derived_data = AirOS.derived_data(data)
77+
7478
_LOGGER.info("Attempting to deserialize full AirOS8Data object...")
75-
airos_data_obj = AirOS8Data.from_dict(data) # noqa: F841
79+
airos_data_obj = AirOS8Data.from_dict(derived_data) # noqa: F841
7680
_LOGGER.info("Success! Full AirOS8Data object is valid.")
7781

78-
except Exception as e:
82+
except Exception:
7983
_LOGGER.info("\n------------------")
8084
_LOGGER.info("CRITICAL ERROR FOUND!")
81-
_LOGGER.info("The program failed at: %s", e)
85+
_LOGGER.exception("The program failed")
8286
_LOGGER.info("------------------\n")
8387

8488

0 commit comments

Comments
 (0)