async def test_service_calls_task_cancellation(hass):
    """Tests if the task that wraps ongoing adaptation service calls gets cancelled."""
    _, switch = await setup_switch(hass, {})
    entity_id = "test_id"

    task = asyncio.ensure_future(asyncio.sleep(1))
    switch.manager.adaptation_tasks_brightness[entity_id] = task

    switch.manager.cancel_ongoing_adaptation_calls(entity_id)

    with contextlib.suppress(asyncio.CancelledError):
        await task

    assert task.cancelled()
Tests if the task that wraps ongoing adaptation service calls gets cancelled.
tests/test_switch.py