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)