more work
This commit is contained in:
@@ -19,26 +19,24 @@ class ADSubsystem:
|
||||
def __post_init__(self) -> None:
|
||||
name = f'_{self.__class__.__name__.lower()}'
|
||||
self.logger = getLogger(f'AppDaemon.{name}')
|
||||
self.AD.starts.append(self.start)
|
||||
if start_func := getattr(self, 'start', False):
|
||||
self.AD.starts.append(start_func)
|
||||
|
||||
@property
|
||||
def stopping(self) -> bool:
|
||||
return self.stop.is_set()
|
||||
|
||||
def start(self):
|
||||
raise NotImplementedError('Need to implement start for subsystem')
|
||||
|
||||
|
||||
@dataclass
|
||||
class Utility(ADSubsystem):
|
||||
loop_rate: float = 1.0
|
||||
loop_rate: float = 0.5
|
||||
|
||||
def start(self):
|
||||
self.AD.create_task(self.loop(), 'Utility loop')
|
||||
|
||||
async def loop(self):
|
||||
while not self.stopping:
|
||||
self.logger.info('Looping...')
|
||||
self.logger.debug('Looping...')
|
||||
await asyncio.sleep(self.loop_rate)
|
||||
self.logger.debug('Stopped utility loop')
|
||||
|
||||
@@ -46,14 +44,15 @@ class Utility(ADSubsystem):
|
||||
@dataclass
|
||||
class Plugin(ADSubsystem):
|
||||
state: dict[str, int] = field(default_factory=dict)
|
||||
update_rate: float = 30.0
|
||||
update_rate: float = 5.0
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
super().__post_init__()
|
||||
self.state['update_count'] = 0
|
||||
|
||||
def start(self):
|
||||
self.AD.create_task(self.periodic_self_udpate(), 'Periodic plugin update')
|
||||
self.AD.create_task(self.periodic_self_udpate(),
|
||||
'Periodic plugin update')
|
||||
|
||||
async def periodic_self_udpate(self):
|
||||
while not self.stopping:
|
||||
@@ -73,6 +72,7 @@ class AppDaemon:
|
||||
starts: list[Callable] = field(default_factory=list)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
self.logger = logging.getLogger('AppDaemon')
|
||||
self.utility = Utility(self, self.context.stop_event)
|
||||
self.plugins['dummy'] = Plugin(self, self.context.stop_event)
|
||||
|
||||
@@ -81,6 +81,8 @@ class AppDaemon:
|
||||
|
||||
def start(self):
|
||||
for start in self.starts:
|
||||
subsystem = start.__qualname__.split('.')[0]
|
||||
self.logger.debug(f'Starting {subsystem}')
|
||||
start()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user