Skip to content

Commit 7f97342

Browse files
committed
Debug script
1 parent 897eaf4 commit 7f97342

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

script/mashumaro-step-debug.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Debug userdata json to see where things don't add up."""
2+
3+
import json
4+
import logging
5+
import os
6+
import sys
7+
from typing import Any
8+
9+
current_script_dir = os.path.dirname(os.path.abspath(__file__))
10+
project_root_dir = os.path.abspath(os.path.join(current_script_dir, os.pardir))
11+
12+
if project_root_dir not in sys.path:
13+
sys.path.append(project_root_dir)
14+
15+
from airos.data import AirOS8Data, Remote, Station, Wireless # noqa: E402
16+
17+
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
18+
_LOGGER = logging.getLogger(__name__)
19+
20+
21+
def main():
22+
"""Debug data."""
23+
if len(sys.argv) <= 1:
24+
_LOGGER.info("Use with file to check")
25+
raise Exception("File to check not provided.")
26+
27+
current_script_dir = os.path.dirname(os.path.abspath(__file__))
28+
project_root_dir = os.path.abspath(os.path.join(current_script_dir, os.pardir))
29+
30+
if project_root_dir not in sys.path:
31+
sys.path.append(project_root_dir)
32+
33+
# Load the JSON data
34+
with open(sys.argv[1]) as f:
35+
data = json.loads(f.read())
36+
37+
try:
38+
_LOGGER.info("Attempting to deserialize Wireless object...")
39+
wireless_data: dict[str, Any] = data["wireless"]
40+
41+
_LOGGER.info(" -> Checking Wireless enums...")
42+
wireless_data_prepped = Wireless.__pre_deserialize__(wireless_data.copy()) # noqa: F841
43+
_LOGGER.info(
44+
" Success! Wireless enums (mode, ieeemode, security) are valid."
45+
)
46+
47+
_LOGGER.info(" -> Checking list of Station objects...")
48+
station_list_data = wireless_data["sta"]
49+
station_obj_list = []
50+
for i, station_data in enumerate(station_list_data):
51+
_LOGGER.info(" -> Checking Station object at index %s...", i)
52+
remote_data = station_data["remote"]
53+
_LOGGER.info(" -> Checking Remote object at index %s...", i)
54+
_LOGGER.info("Remote data = %s", remote_data)
55+
remote_obj = Remote.from_dict(remote_data) # noqa: F841
56+
_LOGGER.info(" Success! Remote is valid.")
57+
58+
station_obj = Station.from_dict(station_data)
59+
station_obj_list.append(station_obj) # noqa: F841
60+
_LOGGER.info(" Success! Station at index %s is valid.", i)
61+
62+
_LOGGER.info(" -> Checking top-level Wireless object...")
63+
wireless_obj = Wireless.from_dict(wireless_data) # noqa: F841
64+
_LOGGER.info(" -> Success! The Wireless object is valid.")
65+
66+
_LOGGER.info("Attempting to deserialize full AirOS8Data object...")
67+
airos_data_obj = AirOS8Data.from_dict(data) # noqa: F841
68+
_LOGGER.info("Success! Full AirOS8Data object is valid.")
69+
70+
except Exception as e:
71+
_LOGGER.info("\n------------------")
72+
_LOGGER.info("CRITICAL ERROR FOUND!")
73+
_LOGGER.info("The program failed at: %s", e)
74+
_LOGGER.info("------------------\n")
75+
76+
77+
if __name__ == "__main__":
78+
main()

0 commit comments

Comments
 (0)