Skip to content

Commit

Permalink
Add missing parameters to the grouped_light set_state (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Mar 23, 2022
1 parent 8f24ddb commit cdc2278
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion aiohue/v2/controllers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def check_version(self, version: str) -> bool:

def require_version(self, version: str) -> None:
"""Raise exception if Bridge version is lower than given minimal version."""
if not self.require_version(version):
if not self.check_version(version):
raise BridgeSoftwareOutdated(
f"Bridge software version outdated. Minimal required version is {version}"
)
Expand Down
59 changes: 54 additions & 5 deletions aiohue/v2/controllers/groups.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
"""Controller holding and managing HUE group resources."""
from typing import TYPE_CHECKING, List, Type, Union

from ..models.feature import OnFeature
import asyncio
from typing import TYPE_CHECKING, List, Optional, Tuple, Type, Union

from ..models.feature import (
AlertEffectType,
AlertFeaturePut,
ColorFeaturePut,
ColorPoint,
ColorTemperatureFeaturePut,
DimmingFeaturePut,
DynamicsFeaturePut,
OnFeature,
)
from ..models.grouped_light import GroupedLight, GroupedLightPut
from ..models.light import Light
from ..models.resource import ResourceTypes
Expand Down Expand Up @@ -85,11 +95,50 @@ def get_lights(self, id: str) -> List[Light]:
return self._bridge.groups.zone.get_lights(zone.id)
return []

async def set_state(self, id: str, on: bool = True) -> None:
async def set_flash(self, id: str, short: bool = False) -> None:
"""Send Flash command to grouped_light."""
if short:
# redirect command to underlying lights
await asyncio.gather(
*[
self._bridge.lights.set_flash(
id=light.id,
short=True,
)
for light in self.get_lights(id)
]
)
return
await self.set_state(id, alert=AlertEffectType.BREATHE)

async def set_state(
self,
id: str,
on: Optional[bool] = None,
brightness: Optional[float] = None,
color_xy: Optional[Tuple[float, float]] = None,
color_temp: Optional[int] = None,
transition_time: Optional[int] = None,
alert: Optional[AlertEffectType] = None,
) -> None:
"""Set supported feature(s) to grouped_light resource."""
# Sending (color) commands to grouped_light was added in Bridge version 1.50.1950111030
self._bridge.config.require_version("1.50.1950111030")
await self.update(id, GroupedLightPut(on=OnFeature(on=on)))
update_obj = GroupedLightPut()
if on is not None:
update_obj.on = OnFeature(on=on)
if brightness is not None:
update_obj.dimming = DimmingFeaturePut(brightness=brightness)
if color_xy is not None:
update_obj.color = ColorFeaturePut(xy=ColorPoint(*color_xy))
if color_temp is not None:
update_obj.color_temperature = ColorTemperatureFeaturePut(mirek=color_temp)
if transition_time is not None:
update_obj.dynamics = DynamicsFeaturePut(duration=transition_time)
if alert is not None:
update_obj.alert = AlertFeaturePut(action=alert)

await self.update(id, update_obj)


class GroupsController(GroupedControllerBase[Union[Room, Zone, GroupedLight]]):
Expand Down
2 changes: 1 addition & 1 deletion aiohue/v2/controllers/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def set_flash(self, id: str, short: bool = False) -> None:
device = self.get_device(id)
await self._bridge.devices.set_identify(device.id)
else:
await self.set_state(id, on=True, alert=AlertEffectType.BREATHE)
await self.set_state(id, alert=AlertEffectType.BREATHE)

async def set_state(
self,
Expand Down

0 comments on commit cdc2278

Please sign in to comment.