package setup work
This commit is contained in:
1 parent
ddbd780560
commit
30a6f2ca6e
28 files changed
+85
-150
No files matched your search
@@ -36,6 +36,16 @@ def extract_automation_paths(
|
||||
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
|
||||
else:
|
||||
raise AssertionError("configurations.homeassistant must be a dictionary!")
|
||||
|
||||
|
||||
def get_base_automation_key(hass_config: HassConfig):
|
||||
found_any = False
|
||||
for key, value in extract_automation_keys(hass_config):
|
||||
|
||||
@@ -2,7 +2,7 @@ from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from src.automations.tags import TagManager
|
||||
from src.yaml_serializer import IncludedYaml, load_yaml
|
||||
from src.yaml_serializer import IncludedYaml, IncludedYamlDir, load_yaml
|
||||
|
||||
|
||||
class HassConfig:
|
||||
@@ -14,6 +14,29 @@ class HassConfig:
|
||||
with self.get_configuration_path().open("r") as f:
|
||||
return dict(load_yaml(f, root_path=self.root_path)) # type: ignore
|
||||
|
||||
@property
|
||||
def homeassistant(self) -> dict:
|
||||
if homeassistant_config := self.configurations.get("homeassistant", None):
|
||||
if isinstance(homeassistant_config, IncludedYamlDir): # type: ignore
|
||||
homeassistant_config = homeassistant_config.to_normalized_json()
|
||||
if isinstance(homeassistant_config, dict):
|
||||
return homeassistant_config
|
||||
else:
|
||||
raise AssertionError("configurations.homeassistant must be a dictionary!")
|
||||
return {}
|
||||
|
||||
@property
|
||||
def pacakges(self) -> dict:
|
||||
if packages_config := self.homeassistant.get("packages", None):
|
||||
if isinstance(packages_config, IncludedYamlDir): # type: ignore
|
||||
packages_config = packages_config.to_normalized_json()
|
||||
if isinstance(packages_config, dict):
|
||||
return packages_config
|
||||
else:
|
||||
raise AssertionError("configurations.homeassistant.packages must be a dictionary!")
|
||||
|
||||
return {}
|
||||
|
||||
@property
|
||||
def automation_tags(self) -> TagManager:
|
||||
tag_path = self.get_automation_tags_path()
|
||||
|
||||
@@ -81,7 +81,7 @@ class IncludedYamlDirMergedNamed(NamedTuple):
|
||||
def to_normalized_json(self):
|
||||
out = {}
|
||||
for path, data in load_dir_yaml(self.path):
|
||||
overlap = set(data.key()).intersection(set(out.keys()))
|
||||
overlap = set(data.keys()).intersection(set(out.keys()))
|
||||
if len(overlap) > 0:
|
||||
raise AssertionError(
|
||||
f"The keys {overlap} were found in more than 1 file, cannot handle overlapping keys due to undefined behavior expectation. See {path}"
|
||||
@@ -114,7 +114,7 @@ class IncludedYamlDirNamed(NamedTuple):
|
||||
def to_normalized_json(self):
|
||||
out = {}
|
||||
for path, data in load_dir_yaml(self.path):
|
||||
if out.get(path.name, None):
|
||||
if out.get(path.name, None) is None:
|
||||
out[path.name] = data
|
||||
else:
|
||||
raise AssertionError(
|
||||
|
||||
Reference in new issue
Block a user