added food.meal
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
.pytest_cache
|
||||
*.egg-info
|
||||
19
conf/apps/food-repo/src/food/meal.py
Normal file
19
conf/apps/food-repo/src/food/meal.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
from .eggs import Eggs
|
||||
from .ham import Ham
|
||||
|
||||
|
||||
class GreenEggs(Eggs):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Meal:
|
||||
dishes: List[ADAPI] = field(init=False)
|
||||
|
||||
def __post_init__(self):
|
||||
self.dishes = [GreenEggs, Ham]
|
||||
@@ -1,7 +1,10 @@
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
from food import Eggs
|
||||
from food.meal import Meal
|
||||
|
||||
|
||||
class Restaurant(ADAPI):
|
||||
def initialize(self):
|
||||
self.log(f'{self.__class__.__name__} initialized with {Eggs}')
|
||||
meal = Meal()
|
||||
eggs: Eggs = meal.dishes[0]
|
||||
self.log(f'{self.__class__.__name__} initialized with {eggs}')
|
||||
|
||||
@@ -31,21 +31,6 @@ def ad_system(base_config) -> AppDaemon:
|
||||
return ad
|
||||
|
||||
|
||||
# def test_dependency_graph():
|
||||
# app_dir = Path('/home/john/conf/apps')
|
||||
# files = app_dir.rglob('*.yaml')
|
||||
# files = (f for f in files if f.stem != 'secrets' and f.stem != 'appdaemon')
|
||||
|
||||
# cfg = AllAppConfig.from_config_files(files)
|
||||
# graph = cfg.depedency_graph()
|
||||
# rev = cfg.reversed_dependency_graph()
|
||||
|
||||
# assert 'App1Foo' in graph['App2'], 'App2 is not dependent on App1Foo'
|
||||
# assert 'App2' in rev['App1Foo'], 'App1 is not a predicate of App1Foo'
|
||||
|
||||
# print(graph)
|
||||
|
||||
|
||||
async def delayed_stop(ad: AppDaemon, delay: float):
|
||||
await asyncio.sleep(delay)
|
||||
ad.stop()
|
||||
@@ -58,6 +43,17 @@ def get_load_order(caplog: pytest.LogCaptureFixture) -> List[str]:
|
||||
return record.args[0]
|
||||
|
||||
|
||||
def validate_app_dependencies(ad: AppDaemon):
|
||||
graph = ad.app_management.app_config.depedency_graph()
|
||||
assert 'hello_world' in graph['food_app']
|
||||
|
||||
|
||||
def validate_module_dependencies(ad: AppDaemon):
|
||||
graph = ad.app_management.module_dependencies
|
||||
assert 'food' in graph['restaurant']
|
||||
assert 'food.meal' in graph['restaurant']
|
||||
|
||||
|
||||
def validate_module_load_order(ad: AppDaemon, module_load_order: List[str]):
|
||||
dependency_graph = ad.app_management.module_dependencies
|
||||
for node, deps in dependency_graph.items():
|
||||
@@ -85,6 +81,9 @@ def test_startup(ad_system: AppDaemon, caplog: pytest.LogCaptureFixture):
|
||||
assert "Started 'hello_world'" in caplog.text
|
||||
assert 'App initialization complete' in caplog.text
|
||||
|
||||
validate_app_dependencies(ad_system)
|
||||
validate_module_dependencies(ad_system)
|
||||
|
||||
module_load_order = get_load_order(caplog)
|
||||
validate_module_load_order(ad_system, module_load_order)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user