moved sleep function
This commit is contained in:
@@ -29,6 +29,7 @@ class ADSubsystem:
|
||||
name = f'_{self.__class__.__name__.lower()}'
|
||||
self.logger = getLogger(f'AppDaemon.{name}')
|
||||
self.create_task = self.AD.create_task
|
||||
self.sleep = self.AD.context.sleep
|
||||
|
||||
def __enter__(self):
|
||||
self.logger.debug(f'Starting {self.__class__.__name__}')
|
||||
@@ -41,16 +42,6 @@ class ADSubsystem:
|
||||
def stopping(self) -> bool:
|
||||
return self.stop.is_set()
|
||||
|
||||
async def sleep(self, delay: float):
|
||||
"""Wrapper function for asyncio.sleep that suppresses and logs a task cancellation"""
|
||||
try:
|
||||
if not self.stopping:
|
||||
await asyncio.sleep(delay)
|
||||
else:
|
||||
self.logger.debug('Skipping sleep due to stop event')
|
||||
except asyncio.CancelledError:
|
||||
self.logger.debug('Cancelled during sleep')
|
||||
|
||||
|
||||
@dataclass
|
||||
class Utility(ADSubsystem):
|
||||
@@ -102,8 +93,8 @@ class Plugin(ADSubsystem):
|
||||
)
|
||||
loop_time = perf_counter()
|
||||
|
||||
# if self.state['update_count'] == 2:
|
||||
# raise ValueError('fake error')
|
||||
if self.state['update_count'] == 2:
|
||||
raise ValueError('fake error')
|
||||
|
||||
await self.sleep(self.update_rate)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user