forked from litinoveweedle/SmartIR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_device_data.py
70 lines (58 loc) · 1.75 KB
/
test_device_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import asyncio
import pathlib
import json
import sys
from custom_components.smartir import DeviceData
CHECK_DATA = {
"climate": {
"hvac_modes": ["auto", "heat", "cool", "heat_cool", "fan_only", "dry"],
},
"fan": {},
"media_player": {},
"light": {},
}
async def test_json(file_path, docs):
p = pathlib.Path(file_path)
path = p.parts
if path[0] != "codes" and path[0] != "custom_codes":
return True
file_name = path[-1]
device_class = path[-2]
if device_data := DeviceData.read_file_as_json(file_path):
if result := await DeviceData.check_file(
file_name,
device_data,
device_class,
CHECK_DATA[device_class],
):
docs[device_class].append(
{
"file": file_name,
"manufacturer": device_data["manufacturer"],
"models": ", ".join(device_data["supportedModels"]),
"controller": device_data["supportedController"],
}
)
return True
return False
async def main():
exit = 0
generate_docs = False
docs = {"climate": [], "fan": [], "media_player": [], "light": []}
files = sys.argv
files.pop(0)
if not len(files):
sys.exit(0)
if files[0] == "--docs":
files.pop(0)
generate_docs = True
if len(files):
for file_path in files:
if not await test_json(file_path, docs):
exit = 1
if generate_docs:
for device_class in docs.keys():
with open("docs/" + device_class + "_codes.json", "w") as outfile:
json.dump(docs[device_class], outfile)
sys.exit(exit)
asyncio.run(main())