partial support
This commit is contained in:
1 parent
30a6f2ca6e
commit
80bfbdab80
21 files changed
+52
-213
No files matched your search
@@ -1,3 +1,4 @@
|
||||
from itertools import chain
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterator, Tuple, Union
|
||||
|
||||
@@ -25,25 +26,45 @@ def extract_automation_paths(
|
||||
hass_config: HassConfig,
|
||||
) -> Iterator[Tuple[str, str]]:
|
||||
found = False
|
||||
for key, value in extract_automation_keys(hass_config):
|
||||
logger.info(f"Loading automations from '{key}'")
|
||||
|
||||
for config_key, automation_path in chain(
|
||||
extract_automation_root_paths(hass_config), extract_package_automation_paths(hass_config)
|
||||
):
|
||||
found = True
|
||||
if isinstance(value, IncludedYamlDir): # type: ignore
|
||||
yield key, str(value.path.relative_to(hass_config.root_path))
|
||||
else:
|
||||
logger.warning(f"found an invalid type in {key}!")
|
||||
yield config_key, automation_path
|
||||
|
||||
if not found:
|
||||
yield "", "automations.yaml"
|
||||
|
||||
|
||||
def extract_package_automation_paths(hass_config: HassConfig):
|
||||
if homeassistant_config := hass_config.configurations.get("homeassistant", None):
|
||||
if isinstance(homeassistant_config, IncludedYamlDir): # type: ignore
|
||||
homeassistant_config_d = homeassistant_config.to_normalized_json()
|
||||
elif isinstance(homeassistant_config, dict):
|
||||
homeassistant_config_d = homeassistant_config
|
||||
def extract_automation_root_paths(
|
||||
hass_config: HassConfig,
|
||||
) -> Iterator[Tuple[str, str]]:
|
||||
for key, value in extract_automation_keys(hass_config):
|
||||
logger.info(f"Loading automations from '{key}'")
|
||||
if isinstance(value, IncludedYamlDir): # type: ignore
|
||||
yield key, str(value.path.relative_to(hass_config.root_path))
|
||||
elif isinstance(value, list):
|
||||
logger.warning(f"Failed to load from '{key}' as no support for inline automations yet.")
|
||||
else:
|
||||
raise AssertionError("configurations.homeassistant must be a dictionary!")
|
||||
logger.warning(f"found an invalid type in {key}!")
|
||||
|
||||
|
||||
def extract_package_automation_paths(hass_config: HassConfig) -> Iterator[Tuple[str, str]]:
|
||||
for package_name, package_data in hass_config.pacakges.items():
|
||||
if not isinstance(package_data, dict):
|
||||
logger.warning(f"The package {package_name} is incorrectly configured!")
|
||||
else:
|
||||
if automations := package_data.get("automation", None):
|
||||
logger.info(f"Loading automations from package '{package_name}'")
|
||||
if isinstance(automations, IncludedYamlDir): # type: ignore
|
||||
yield package_name, str(automations.path.relative_to(hass_config.root_path))
|
||||
elif isinstance(automations, list):
|
||||
logger.warning(
|
||||
f"Failed to load from '{package_name}' as no support for inline automations yet."
|
||||
)
|
||||
else:
|
||||
logger.warning(f"found an invalid type in {package_name}!")
|
||||
|
||||
|
||||
def get_base_automation_key(hass_config: HassConfig):
|
||||
|
||||
@@ -115,7 +115,7 @@ class IncludedYamlDirNamed(NamedTuple):
|
||||
out = {}
|
||||
for path, data in load_dir_yaml(self.path):
|
||||
if out.get(path.name, None) is None:
|
||||
out[path.name] = data
|
||||
out[path.stem] = data
|
||||
else:
|
||||
raise AssertionError(
|
||||
f"expected {path.name} to be a unique file name but found a second file name in {path}"
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
- id: "base1"
|
||||
alias: BASE
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
- id: "base2"
|
||||
alias: base 2
|
||||
description: ""
|
||||
trigger:
|
||||
- platform: sun
|
||||
event: sunrise
|
||||
offset: 0
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,14 +0,0 @@
|
||||
id: "1659114822642"
|
||||
alias: On Home Down
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: shutdown
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
target:
|
||||
entity_id:
|
||||
- counter.up_times
|
||||
data: {}
|
||||
@@ -1,13 +0,0 @@
|
||||
id: "1659114647066"
|
||||
alias: HA Up
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
@@ -1,13 +0,0 @@
|
||||
id: "1659114647067"
|
||||
alias: Notify Washer
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
@@ -1,7 +0,0 @@
|
||||
- id: "mlist1"
|
||||
alias: Merged List 1
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,14 +0,0 @@
|
||||
- id: "mlist2"
|
||||
alias: Merged List 2
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
- id: "mlist3"
|
||||
alias: Merged List 3
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,14 +0,0 @@
|
||||
- id: "sublist3-mlist2"
|
||||
alias: Sublist 3 - Merged List 2
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
- id: "sublist3-mlist3"
|
||||
alias: Sublist 3 - Merged List 3
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,6 +1,6 @@
|
||||
package2:
|
||||
automation:
|
||||
- id: "package-ha"
|
||||
- id: "package2"
|
||||
alias: package ha
|
||||
description: Example package auto
|
||||
mode: single
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
- id: "base1"
|
||||
alias: BASE
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
- id: "base2"
|
||||
alias: base 2
|
||||
description: ""
|
||||
trigger:
|
||||
- platform: sun
|
||||
event: sunrise
|
||||
offset: 0
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,14 +0,0 @@
|
||||
id: "1659114822642"
|
||||
alias: On Home Down
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: shutdown
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
target:
|
||||
entity_id:
|
||||
- counter.up_times
|
||||
data: {}
|
||||
@@ -1,13 +0,0 @@
|
||||
id: "1659114647066"
|
||||
alias: HA Up
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
@@ -1,13 +0,0 @@
|
||||
id: "1659114647067"
|
||||
alias: Notify Washer
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
@@ -1,7 +0,0 @@
|
||||
- id: "mlist1"
|
||||
alias: Merged List 1
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,14 +0,0 @@
|
||||
- id: "mlist2"
|
||||
alias: Merged List 2
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
- id: "mlist3"
|
||||
alias: Merged List 3
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,14 +0,0 @@
|
||||
- id: "sublist3-mlist2"
|
||||
alias: Sublist 3 - Merged List 2
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
- id: "sublist3-mlist3"
|
||||
alias: Sublist 3 - Merged List 3
|
||||
description: ""
|
||||
trigger: []
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -1,5 +1,5 @@
|
||||
automation:
|
||||
- id: "package-ha"
|
||||
- id: "package-sub"
|
||||
alias: package ha
|
||||
description: Example package auto
|
||||
mode: single
|
||||
|
||||
@@ -10,11 +10,14 @@ from src.automations.tags import TagManager
|
||||
from src.automations.types import ExtenededAutomation
|
||||
from src.hass_config.loader import HassConfig
|
||||
from tests.utils import (
|
||||
HA_CONFIG10_EXAMPLE,
|
||||
HA_CONFIG2_EXAMPLE,
|
||||
HA_CONFIG3_EXAMPLE,
|
||||
HA_CONFIG4_EXAMPLE,
|
||||
HA_CONFIG5_EXAMPLE,
|
||||
HA_CONFIG6_EXAMPLE,
|
||||
HA_CONFIG7_EXAMPLE,
|
||||
HA_CONFIG8_EXAMPLE,
|
||||
HA_CONFIG9_EXAMPLE,
|
||||
HA_CONFIG_EXAMPLE,
|
||||
)
|
||||
@@ -149,9 +152,12 @@ class loader_tests(TestCase):
|
||||
(HA_CONFIG4_EXAMPLE, 1),
|
||||
(HA_CONFIG5_EXAMPLE, 3),
|
||||
(HA_CONFIG6_EXAMPLE, 4),
|
||||
(HA_CONFIG7_EXAMPLE, 1),
|
||||
(HA_CONFIG8_EXAMPLE, 1),
|
||||
(HA_CONFIG9_EXAMPLE, 1),
|
||||
(HA_CONFIG10_EXAMPLE, 1),
|
||||
]:
|
||||
with self.subTest(ha_path=ha_path, expected=expected):
|
||||
with self.subTest(config_name=ha_path.name, expected=expected):
|
||||
hass_config = HassConfig(ha_path)
|
||||
paths = list(extract_automation_paths(hass_config))
|
||||
self.assertEqual(len(paths), expected)
|
||||
@@ -12,6 +12,7 @@ from src.errors import ErrorSet
|
||||
from src.hass_config.loader import HassConfig
|
||||
from tests.utils import (
|
||||
HA_CONFIG6_EXAMPLE,
|
||||
HA_CONFIG8_EXAMPLE,
|
||||
HA_CONFIG_EXAMPLE,
|
||||
create_copy_of_example_config,
|
||||
)
|
||||
@@ -327,3 +328,9 @@ class manager_tests(TestWithDB):
|
||||
auto.tags,
|
||||
{},
|
||||
)
|
||||
|
||||
def test_load_pacakges(self):
|
||||
_, automation_manager = self.get_manager(HA_CONFIG8_EXAMPLE)
|
||||
automation_manager.reload()
|
||||
auto = automation_manager.get("package-sub")
|
||||
self.assertEqual(auto.configuration_key, "pacakage2")
|
||||
@@ -19,6 +19,7 @@ HA_CONFIG6_EXAMPLE = SAMPLES_FOLDER / "config-6"
|
||||
HA_CONFIG7_EXAMPLE = SAMPLES_FOLDER / "config-7"
|
||||
HA_CONFIG8_EXAMPLE = SAMPLES_FOLDER / "config-8"
|
||||
HA_CONFIG9_EXAMPLE = SAMPLES_FOLDER / "config-9"
|
||||
HA_CONFIG10_EXAMPLE = SAMPLES_FOLDER / "config-10"
|
||||
|
||||
|
||||
def get_example_automation_loader(
|
||||
|
||||
Reference in new issue
Block a user