Skip to content

Commit 8fa8a25

Browse files
committed
Add CRAI suggestions
1 parent 1ccab3a commit 8fa8a25

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

script/generate_ha_fixture.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ def generate_airos_fixtures() -> None:
4848
with open(base_fixture_path, encoding="utf-8") as source: # noqa: PTH123
4949
source_data = json.loads(source.read())
5050

51-
fwversion = source_data.get("host").get("fwversion")
51+
fwversion = (source_data.get("host") or {}).get("fwversion")
5252
if not fwversion:
53-
_LOGGER.error("Unable to determine firmware version")
54-
raise Exception from None # noqa: TRY002, TRY301
53+
_LOGGER.error(
54+
"Unable to determine firmware version in '%s' (missing host.fwversion)",
55+
filename,
56+
)
57+
raise ValueError("fwversion missing") from None # noqa: TRY301
5558

56-
fw_major = int(fwversion.lstrip("v").split(".")[0])
59+
try:
60+
fw_major = int(fwversion.lstrip("v").split(".", 1)[0])
61+
except (ValueError, AttributeError) as exc:
62+
_LOGGER.error(
63+
"Invalid firmware version '%s' in '%s'", fwversion, filename
64+
)
65+
raise ValueError("invalid fwversion") from exc
5766

5867
new_data: AirOS6Data | AirOS8Data
5968

script/mashumaro-step-debug.py

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

15-
from airos.airos6 import AirOS as AirOS6 # noqa: E402
15+
from airos.airos6 import AirOS6 # noqa: E402
1616
from airos.airos8 import AirOS as AirOS8 # noqa: E402
1717
from airos.data import ( # noqa: E402
1818
AirOS6Data,
@@ -45,12 +45,20 @@ def main() -> None:
4545
with open(sys.argv[1], encoding="utf-8") as f: # noqa: PTH123
4646
data = json.loads(f.read())
4747

48-
fwversion = data.get("host").get("fwversion")
48+
fwversion = (data.get("host") or {}).get("fwversion")
4949
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
5261

53-
fw_major = int(fwversion.lstrip("v").split(".")[0])
5462
if fw_major != 8:
5563
_LOGGER.warning("Non firmware 8 detected: %s", fwversion)
5664

@@ -108,13 +116,17 @@ def main() -> None:
108116
airos_data_obj: AirOS6Data | AirOS8Data
109117
if fw_major == 6:
110118
_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+
)
112122
_LOGGER.info("Attempting to deserialize full AirOS6Data object...")
113123
airos_data_obj = AirOS6Data.from_dict(derived_data)
114124
_LOGGER.info("Success! Full AirOS6Data object is valid.")
115125
else:
116126
_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+
)
118130
_LOGGER.info("Attempting to deserialize full AirOS8Data object...")
119131
airos_data_obj = AirOS8Data.from_dict(derived_data) # noqa: F841
120132
_LOGGER.info("Success! Full AirOS8Data object is valid.")

0 commit comments

Comments
 (0)