Skip to content

Commit 9e85bb9

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 9e85bb9

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Diff for: aiohue/v2/controllers/groups.py

+25
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,29 @@ 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+
None: STOP (this immediately stops any dimming transition)
155+
> 0: UP,
156+
< 0: DOWN
157+
"""
158+
if brightness_delta in (None, 0):
159+
dimming_delta = DimmingDeltaFeaturePut(action=DeltaAction.STOP)
160+
else:
161+
dimming_delta = DimmingDeltaFeaturePut(
162+
action=DeltaAction.UP if brightness_delta > 0 else DeltaAction.DOWN,
163+
brightness_delta=abs(brightness_delta),
164+
)
165+
166+
update_obj = GroupedLightPut()
167+
update_obj.dimming_delta = dimming_delta
168+
await self.update(id, update_obj)
169+
145170

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

Diff for: aiohue/v2/controllers/lights.py

+25
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,26 @@ 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+
None: STOP (this immediately stops any dimming transition)
114+
> 0: UP,
115+
< 0: DOWN
116+
"""
117+
if brightness_delta in (None, 0):
118+
dimming_delta = DimmingDeltaFeaturePut(action=DeltaAction.STOP)
119+
else:
120+
dimming_delta = DimmingDeltaFeaturePut(
121+
action=DeltaAction.UP if brightness_delta > 0 else DeltaAction.DOWN,
122+
brightness_delta=abs(brightness_delta),
123+
)
124+
125+
update_obj = LightPut()
126+
update_obj.dimming_delta = dimming_delta
127+
await self.update(id, update_obj)

0 commit comments

Comments
 (0)