diff --git a/conf/apps/food-repo/src/food/meal.py b/conf/apps/food-repo/src/food/menu.py similarity index 96% rename from conf/apps/food-repo/src/food/meal.py rename to conf/apps/food-repo/src/food/menu.py index 510f683..1089780 100644 --- a/conf/apps/food-repo/src/food/meal.py +++ b/conf/apps/food-repo/src/food/menu.py @@ -12,7 +12,7 @@ class GreenEggs(Eggs): @dataclass -class Meal: +class Menu: dishes: List[ADAPI] = field(init=False) def __post_init__(self): diff --git a/conf/apps/restaurant/restaurant.py b/conf/apps/restaurant/restaurant.py index ce52f5a..557f7bf 100644 --- a/conf/apps/restaurant/restaurant.py +++ b/conf/apps/restaurant/restaurant.py @@ -1,11 +1,16 @@ +from dataclasses import dataclass, field + from appdaemon.adapi import ADAPI -from food import Eggs -from food.meal import Meal +from food.menu import Menu +@dataclass(init=False) class Restaurant(ADAPI): + menu: Menu = field(default=Menu) + def initialize(self): - meal = Meal() - eggs: Eggs = meal.dishes[0] - self.log(f"{self.__class__.__name__} initialized with {eggs}") - self.log(f"Last dish: {meal.dishes[-1]}") + self.log(f'{self.__class__.__name__} initialized') + + log_str = ', '.join(f'{d.name}' for d in self.menu.dishes) + + self.log(f'Menu: {log_str}') diff --git a/src/ad_test/test_file_change.py b/src/ad_test/test_file_change.py index 90d6e43..a902bdf 100644 --- a/src/ad_test/test_file_change.py +++ b/src/ad_test/test_file_change.py @@ -3,7 +3,7 @@ import logging import re from pathlib import Path -import food.meal +import food.menu import pytest from appdaemon.appdaemon import AppDaemon from git import Repo @@ -33,7 +33,7 @@ def insert_import_error(path: Path): def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo): assert isinstance(ad, AppDaemon) - module_file = Path(food.meal.__file__) + module_file = Path(food.menu.__file__) modify_file(module_file) try: @@ -52,7 +52,7 @@ def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo): assert isinstance(ad, AppDaemon) - module_file = Path(food.meal.__file__) + module_file = Path(food.menu.__file__) insert_import_error(module_file) try: diff --git a/src/ad_test/test_startup.py b/src/ad_test/test_startup.py index 4e394d9..9aea1c3 100644 --- a/src/ad_test/test_startup.py +++ b/src/ad_test/test_startup.py @@ -15,8 +15,7 @@ def validate_app_dependencies(ad: AppDaemon): def validate_module_dependencies(ad: AppDaemon): graph = ad.app_management.module_dependencies - assert 'food' in graph['restaurant'] - assert 'food.meal' in graph['restaurant'] + assert 'food.menu' in graph['restaurant'] def validate_module_load_order(ad: AppDaemon, module_load_order: List[str]):