Skip to content

Commit

Permalink
Add set_dimming_delta method
Browse files Browse the repository at this point in the history
This method sets the brightness_delta value and its action based on the
value to up/down/stop. This can be useful if someone wants to dim a light to
the max/min value within a dedicated transition time but stop the
transition  when for instance a btn was released.
  • Loading branch information
olsen-sorensen committed Oct 6, 2024
1 parent 3821a01 commit 3e0ba79
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions aiohue/v2/controllers/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
ColorFeaturePut,
ColorPoint,
ColorTemperatureFeaturePut,
DeltaAction,
DimmingFeaturePut,
DimmingDeltaFeaturePut,
DynamicsFeaturePut,
OnFeature,
)
Expand Down Expand Up @@ -142,6 +144,27 @@ async def set_state(

await self.update(id, update_obj)

async def set_dimming_delta(
self, id: str, brightness_delta: float | None = None
) -> None:
"""
Set brightness_delta value and action via DimmingDeltaFeature.
The action to be send depends on brightness_delta value:
> 0: UP,
< 0: DOWN,
else: STOP (this immediately stops any dimming transition)
"""
if brightness_delta is not None:
update_obj = GroupedLightPut()
action = DeltaAction.DOWN if brightness_delta < 0 else DeltaAction.UP if brightness_delta > 0 else DeltaAction.STOP
brightness_delta_clipped = abs(brightness_delta)
update_obj.dimming_delta = DimmingDeltaFeaturePut(
action=action,
brightness_delta=brightness_delta_clipped if action!=DeltaAction.STOP else None
)
await self.update(id, update_obj)


class GroupsController(GroupedControllerBase[Union[Room, Zone, GroupedLight]]): # noqa: UP007
"""Controller grouping resources of both room and zone."""
Expand Down
23 changes: 23 additions & 0 deletions aiohue/v2/controllers/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
ColorFeaturePut,
ColorPoint,
ColorTemperatureFeaturePut,
DeltaAction,
DimmingFeaturePut,
DimmingDeltaFeaturePut,
DynamicsFeaturePut,
EffectsFeaturePut,
EffectStatus,
Expand Down Expand Up @@ -100,3 +102,24 @@ async def set_state(
elif effect is not None:
update_obj.effects = EffectsFeaturePut(effect=effect)
await self.update(id, update_obj)

async def set_dimming_delta(
self, id: str, brightness_delta: float | None = None
) -> None:
"""
Set brightness_delta value and action via DimmingDeltaFeature.
The action to be send depends on brightness_delta value:
> 0: UP,
< 0: DOWN,
else: STOP (this immediately stops any dimming transition)
"""
if brightness_delta is not None:
update_obj = LightPut()
action = DeltaAction.DOWN if brightness_delta < 0 else DeltaAction.UP if brightness_delta > 0 else DeltaAction.STOP
brightness_delta_clipped = abs(brightness_delta)
update_obj.dimming_delta = DimmingDeltaFeaturePut(
action=action,
brightness_delta=brightness_delta_clipped if action!=DeltaAction.STOP else None
)
await self.update(id, update_obj)

0 comments on commit 3e0ba79

Please sign in to comment.