Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ repos:
- id: markdownlint
- repo: local
hooks:
- id: 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"
entry: script/run-in-env.sh pytest
Expand Down
3 changes: 2 additions & 1 deletion airos/airos8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion script/generate_ha_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions script/mashumaro-step-debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(data)

_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")


Expand Down