fix task creation

This commit is contained in:
Jeffrey C. Ollie 2023-08-30 17:06:59 -05:00
parent a93031c35b
commit 1c64a8f2bd
Signed by: jeff
GPG key ID: 6F86035A6D97044E

View file

@ -89,9 +89,12 @@ class DeckHandler:
await self.deck.set_brightness(self.deck_config.brightness) await self.deck.set_brightness(self.deck_config.brightness)
tasks = [] tasks: list[asyncio.Task] = []
for key in range(self.deck.KEY_COUNT): 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) await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)
@ -286,11 +289,14 @@ async def _main(config: Config):
token=config.homeassistant.token, token=config.homeassistant.token,
) )
tasks = [homeassistant.start()] tasks = [asyncio.create_task(homeassistant.start(), name="homeassistant")]
for deck, deck_config in decks.values(): for deck, deck_config in decks.values():
deck_handler = DeckHandler(deck, deck_config, config, homeassistant) 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) await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)