forked from esphome/esphome-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_automations_pages.py
45 lines (34 loc) · 1.12 KB
/
build_automations_pages.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
#!/usr/bin/env python3
import argparse
import json
if __name__ == "__main__":
file_name = "all_automations.json"
arg_choices = ["actions", "conditions", "pin_providers"]
parser = argparse.ArgumentParser()
parser.add_argument(
"-t",
"--type",
choices=arg_choices,
help="Automation type to extract ('actions', 'conditions', 'pin_providers')",
)
args = parser.parse_args()
with open(file_name) as json_file:
raw_json = json.load(json_file)
if args.type not in arg_choices:
print("Unrecognized automation type")
exit()
automation_list = raw_json[args.type]
component_dict = {}
for item in automation_list:
parts = item.split(".")
if len(parts) == 2:
if parts[0] not in component_dict:
component_dict[parts[0]] = []
component_dict[parts[0]].append(parts[1])
out_str = ""
for comp, autos in component_dict.items():
out_str += f"- **{comp}:** "
for item in autos:
out_str += f"``{item}``, "
out_str = out_str[:-2] + "\n"
print(out_str)