watching folders

This commit is contained in:
ari committed 2022-08-14 01:07:19 -04:00
1 parent 579017d9ec
commit e11f4deab5
3 files changed
+16 -2

No files matched your search

+5
View File
@@ -1,3 +1,4 @@
from curses.ascii import isdigit
from pathlib import Path from pathlib import Path
from typing import Any, Iterator, Union, Dict from typing import Any, Iterator, Union, Dict
from ..hass_config.loader import HassConfig from ..hass_config.loader import HassConfig
@@ -61,6 +62,10 @@ def load_automation_path(automation_path: Path) -> Iterator[ExtenededAutomationD
if not automation_path.exists(): if not automation_path.exists():
logger.warning(f"the file {automation_path} does not exists") logger.warning(f"the file {automation_path} does not exists")
return return
if automation_path.is_dir():
for f in extract_files(automation_path):
yield from load_automation_path(f)
else:
try: try:
with automation_path.open("r") as fp: with automation_path.open("r") as fp:
automations = load_yaml(fp) automations = load_yaml(fp)
@@ -1,5 +1,5 @@
from src.automations_v2.watcher import AutomationFileWatcher from src.automations_v2.automation_watcher import AutomationFileWatcher
from tests.utils import create_copy_of_example_config from tests.utils import HA_CONFIG6_EXAMPLE, create_copy_of_example_config
from .utils import TestWithDB from .utils import TestWithDB
@@ -30,6 +30,15 @@ class watcher_tests(TestWithDB):
watcher.start() watcher.start()
watcher.wait_until_next_reload(True) watcher.wait_until_next_reload(True)
self.assertEqual(self.db.count_automations(), 0) self.assertEqual(self.db.count_automations(), 0)
watcher.join()
def test_watch_folder(self):
example_folder = create_copy_of_example_config(HA_CONFIG6_EXAMPLE)
watcher = AutomationFileWatcher(example_folder / "automations", self.db_file)
watcher.start()
watcher.wait_until_next_reload(True)
self.assertEqual(self.db.count_automations(), 12)
watcher.join()
# def test_valid_changes(self): # def test_valid_changes(self):
# example_folder = create_copy_of_example_config() # example_folder = create_copy_of_example_config()