Skip to content

Commit fec50ad

Browse files
Adapt lights simultaneously instead of one by one (#529)
* Update switch.py * Update test_switch.py * Revert "Update test_switch.py" This reverts commit 87ea524. * remove unnecessary create_task * remove unneeded len() * Revert "remove unnecessary create_task" This reverts commit 2c5da6d. * use `hass.async_create_task` --------- Co-authored-by: Bas Nijholt <[email protected]> Co-authored-by: Bas Nijholt <[email protected]>
1 parent d44cb66 commit fec50ad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

custom_components/adaptive_lighting/switch.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ async def _update_attrs_and_maybe_adapt_lights(
13991399
adapt_color = self.adapt_color_switch.is_on
14001400
assert isinstance(adapt_brightness, bool)
14011401
assert isinstance(adapt_color, bool)
1402-
1402+
tasks = []
14031403
for light in filtered_lights:
14041404
manually_controlled = (
14051405
self._take_over_control
@@ -1446,7 +1446,13 @@ async def _update_attrs_and_maybe_adapt_lights(
14461446
transition,
14471447
context.id,
14481448
)
1449-
await self._adapt_light(light, context, transition, force=force)
1449+
coro = self._adapt_light(light, context, transition, force=force)
1450+
task = self.hass.async_create_task(
1451+
coro,
1452+
)
1453+
tasks.append(task)
1454+
if tasks:
1455+
await asyncio.gather(*tasks)
14501456

14511457
async def _respond_to_off_to_on_event(self, entity_id: str, event: Event) -> None:
14521458
assert not self.manager.is_proactively_adapting(event.context.id)

0 commit comments

Comments
 (0)