Send commands to Hue grouped lights all at once (#62973)

pull/62981/head
Marcel van der Veldt 2021-12-29 07:20:20 +01:00 committed by GitHub
parent 67663dd31a
commit bc7e51b992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 20 deletions

View File

@ -1,6 +1,7 @@
"""Support for Hue groups (room/zone)."""
from __future__ import annotations
import asyncio
from typing import Any
from aiohue.v2 import HueBridgeV2
@ -173,18 +174,22 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
# redirect all other feature commands to underlying lights
# note that this silently ignores params sent to light that are not supported
for light in self.controller.get_lights(self.resource.id):
await self.bridge.async_request_call(
self.api.lights.set_state,
light.id,
on=True,
brightness=brightness if light.supports_dimming else None,
color_xy=xy_color if light.supports_color else None,
color_temp=color_temp if light.supports_color_temperature else None,
transition_time=transition,
alert=AlertEffectType.BREATHE if flash is not None else None,
allowed_errors=ALLOWED_ERRORS,
)
await asyncio.gather(
*[
self.bridge.async_request_call(
self.api.lights.set_state,
light.id,
on=True,
brightness=brightness if light.supports_dimming else None,
color_xy=xy_color if light.supports_color else None,
color_temp=color_temp if light.supports_color_temperature else None,
transition_time=transition,
alert=AlertEffectType.BREATHE if flash is not None else None,
allowed_errors=ALLOWED_ERRORS,
)
for light in self.controller.get_lights(self.resource.id)
]
)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
@ -202,14 +207,18 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
return
# redirect all other feature commands to underlying lights
for light in self.controller.get_lights(self.resource.id):
await self.bridge.async_request_call(
self.api.lights.set_state,
light.id,
on=False,
transition_time=transition,
allowed_errors=ALLOWED_ERRORS,
)
await asyncio.gather(
*[
self.bridge.async_request_call(
self.api.lights.set_state,
light.id,
on=False,
transition_time=transition,
allowed_errors=ALLOWED_ERRORS,
)
for light in self.controller.get_lights(self.resource.id)
]
)
@callback
def on_update(self) -> None: