automation path loader

This commit is contained in:
ari committed 2022-08-14 01:00:19 -04:00
1 parent a746c4db3a
commit 579017d9ec
5 files changed
+79 -5

No files matched your search

@@ -0,0 +1,13 @@
# Loads default set of integrations. Do not remove.
default_config:
# Text to speech
tts:
- platform: google_translate
automation manual: !include_dir_list ./automations/include_dir_list
automation ui: !include automations/ui.yaml
automation: !include automations/base.yaml
automation cools: !include_dir_merge_list automations/include_dir_merge_list
script: !include scripts.yaml
scene: !include scenes.yaml
@@ -2,9 +2,17 @@ from pathlib import Path
from tempfile import mktemp
from unittest import TestCase
from src.automations_v2.loader import load_automation_path
from src.automations_v2.loader import extract_automation_paths, load_automation_path
from src.automations_v2.types import ExtenededAutomationData
from tests.utils import HA_CONFIG2_EXAMPLE, HA_CONFIG4_EXAMPLE
from src.hass_config.loader import HassConfig
from tests.utils import (
HA_CONFIG2_EXAMPLE,
HA_CONFIG3_EXAMPLE,
HA_CONFIG4_EXAMPLE,
HA_CONFIG5_EXAMPLE,
HA_CONFIG6_EXAMPLE,
HA_CONFIG_EXAMPLE,
)
class loader_tests(TestCase):
@@ -85,3 +93,17 @@ class loader_tests(TestCase):
file_path.unlink(missing_ok=True)
automations = list(load_automation_path(file_path))
self.assertEqual(len(automations), 0)
def test_extract_all_automation_files(self):
for ha_path, expected in [
(HA_CONFIG_EXAMPLE, 1),
(HA_CONFIG2_EXAMPLE, 1),
(HA_CONFIG3_EXAMPLE, 1),
(HA_CONFIG4_EXAMPLE, 3),
(HA_CONFIG5_EXAMPLE, 7),
(HA_CONFIG6_EXAMPLE, 8),
]:
with self.subTest(ha_path=ha_path, expected=expected):
hass_config = HassConfig(ha_path)
paths = list(extract_automation_paths(hass_config))
self.assertEqual(len(paths), expected)
+2
View File
@@ -15,6 +15,8 @@ HA_CONFIG_EXAMPLE = SAMPLES_FOLDER / "config"
HA_CONFIG2_EXAMPLE = SAMPLES_FOLDER / "config-2"
HA_CONFIG3_EXAMPLE = SAMPLES_FOLDER / "config-3"
HA_CONFIG4_EXAMPLE = SAMPLES_FOLDER / "config-4"
HA_CONFIG5_EXAMPLE = SAMPLES_FOLDER / "config-5"
HA_CONFIG6_EXAMPLE = SAMPLES_FOLDER / "config-6"
def get_example_automation_loader(