restructure
This commit is contained in:
@@ -2,4 +2,4 @@ from .eggs import Eggs
|
|||||||
from .ham import Ham
|
from .ham import Ham
|
||||||
from .spam import Spam
|
from .spam import Spam
|
||||||
|
|
||||||
__all__ = ["Eggs", "Ham", "Spam"]
|
__all__ = ['Eggs', 'Ham', 'Spam']
|
||||||
|
|||||||
6
conf/apps/food-repo/src/food/base.py
Normal file
6
conf/apps/food-repo/src/food/base.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class FoodItem:
|
||||||
|
taste: str
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
from appdaemon.adapi import ADAPI
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from .base import FoodItem
|
||||||
|
|
||||||
|
|
||||||
class Eggs(ADAPI):
|
@dataclass
|
||||||
def initialize(self):
|
class Eggs(FoodItem):
|
||||||
self.log(f"{self.__class__.__name__} Initialized")
|
taste: str = 'good'
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from appdaemon.adapi import ADAPI
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from .base import FoodItem
|
||||||
|
|
||||||
|
|
||||||
class Ham(ADAPI):
|
@dataclass
|
||||||
def initialize(self):
|
class Ham(FoodItem):
|
||||||
self.log(f"{self.__class__.__name__} Initialized")
|
taste: str = 'good'
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from appdaemon.adapi import ADAPI
|
from .base import FoodItem
|
||||||
|
|
||||||
from .eggs import Eggs
|
from .eggs import Eggs
|
||||||
from .ham import Ham
|
from .ham import Ham
|
||||||
|
|
||||||
@@ -13,7 +12,7 @@ class GreenEggs(Eggs):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Menu:
|
class Menu:
|
||||||
dishes: List[ADAPI] = field(init=False)
|
dishes: List[FoodItem] = field(init=False)
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
self.dishes = [GreenEggs, Ham]
|
self.dishes = [GreenEggs, Ham]
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from appdaemon.adapi import ADAPI
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from .base import FoodItem
|
||||||
|
|
||||||
|
|
||||||
class Spam(ADAPI):
|
@dataclass
|
||||||
def initialize(self):
|
class Spam(FoodItem):
|
||||||
self.log(f"{self.__class__.__name__} Initialized")
|
taste: str = 'bad'
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
from dataclasses import dataclass, field
|
|
||||||
|
|
||||||
from appdaemon.adapi import ADAPI
|
from appdaemon.adapi import ADAPI
|
||||||
from food.menu import Menu
|
from food.menu import Menu
|
||||||
|
|
||||||
|
|
||||||
@dataclass(init=False)
|
|
||||||
class Restaurant(ADAPI):
|
class Restaurant(ADAPI):
|
||||||
menu: Menu = field(default=Menu)
|
menu: Menu
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.log(f'{self.__class__.__name__} initialized')
|
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}')
|
self.log(f'Menu: {log_str}')
|
||||||
@@ -41,7 +41,7 @@ def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo
|
|||||||
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
||||||
|
|
||||||
module_load_order = get_load_order(caplog)
|
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)
|
reset_file(config_repo, module_file)
|
||||||
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
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))
|
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
||||||
|
|
||||||
module_load_order = get_load_order(caplog)
|
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)
|
reset_file(config_repo, module_file)
|
||||||
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
||||||
|
|||||||
Reference in New Issue
Block a user