diff --git a/conf/apps/food-repo/src/food/__init__.py b/conf/apps/food-repo/src/food/__init__.py index 0f35724..ebac54a 100644 --- a/conf/apps/food-repo/src/food/__init__.py +++ b/conf/apps/food-repo/src/food/__init__.py @@ -2,4 +2,4 @@ from .eggs import Eggs from .ham import Ham from .spam import Spam -__all__ = ["Eggs", "Ham", "Spam"] +__all__ = ['Eggs', 'Ham', 'Spam'] diff --git a/conf/apps/food-repo/src/food/base.py b/conf/apps/food-repo/src/food/base.py new file mode 100644 index 0000000..4764e74 --- /dev/null +++ b/conf/apps/food-repo/src/food/base.py @@ -0,0 +1,6 @@ +from dataclasses import dataclass + + +@dataclass +class FoodItem: + taste: str diff --git a/conf/apps/food-repo/src/food/eggs.py b/conf/apps/food-repo/src/food/eggs.py index 982c26b..f135698 100644 --- a/conf/apps/food-repo/src/food/eggs.py +++ b/conf/apps/food-repo/src/food/eggs.py @@ -1,6 +1,8 @@ -from appdaemon.adapi import ADAPI +from dataclasses import dataclass + +from .base import FoodItem -class Eggs(ADAPI): - def initialize(self): - self.log(f"{self.__class__.__name__} Initialized") +@dataclass +class Eggs(FoodItem): + taste: str = 'good' diff --git a/conf/apps/food-repo/src/food/ham.py b/conf/apps/food-repo/src/food/ham.py index 0924527..5a9b2a0 100644 --- a/conf/apps/food-repo/src/food/ham.py +++ b/conf/apps/food-repo/src/food/ham.py @@ -1,6 +1,8 @@ -from appdaemon.adapi import ADAPI +from dataclasses import dataclass + +from .base import FoodItem -class Ham(ADAPI): - def initialize(self): - self.log(f"{self.__class__.__name__} Initialized") +@dataclass +class Ham(FoodItem): + taste: str = 'good' diff --git a/conf/apps/food-repo/src/food/menu.py b/conf/apps/food-repo/src/food/menu.py index 1089780..a8213df 100644 --- a/conf/apps/food-repo/src/food/menu.py +++ b/conf/apps/food-repo/src/food/menu.py @@ -1,8 +1,7 @@ from dataclasses import dataclass, field from typing import List -from appdaemon.adapi import ADAPI - +from .base import FoodItem from .eggs import Eggs from .ham import Ham @@ -13,7 +12,7 @@ class GreenEggs(Eggs): @dataclass class Menu: - dishes: List[ADAPI] = field(init=False) + dishes: List[FoodItem] = field(init=False) def __post_init__(self): self.dishes = [GreenEggs, Ham] diff --git a/conf/apps/food-repo/src/food/spam.py b/conf/apps/food-repo/src/food/spam.py index fdbd691..5ab242e 100644 --- a/conf/apps/food-repo/src/food/spam.py +++ b/conf/apps/food-repo/src/food/spam.py @@ -1,6 +1,8 @@ -from appdaemon.adapi import ADAPI +from dataclasses import dataclass + +from .base import FoodItem -class Spam(ADAPI): - def initialize(self): - self.log(f"{self.__class__.__name__} Initialized") +@dataclass +class Spam(FoodItem): + taste: str = 'bad' diff --git a/conf/apps/restaurant/restaurant.py b/conf/apps/food-repo/src/restaurant/restaurant.py similarity index 55% rename from conf/apps/restaurant/restaurant.py rename to conf/apps/food-repo/src/restaurant/restaurant.py index 557f7bf..faf143e 100644 --- a/conf/apps/restaurant/restaurant.py +++ b/conf/apps/food-repo/src/restaurant/restaurant.py @@ -1,16 +1,14 @@ -from dataclasses import dataclass, field - from appdaemon.adapi import ADAPI from food.menu import Menu -@dataclass(init=False) class Restaurant(ADAPI): - menu: Menu = field(default=Menu) + menu: Menu def initialize(self): self.log(f'{self.__class__.__name__} initialized') - log_str = ', '.join(f'{d.name}' for d in self.menu.dishes) + self.menu = Menu() + log_str = ', '.join(f'{d.__class__.__name__} [{d.taste}]' for d in self.menu.dishes) self.log(f'Menu: {log_str}') diff --git a/conf/apps/restaurant/restaurant.yaml b/conf/apps/food-repo/src/restaurant/restaurant.yaml similarity index 100% rename from conf/apps/restaurant/restaurant.yaml rename to conf/apps/food-repo/src/restaurant/restaurant.yaml diff --git a/src/ad_test/test_file_change.py b/src/ad_test/test_file_change.py index a902bdf..14c680a 100644 --- a/src/ad_test/test_file_change.py +++ b/src/ad_test/test_file_change.py @@ -41,7 +41,7 @@ def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo ad.loop.run_until_complete(asyncio.sleep(1.0)) module_load_order = get_load_order(caplog) - assert module_load_order == ['food.meal', 'restaurant'] + assert module_load_order == ['food.menu', 'restaurant'] reset_file(config_repo, module_file) ad.loop.run_until_complete(asyncio.sleep(1.0)) @@ -60,7 +60,7 @@ def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config ad.loop.run_until_complete(asyncio.sleep(1.0)) module_load_order = get_load_order(caplog) - assert module_load_order == ['food.meal', 'restaurant'] + assert module_load_order == ['food.menu', 'restaurant'] reset_file(config_repo, module_file) ad.loop.run_until_complete(asyncio.sleep(1.0))