Adapt lights simultaneously instead of one by one (#529)

* Update switch.py

* Update test_switch.py

* Revert "Update test_switch.py"

This reverts commit 87ea5243b9.

* remove unnecessary create_task

* remove unneeded len()

* Revert "remove unnecessary create_task"

This reverts commit 2c5da6d739.

* use `hass.async_create_task`

---------

Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
Co-authored-by: Bas Nijholt <bas@nijho.lt>
This commit is contained in:
Benjamin Auquite 2023-08-05 23:19:18 -05:00 committed by GitHub
commit fec50ad526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1399,7 +1399,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
adapt_color = self.adapt_color_switch.is_on
assert isinstance(adapt_brightness, bool)
assert isinstance(adapt_color, bool)
tasks = []
for light in filtered_lights:
manually_controlled = (
self._take_over_control
@ -1446,7 +1446,13 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
transition,
context.id,
)
await self._adapt_light(light, context, transition, force=force)
coro = self._adapt_light(light, context, transition, force=force)
task = self.hass.async_create_task(
coro,
)
tasks.append(task)
if tasks:
await asyncio.gather(*tasks)
async def _respond_to_off_to_on_event(self, entity_id: str, event: Event) -> None:
assert not self.manager.is_proactively_adapting(event.context.id)