Skip to content

Commit aa4d88b

Browse files
Add set_dimming_delta method
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.
1 parent 3821a01 commit aa4d88b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

aiohue/v2/controllers/groups.py

+19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
ColorFeaturePut,
1010
ColorPoint,
1111
ColorTemperatureFeaturePut,
12+
DeltaAction,
1213
DimmingFeaturePut,
14+
DimmingDeltaFeaturePut,
1315
DynamicsFeaturePut,
1416
OnFeature,
1517
)
@@ -142,6 +144,23 @@ async def set_state(
142144

143145
await self.update(id, update_obj)
144146

147+
async def set_dimming_delta(
148+
self, id: str, brightness_delta: float | None = None
149+
) -> None:
150+
"""
151+
Set brightness_delta value and action via DimmingDeltaFeature.
152+
153+
The action to be send depends on brightness_delta value:
154+
> 0: UP,
155+
< 0: DOWN,
156+
else: STOP (this immediately stops any dimming transition)
157+
"""
158+
if brightness_delta is not None:
159+
update_obj = GroupedLightPut()
160+
action = DeltaAction.DOWN if brightness_delta < 0 else DeltaAction.UP if brightness_delta > 0 else DeltaAction.STOP
161+
update_obj.dimming_delta = DimmingDeltaFeaturePut(action=action, brightness_delta=brightness_delta)
162+
await self.update(id, update_obj)
163+
145164

146165
class GroupsController(GroupedControllerBase[Union[Room, Zone, GroupedLight]]): # noqa: UP007
147166
"""Controller grouping resources of both room and zone."""

aiohue/v2/controllers/lights.py

+19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
ColorFeaturePut,
77
ColorPoint,
88
ColorTemperatureFeaturePut,
9+
DeltaAction,
910
DimmingFeaturePut,
11+
DimmingDeltaFeaturePut,
1012
DynamicsFeaturePut,
1113
EffectsFeaturePut,
1214
EffectStatus,
@@ -100,3 +102,20 @@ async def set_state(
100102
elif effect is not None:
101103
update_obj.effects = EffectsFeaturePut(effect=effect)
102104
await self.update(id, update_obj)
105+
106+
async def set_dimming_delta(
107+
self, id: str, brightness_delta: float | None = None
108+
) -> None:
109+
"""
110+
Set brightness_delta value and action via DimmingDeltaFeature.
111+
112+
The action to be send depends on brightness_delta value:
113+
> 0: UP,
114+
< 0: DOWN,
115+
else: STOP (this immediately stops any dimming transition)
116+
"""
117+
if brightness_delta is not None:
118+
update_obj = LightPut()
119+
action = DeltaAction.DOWN if brightness_delta < 0 else DeltaAction.UP if brightness_delta > 0 else DeltaAction.STOP
120+
update_obj.dimming_delta = DimmingDeltaFeaturePut(action=action, brightness_delta=brightness_delta)
121+
await self.update(id, update_obj)

0 commit comments

Comments
 (0)