Skip to content

Commit e18f5c4

Browse files
committed
Provide effects on supported Philips Hue lights.
1 parent 3aaf797 commit e18f5c4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

zha/application/platforms/light/__init__.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,69 @@ class HueLight(Light):
991991
_REFRESH_INTERVAL = (180, 300)
992992

993993

994+
@STRICT_MATCH(
995+
cluster_handler_names=CLUSTER_HANDLER_ON_OFF,
996+
aux_cluster_handlers={
997+
CLUSTER_HANDLER_COLOR,
998+
CLUSTER_HANDLER_LEVEL,
999+
"philips_hue_cluster",
1000+
},
1001+
manufacturers={"Philips", "Signify Netherlands B.V."},
1002+
)
1003+
class HueEffectLight(HueLight):
1004+
# Supported effects and their ID used in commands
1005+
HUE_EFFECTS = {"candle": 1, "fireplace": 2, "prism": 3}
1006+
1007+
"""Representation of a HUE light with effects."""
1008+
1009+
def __init__(
1010+
self,
1011+
unique_id: str,
1012+
cluster_handlers: list[ClusterHandler],
1013+
endpoint: Endpoint,
1014+
device: Device,
1015+
**kwargs,
1016+
) -> None:
1017+
"""Initialize the ZHA light."""
1018+
super().__init__(unique_id, cluster_handlers, endpoint, device, **kwargs)
1019+
self._hue_cluster = self.cluster_handlers.get("philips_hue_cluster")
1020+
self._effect_list.extend(self.HUE_EFFECTS.keys())
1021+
1022+
async def async_turn_on(self, **kwargs: Any) -> None:
1023+
# If only change of brightness is requested, the effect doesn't have to be interupted
1024+
if kwargs.get(ATTR_BRIGHTNESS) is not None and all(
1025+
attr == ATTR_BRIGHTNESS or kwargs.get(attr) is None
1026+
for attr in kwargs.keys()
1027+
):
1028+
effect = self._effect
1029+
else:
1030+
effect = kwargs.get(ATTR_EFFECT)
1031+
1032+
await super().async_turn_on(**kwargs)
1033+
1034+
if effect == self._effect:
1035+
return
1036+
1037+
if effect in self.HUE_EFFECTS:
1038+
effect_id = self.HUE_EFFECTS[effect]
1039+
await self._hue_cluster.multicolor(
1040+
data=bytearray([0x22, 0x00, self._brightness, effect_id])
1041+
)
1042+
self._effect = effect
1043+
elif (
1044+
effect is None or effect == EFFECT_OFF and self._effect in self.HUE_EFFECTS
1045+
):
1046+
# Only stop effect if it was started by us
1047+
# Following command will stop the effect while preserving brightness
1048+
await self._hue_cluster.multicolor(data=bytearray([0x20, 0x00, 0x00, 0x00]))
1049+
self._effect = EFFECT_OFF
1050+
else:
1051+
# Don't react on unknown effects, for example 'colorloop'
1052+
return
1053+
1054+
self.maybe_emit_state_changed_event()
1055+
1056+
9941057
@STRICT_MATCH(
9951058
cluster_handler_names=CLUSTER_HANDLER_ON_OFF,
9961059
aux_cluster_handlers={CLUSTER_HANDLER_COLOR, CLUSTER_HANDLER_LEVEL},

0 commit comments

Comments
 (0)