mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-11-10 10:11:29 +01:00
5c78504d97
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
#!/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)
|