diff --git a/script/extract_automations.py b/script/extract_automations.py new file mode 100755 index 0000000000..943eb7110a --- /dev/null +++ b/script/extract_automations.py @@ -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)) diff --git a/script/list-components.py b/script/list-components.py index 5b5fa5811f..4eccdbf96c 100755 --- a/script/list-components.py +++ b/script/list-components.py @@ -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__":