mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 05:24:53 +01:00
[core] Add script to extract actions, conditions, and pin_providers (#6929)
This commit is contained in:
parent
53cfa8d3a1
commit
11b8e2e1af
2 changed files with 45 additions and 18 deletions
25
script/extract_automations.py
Executable file
25
script/extract_automations.py
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
|
||||
from helpers import git_ls_files
|
||||
|
||||
from esphome.automation import ACTION_REGISTRY, CONDITION_REGISTRY
|
||||
from esphome.pins import PIN_SCHEMA_REGISTRY
|
||||
|
||||
list_components = __import__("list-components")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
files = git_ls_files()
|
||||
files = filter(list_components.filter_component_files, files)
|
||||
|
||||
components = list_components.get_components(files, True)
|
||||
|
||||
dump = {
|
||||
"actions": sorted(list(ACTION_REGISTRY.keys())),
|
||||
"conditions": sorted(list(CONDITION_REGISTRY.keys())),
|
||||
"pin_providers": sorted(list(PIN_SCHEMA_REGISTRY.keys())),
|
||||
}
|
||||
|
||||
print(json.dumps(dump, indent=2))
|
|
@ -50,6 +50,7 @@ def create_components_graph():
|
|||
{KEY_TARGET_FRAMEWORK: "arduino", KEY_TARGET_PLATFORM: None},
|
||||
{KEY_TARGET_FRAMEWORK: "esp-idf", KEY_TARGET_PLATFORM: None},
|
||||
{KEY_TARGET_FRAMEWORK: None, KEY_TARGET_PLATFORM: PLATFORM_ESP32},
|
||||
{KEY_TARGET_FRAMEWORK: None, KEY_TARGET_PLATFORM: PLATFORM_ESP8266},
|
||||
]
|
||||
CORE.data[KEY_CORE] = TARGET_CONFIGURATIONS[0]
|
||||
|
||||
|
@ -119,6 +120,23 @@ def find_children_of_component(components_graph, component_name, depth=0):
|
|||
return list(set(children))
|
||||
|
||||
|
||||
def get_components(files: list[str], get_dependencies: bool = False):
|
||||
components = extract_component_names_array_from_files_array(files)
|
||||
|
||||
if get_dependencies:
|
||||
components_graph = create_components_graph()
|
||||
|
||||
all_components = components.copy()
|
||||
for c in components:
|
||||
all_components.extend(find_children_of_component(components_graph, c))
|
||||
# Remove duplicate values
|
||||
all_changed_components = list(set(all_components))
|
||||
|
||||
return sorted(all_changed_components)
|
||||
|
||||
return sorted(components)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
|
@ -142,24 +160,8 @@ def main():
|
|||
changed = changed_files()
|
||||
files = [f for f in files if f in changed]
|
||||
|
||||
components = extract_component_names_array_from_files_array(files)
|
||||
|
||||
if args.changed:
|
||||
components_graph = create_components_graph()
|
||||
|
||||
all_changed_components = components.copy()
|
||||
for c in components:
|
||||
all_changed_components.extend(
|
||||
find_children_of_component(components_graph, c)
|
||||
)
|
||||
# Remove duplicate values
|
||||
all_changed_components = list(set(all_changed_components))
|
||||
|
||||
for c in sorted(all_changed_components):
|
||||
print(c)
|
||||
else:
|
||||
for c in sorted(components):
|
||||
print(c)
|
||||
for c in get_components(files, args.changed):
|
||||
print(c)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue