Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dimming_delta support #417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)