|
12 | 12 | if _project_root_dir not in sys.path: |
13 | 13 | sys.path.append(_project_root_dir) |
14 | 14 |
|
15 | | -from airos.airos6 import AirOS as AirOS6 # noqa: E402 |
| 15 | +from airos.airos6 import AirOS6 # noqa: E402 |
16 | 16 | from airos.airos8 import AirOS as AirOS8 # noqa: E402 |
17 | 17 | from airos.data import ( # noqa: E402 |
18 | 18 | AirOS6Data, |
@@ -45,12 +45,20 @@ def main() -> None: |
45 | 45 | with open(sys.argv[1], encoding="utf-8") as f: # noqa: PTH123 |
46 | 46 | data = json.loads(f.read()) |
47 | 47 |
|
48 | | - fwversion = data.get("host").get("fwversion") |
| 48 | + fwversion = (data.get("host") or {}).get("fwversion") |
49 | 49 | if not fwversion: |
50 | | - _LOGGER.error("Unable to determine firmware version") |
51 | | - raise Exception from None # noqa: TRY002 |
| 50 | + _LOGGER.error( |
| 51 | + "Unable to determine firmware version in '%s' (missing host.fwversion)", |
| 52 | + sys.argv[1], |
| 53 | + ) |
| 54 | + raise ValueError("fwversion missing") from None |
| 55 | + |
| 56 | + try: |
| 57 | + fw_major = int(fwversion.lstrip("v").split(".", 1)[0]) |
| 58 | + except (ValueError, AttributeError) as exc: |
| 59 | + _LOGGER.error("Invalid firmware version '%s' in '%s'", fwversion, sys.argv[1]) |
| 60 | + raise ValueError("invalid fwversion") from exc |
52 | 61 |
|
53 | | - fw_major = int(fwversion.lstrip("v").split(".")[0]) |
54 | 62 | if fw_major != 8: |
55 | 63 | _LOGGER.warning("Non firmware 8 detected: %s", fwversion) |
56 | 64 |
|
@@ -108,13 +116,17 @@ def main() -> None: |
108 | 116 | airos_data_obj: AirOS6Data | AirOS8Data |
109 | 117 | if fw_major == 6: |
110 | 118 | _LOGGER.info("Deriving AirOS6Data from object...") |
111 | | - derived_data = AirOS6.derived_data(data) |
| 119 | + derived_data = AirOS6._derived_data_helper( # noqa: SLF001 |
| 120 | + data, AirOS6.derived_wireless_data |
| 121 | + ) |
112 | 122 | _LOGGER.info("Attempting to deserialize full AirOS6Data object...") |
113 | 123 | airos_data_obj = AirOS6Data.from_dict(derived_data) |
114 | 124 | _LOGGER.info("Success! Full AirOS6Data object is valid.") |
115 | 125 | else: |
116 | 126 | _LOGGER.info("Deriving AirOS8Data from object...") |
117 | | - derived_data = AirOS8.derived_data(data) |
| 127 | + derived_data = AirOS8._derived_data_helper( # noqa: SLF001 |
| 128 | + data, AirOS8.derived_wireless_data |
| 129 | + ) |
118 | 130 | _LOGGER.info("Attempting to deserialize full AirOS8Data object...") |
119 | 131 | airos_data_obj = AirOS8Data.from_dict(derived_data) # noqa: F841 |
120 | 132 | _LOGGER.info("Success! Full AirOS8Data object is valid.") |
|
0 commit comments