From 1c64a8f2bda3999255ba4160b8a447fb7b36710f Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Wed, 30 Aug 2023 17:06:59 -0500 Subject: [PATCH] fix task creation --- greendeck/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/greendeck/main.py b/greendeck/main.py index c9240c5..735d32b 100644 --- a/greendeck/main.py +++ b/greendeck/main.py @@ -89,9 +89,12 @@ class DeckHandler: await self.deck.set_brightness(self.deck_config.brightness) - tasks = [] + tasks: list[asyncio.Task] = [] for key in range(self.deck.KEY_COUNT): - tasks.append(self.initialize_key(key)) + tasks.append(asyncio.create_task(self.initialize_key(key))) + + for task in tasks: + task.add_done_callback(task_done_callback) await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED) @@ -286,11 +289,14 @@ async def _main(config: Config): token=config.homeassistant.token, ) - tasks = [homeassistant.start()] + tasks = [asyncio.create_task(homeassistant.start(), name="homeassistant")] for deck, deck_config in decks.values(): deck_handler = DeckHandler(deck, deck_config, config, homeassistant) - tasks.append(deck_handler.start()) + tasks.append(asyncio.create_task(deck_handler.start())) + + for task in tasks: + task.add_done_callback(task_done_callback) await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)