util.py 411 B

1234567891011121314151617
  1. """Library to handle connection with Switchbot."""
  2. import asyncio
  3. from collections.abc import Awaitable
  4. from typing import Any
  5. def execute_task(fut: Awaitable[Any]) -> None:
  6. """Execute task."""
  7. task = asyncio.create_task(fut)
  8. tasks = [task]
  9. def _cleanup_task(task: asyncio.Task[Any]) -> None:
  10. """Cleanup task."""
  11. tasks.remove(task)
  12. task.add_done_callback(_cleanup_task)