diff --git a/api/src/automations/loader.py b/api/src/automations/loader.py index 7c8f511..7e2d7fe 100644 --- a/api/src/automations/loader.py +++ b/api/src/automations/loader.py @@ -1,4 +1,3 @@ -from itertools import chain from pathlib import Path from typing import Any, Iterator, Tuple, Union @@ -141,6 +140,7 @@ def extract_automation_inline_package_refs( ignore_package_name=False, ) -> AutomationExtractedIter: for package_name, package_data in packages_config.items(): + logger.info(f"Loading package={package_name}:{type(package_data)} from {package_data}") try: if isinstance(package_data, IncludedYaml): package_mapping = package_data.to_normalized_json() @@ -176,11 +176,11 @@ def extract_automation_inline_package_refs( prefix_config_keys=prefix_config_keys, ignore_package_name=ignore_package_name, ) - else: + elif package_data is not None: raise InvalidPackage( - f"configurations.homeassistant.packages[{package_name}] must be a dictionary!" + f"configurations.homeassistant.packages.{package_name} must be a dictionary but got {type(package_data)}!" ) - except Exception as err: + except InvalidPackage as err: logger.error(err) diff --git a/api/tests/samples/config-15/automations.yaml b/api/tests/samples/config-15/automations.yaml new file mode 100644 index 0000000..e125729 --- /dev/null +++ b/api/tests/samples/config-15/automations.yaml @@ -0,0 +1,21 @@ +- alias: UI 1 + description: Example + mode: single + trigger: + - platform: homeassistant + event: start + condition: [] + action: + - service: counter.increment + data: {} + target: + entity_id: counter.up_times +- alias: UI 2 + description: "" + trigger: + - platform: sun + event: sunrise + offset: 0 + condition: [] + action: [] + mode: single diff --git a/api/tests/samples/config-15/configuration.yaml b/api/tests/samples/config-15/configuration.yaml new file mode 100644 index 0000000..0a9299f --- /dev/null +++ b/api/tests/samples/config-15/configuration.yaml @@ -0,0 +1,2 @@ +homeassistant: + packages: !include_dir_named integrations diff --git a/api/tests/samples/config-15/integrations/automation.yaml b/api/tests/samples/config-15/integrations/automation.yaml new file mode 100644 index 0000000..baad389 --- /dev/null +++ b/api/tests/samples/config-15/integrations/automation.yaml @@ -0,0 +1 @@ +automation: !include ../automations.yaml diff --git a/api/tests/samples/config-15/integrations/media_player.yaml b/api/tests/samples/config-15/integrations/media_player.yaml new file mode 100644 index 0000000..037e661 --- /dev/null +++ b/api/tests/samples/config-15/integrations/media_player.yaml @@ -0,0 +1 @@ +# media_player: !include_dir_list ../entities/media_players diff --git a/api/tests/samples/config-16/automations.yaml b/api/tests/samples/config-16/automations.yaml new file mode 100644 index 0000000..e125729 --- /dev/null +++ b/api/tests/samples/config-16/automations.yaml @@ -0,0 +1,21 @@ +- alias: UI 1 + description: Example + mode: single + trigger: + - platform: homeassistant + event: start + condition: [] + action: + - service: counter.increment + data: {} + target: + entity_id: counter.up_times +- alias: UI 2 + description: "" + trigger: + - platform: sun + event: sunrise + offset: 0 + condition: [] + action: [] + mode: single diff --git a/api/tests/samples/config-16/configuration.yaml b/api/tests/samples/config-16/configuration.yaml new file mode 100644 index 0000000..0a9299f --- /dev/null +++ b/api/tests/samples/config-16/configuration.yaml @@ -0,0 +1,2 @@ +homeassistant: + packages: !include_dir_named integrations diff --git a/api/tests/samples/config-16/integrations/automation.yaml b/api/tests/samples/config-16/integrations/automation.yaml new file mode 100644 index 0000000..baad389 --- /dev/null +++ b/api/tests/samples/config-16/integrations/automation.yaml @@ -0,0 +1 @@ +automation: !include ../automations.yaml diff --git a/api/tests/samples/config-16/integrations/media_player.yaml b/api/tests/samples/config-16/integrations/media_player.yaml new file mode 100644 index 0000000..315b0ff --- /dev/null +++ b/api/tests/samples/config-16/integrations/media_player.yaml @@ -0,0 +1 @@ +media_player: diff --git a/api/tests/samples/config-17/automations.yaml b/api/tests/samples/config-17/automations.yaml new file mode 100644 index 0000000..e125729 --- /dev/null +++ b/api/tests/samples/config-17/automations.yaml @@ -0,0 +1,21 @@ +- alias: UI 1 + description: Example + mode: single + trigger: + - platform: homeassistant + event: start + condition: [] + action: + - service: counter.increment + data: {} + target: + entity_id: counter.up_times +- alias: UI 2 + description: "" + trigger: + - platform: sun + event: sunrise + offset: 0 + condition: [] + action: [] + mode: single diff --git a/api/tests/samples/config-17/configuration.yaml b/api/tests/samples/config-17/configuration.yaml new file mode 100644 index 0000000..0a9299f --- /dev/null +++ b/api/tests/samples/config-17/configuration.yaml @@ -0,0 +1,2 @@ +homeassistant: + packages: !include_dir_named integrations diff --git a/api/tests/samples/config-17/entities/file1.yaml b/api/tests/samples/config-17/entities/file1.yaml new file mode 100644 index 0000000..efdaedb --- /dev/null +++ b/api/tests/samples/config-17/entities/file1.yaml @@ -0,0 +1 @@ +- platform: media \ No newline at end of file diff --git a/api/tests/samples/config-17/integrations/automation.yaml b/api/tests/samples/config-17/integrations/automation.yaml new file mode 100644 index 0000000..baad389 --- /dev/null +++ b/api/tests/samples/config-17/integrations/automation.yaml @@ -0,0 +1 @@ +automation: !include ../automations.yaml diff --git a/api/tests/samples/config-17/integrations/binary_sensors.yaml b/api/tests/samples/config-17/integrations/binary_sensors.yaml new file mode 100644 index 0000000..e195364 --- /dev/null +++ b/api/tests/samples/config-17/integrations/binary_sensors.yaml @@ -0,0 +1,16 @@ +- platform: ping + host: 192.168.0.119 + name: "Ping Pc Tv" + scan_interval: 10 +- platform: ping + host: 192.168.0.181 + name: "Ping Living Room Tv" + scan_interval: 10 +- platform: ping + host: 192.168.0.100 + name: "Ping Printer" + scan_interval: 15 +- platform: ping + host: 192.168.0.177 + name: "Ping Broadlink" + scan_interval: 15 diff --git a/api/tests/samples/config-17/integrations/media_player.yaml b/api/tests/samples/config-17/integrations/media_player.yaml new file mode 100644 index 0000000..e813406 --- /dev/null +++ b/api/tests/samples/config-17/integrations/media_player.yaml @@ -0,0 +1 @@ +media_player: !include_dir_list ../entities/media_players diff --git a/api/tests/unittests/automations/test_loader.py b/api/tests/unittests/automations/test_loader.py index bbce19b..e4816dd 100644 --- a/api/tests/unittests/automations/test_loader.py +++ b/api/tests/unittests/automations/test_loader.py @@ -10,7 +10,6 @@ from src.automations.tags import TagManager from src.automations.types import ExtenededAutomation from src.hass_config.loader import HassConfig from tests.utils import ( - HA_CONFIG14_EXAMPLE, HA_CONFIG2_EXAMPLE, HA_CONFIG3_EXAMPLE, HA_CONFIG4_EXAMPLE, @@ -23,6 +22,10 @@ from tests.utils import ( HA_CONFIG11_EXAMPLE, HA_CONFIG12_EXAMPLE, HA_CONFIG13_EXAMPLE, + HA_CONFIG14_EXAMPLE, + HA_CONFIG15_EXAMPLE, + HA_CONFIG16_EXAMPLE, + HA_CONFIG17_EXAMPLE, HA_CONFIG_EXAMPLE, ) @@ -164,6 +167,9 @@ class loader_tests(TestCase): (HA_CONFIG12_EXAMPLE, 4), (HA_CONFIG13_EXAMPLE, 4), (HA_CONFIG14_EXAMPLE, 1), + (HA_CONFIG15_EXAMPLE, 1), + (HA_CONFIG16_EXAMPLE, 1), + (HA_CONFIG17_EXAMPLE, 1), ]: with self.subTest(config_name=ha_path.name, expected=expected): hass_config = HassConfig(ha_path) diff --git a/api/tests/utils.py b/api/tests/utils.py index 5425a99..9f09575 100644 --- a/api/tests/utils.py +++ b/api/tests/utils.py @@ -24,6 +24,9 @@ HA_CONFIG11_EXAMPLE = SAMPLES_FOLDER / "config-11" HA_CONFIG12_EXAMPLE = SAMPLES_FOLDER / "config-12" HA_CONFIG13_EXAMPLE = SAMPLES_FOLDER / "config-13" HA_CONFIG14_EXAMPLE = SAMPLES_FOLDER / "config-14" +HA_CONFIG15_EXAMPLE = SAMPLES_FOLDER / "config-15" +HA_CONFIG16_EXAMPLE = SAMPLES_FOLDER / "config-16" +HA_CONFIG17_EXAMPLE = SAMPLES_FOLDER / "config-17" def get_example_automation_loader(