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 Dec 20, 2024
1 parent 3821a01 commit b25a585
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 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,31 @@ 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:
None: STOP (this immediately stops any dimming transition)
> 0: UP,
< 0: DOWN
"""
if brightness_delta is None:
dimming_delta = DimmingDeltaFeaturePut(
action=DeltaAction.STOP
)
else:
dimming_delta = DimmingDeltaFeaturePut(
action=DeltaAction.UP if brightness_delta > 0 else DeltaAction.Down,
brightness_delta=abs(brightness_delta)
)

update_obj = GroupedLightPut()
update_obj.dimming_delta = dimming_delta
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
27 changes: 27 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,28 @@ 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:
None: STOP (this immediately stops any dimming transition)
> 0: UP,
< 0: DOWN
"""
if brightness_delta is None:
dimming_delta = DimmingDeltaFeaturePut(
action=DeltaAction.STOP
)
else:
dimming_delta = DimmingDeltaFeaturePut(
action=DeltaAction.UP if brightness_delta > 0 else DeltaAction.Down,
brightness_delta=abs(brightness_delta)
)

update_obj = LightPut()
update_obj.dimming_delta = dimming_delta
await self.update(id, update_obj)

0 comments on commit b25a585

Please sign in to comment.