diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index ba7eb1a7..93f19e48 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -27,9 +27,13 @@ jobs: - python-version: "3.10" core-version: "2023.4.6" - python-version: "3.10" - core-version: "2023.5.2" + core-version: "2023.5.4" - python-version: "3.11" - core-version: "2023.6.1" + core-version: "2023.6.3" + - python-version: "3.11" + core-version: "2023.7.3" + - python-version: "3.11" + core-version: "2023.8.1" - python-version: "3.11" core-version: "dev" steps: diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 150f2ef4..af69f21f 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -2013,11 +2013,9 @@ class AdaptiveLightingManager: # Don't await to avoid blocking the service call. # Assign to a variable only to await in tests. - self.adaptation_tasks.add( - asyncio.create_task( - switch.execute_cancellable_adaptation_calls(adaptation_data), - ), - ) + coro = switch.execute_cancellable_adaptation_calls(adaptation_data) + task = self.hass.async_create_task(coro) + self.adaptation_tasks.add(task) # Remove tasks that are done if done_tasks := [t for t in self.adaptation_tasks if t.done()]: self.adaptation_tasks.difference_update(done_tasks) diff --git a/tests/test_switch.py b/tests/test_switch.py index 4744f878..e0127ecf 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -766,6 +766,7 @@ async def test_auto_reset_manual_control(hass): async def update(): await switch._update_attrs_and_maybe_adapt_lights(context=context, transition=0) + await asyncio.gather(*switch.manager.adaptation_tasks) await hass.async_block_till_done() async def turn_light(state, **kwargs): @@ -796,10 +797,10 @@ async def test_auto_reset_manual_control(hass): ) # Do a couple of quick changes and check that light is not reset - for i in range(3): + for i in range(15): # do 15 changes to get to >0.1s _LOGGER.debug("Quick change %s", i) await turn_light(True, brightness=(i + 1) * 20) - await asyncio.sleep(0.05) # Less than 0.1 + await asyncio.sleep(0.01) # Less than 0.1 assert manual_control[light.entity_id] await update()