refactor + cleanup

This commit is contained in:
ari committed 2021-12-30 22:30:21 -05:00
1 parent 4a08956e1a
commit 381835c642
34 files changed
+724 -933

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
from pathlib import Path
from typing import List
from src.yaml_serializer import load_yaml
from src.yaml_serializer.types import IncludedYaml
class HassConfig:
def __init__(self, root_path: Path) -> None:
self.root_path = root_path
@property
def configurations(self) -> dict:
with (self.root_path / "configuration.yaml").open("r") as f:
return dict(load_yaml(f)) # type: ignore
@property
def automations(self) -> List[dict]:
automation_path = self.root_path / "automations.yaml"
config = self.configurations
if "automation" in config:
automation_ref = config["automation"]
if isinstance(automation_ref, IncludedYaml):
automation_path = automation_ref.path
else:
return list(config["automation"])
with automation_path.open("r") as f:
return list(load_yaml(f)) # type: ignore