1 """Support for HomematicIP Cloud lights."""
3 from __future__
import annotations
7 from homematicip.aio.device
import (
9 AsyncBrandSwitchMeasuring,
10 AsyncBrandSwitchNotificationLight,
17 from homematicip.base.enums
import OpticalSignalBehaviour, RGBColorState
18 from homematicip.base.functionalChannels
import NotificationLightChannel
19 from packaging.version
import Version
35 from .const
import DOMAIN
36 from .entity
import HomematicipGenericEntity
37 from .hap
import HomematicipHAP
42 config_entry: ConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Set up the HomematicIP Cloud lights from a config entry."""
46 hap = hass.data[DOMAIN][config_entry.unique_id]
47 entities: list[HomematicipGenericEntity] = []
48 for device
in hap.home.devices:
49 if isinstance(device, AsyncBrandSwitchMeasuring):
51 elif isinstance(device, AsyncBrandSwitchNotificationLight):
52 device_version = Version(device.firmwareVersion)
56 HomematicipNotificationLightV2
57 if device_version > Version(
"2.0.0")
58 else HomematicipNotificationLight
62 entity_class(hap, device, device.topLightChannelIndex,
"Top")
65 entity_class(hap, device, device.bottomLightChannelIndex,
"Bottom")
68 elif isinstance(device, (AsyncWiredDimmer3, AsyncDinRailDimmer3)):
71 for channel
in range(1, 4)
75 (AsyncDimmer, AsyncPluggableDimmer, AsyncBrandDimmer, AsyncFullFlushDimmer),
83 """Representation of the HomematicIP light."""
85 _attr_color_mode = ColorMode.ONOFF
86 _attr_supported_color_modes = {ColorMode.ONOFF}
88 def __init__(self, hap: HomematicipHAP, device) ->
None:
89 """Initialize the light entity."""
94 """Return true if light is on."""
98 """Turn the light on."""
102 """Turn the light off."""
107 """Representation of the HomematicIP measuring light."""
110 class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity):
111 """Representation of HomematicIP Cloud dimmer."""
113 _attr_color_mode = ColorMode.BRIGHTNESS
114 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
121 is_multi_channel=
True,
123 """Initialize the dimmer light entity."""
125 hap, device, channel=channel, is_multi_channel=is_multi_channel
130 """Return true if dimmer is on."""
131 func_channel = self.
_device_device.functionalChannels[self.
_channel_channel]
132 return func_channel.dimLevel
is not None and func_channel.dimLevel > 0.0
136 """Return the brightness of this light between 0..255."""
138 (self.
_device_device.functionalChannels[self.
_channel_channel].dimLevel
or 0.0) * 255
142 """Turn the dimmer on."""
143 if ATTR_BRIGHTNESS
in kwargs:
144 await self.
_device_device.set_dim_level(
145 kwargs[ATTR_BRIGHTNESS] / 255.0, self.
_channel_channel
151 """Turn the dimmer off."""
156 """Representation of HomematicIP Cloud dimmer."""
158 def __init__(self, hap: HomematicipHAP, device) ->
None:
159 """Initialize the dimmer light entity."""
160 super().
__init__(hap, device, is_multi_channel=
False)
164 """Representation of HomematicIP Cloud notification light."""
166 _attr_color_mode = ColorMode.HS
167 _attr_supported_color_modes = {ColorMode.HS}
168 _attr_supported_features = LightEntityFeature.TRANSITION
170 def __init__(self, hap: HomematicipHAP, device, channel: int, post: str) ->
None:
171 """Initialize the notification light entity."""
172 super().
__init__(hap, device, post=post, channel=channel, is_multi_channel=
True)
174 self._color_switcher: dict[str, tuple[float, float]] = {
175 RGBColorState.WHITE: (0.0, 0.0),
176 RGBColorState.RED: (0.0, 100.0),
177 RGBColorState.YELLOW: (60.0, 100.0),
178 RGBColorState.GREEN: (120.0, 100.0),
179 RGBColorState.TURQUOISE: (180.0, 100.0),
180 RGBColorState.BLUE: (240.0, 100.0),
181 RGBColorState.PURPLE: (300.0, 100.0),
190 """Return true if light is on."""
198 """Return the brightness of this light between 0..255."""
203 """Return the hue and saturation color value [float, float]."""
204 simple_rgb_color = self.
_func_channel_func_channel.simpleRGBColorState
205 return self._color_switcher.
get(simple_rgb_color, (0.0, 0.0))
209 """Return the state attributes of the notification light sensor."""
210 state_attr = super().extra_state_attributes
213 state_attr[ATTR_COLOR_NAME] = self.
_func_channel_func_channel.simpleRGBColorState
219 """Return a unique ID."""
220 return f
"{self.__class__.__name__}_{self._post}_{self._device.id}"
223 """Turn the light on."""
238 brightness =
max(10, brightness)
239 dim_level = brightness / 255.0
240 transition = kwargs.get(ATTR_TRANSITION, 0.5)
242 await self.
_device_device.set_rgb_dim_level_with_time(
244 rgb=simple_rgb_color,
251 """Turn the light off."""
252 simple_rgb_color = self.
_func_channel_func_channel.simpleRGBColorState
253 transition = kwargs.get(ATTR_TRANSITION, 0.5)
255 await self.
_device_device.set_rgb_dim_level_with_time(
257 rgb=simple_rgb_color,
265 """Representation of HomematicIP Cloud notification light."""
268 OpticalSignalBehaviour.BILLOW_MIDDLE,
269 OpticalSignalBehaviour.BLINKING_MIDDLE,
270 OpticalSignalBehaviour.FLASH_MIDDLE,
271 OpticalSignalBehaviour.OFF,
272 OpticalSignalBehaviour.ON,
275 def __init__(self, hap: HomematicipHAP, device, channel: int, post: str) ->
None:
276 """Initialize the notification light entity."""
277 super().
__init__(hap, device, post=post, channel=channel)
282 """Return the list of supported effects."""
287 """Return the current effect."""
288 return self.
_func_channel_func_channel.opticalSignalBehaviour
292 """Return true if light is on."""
296 """Turn the light on."""
304 if ATTR_BRIGHTNESS
in kwargs:
305 brightness = kwargs[ATTR_BRIGHTNESS]
308 brightness =
max(10, brightness)
309 dim_level = round(brightness / 255.0, 2)
312 if ATTR_EFFECT
in kwargs:
313 effect = kwargs[ATTR_EFFECT]
315 await self.
_func_channel_func_channel.async_set_optical_signal(
316 opticalSignalBehaviour=effect, rgb=simple_rgb_color, dimLevel=dim_level
320 """Turn the light off."""
325 """Convert the given color to the reduced RGBColorState color.
327 RGBColorStat contains only 8 colors including white and black,
328 so a conversion is required.
331 return RGBColorState.WHITE
334 saturation =
int(color[1])
336 return RGBColorState.WHITE
338 return RGBColorState.YELLOW
340 return RGBColorState.GREEN
342 return RGBColorState.TURQUOISE
344 return RGBColorState.BLUE
346 return RGBColorState.PURPLE
347 return RGBColorState.RED
None __init__(self, HomematicipHAP hap, device)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, HomematicipHAP hap, device)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, HomematicipHAP hap, device, channel=1, is_multi_channel=True)
None async_turn_on(self, **Any kwargs)
list[str]|None effect_list(self)
None __init__(self, HomematicipHAP hap, device, int channel, str post)
None async_turn_off(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None __init__(self, HomematicipHAP hap, device, int channel, str post)
dict[str, Any] extra_state_attributes(self)
tuple[float, float] hs_color(self)
NotificationLightChannel _func_channel(self)
int|None brightness(self)
tuple[float, float]|None hs_color(self)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
web.Response get(self, web.Request request, str config_key)
RGBColorState _convert_color(tuple color)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)