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
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 in (None, 0):
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 in (None, 0):
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)