1 """Support for Homematic lights."""
3 from __future__
import annotations
21 from .const
import ATTR_DISCOVER_DEVICES
22 from .entity
import HMDevice
28 add_entities: AddEntitiesCallback,
29 discovery_info: DiscoveryInfoType |
None =
None,
31 """Set up the Homematic light platform."""
32 if discovery_info
is None:
36 for conf
in discovery_info[ATTR_DISCOVER_DEVICES]:
38 devices.append(new_device)
44 """Representation of a Homematic light."""
48 """Return the brightness of this light between 0..255."""
56 """Return true if light is on."""
64 """Return the color mode of the light."""
65 if "COLOR" in self.
_hmdevice_hmdevice.WRITENODE:
67 if hasattr(self.
_hmdevice_hmdevice,
"get_color_temp"):
68 return ColorMode.COLOR_TEMP
69 return ColorMode.BRIGHTNESS
73 """Flag supported color modes."""
74 color_modes: set[ColorMode] = set()
76 if "COLOR" in self.
_hmdevice_hmdevice.WRITENODE:
77 color_modes.add(ColorMode.HS)
78 if hasattr(self.
_hmdevice_hmdevice,
"get_color_temp"):
79 color_modes.add(ColorMode.COLOR_TEMP)
81 color_modes.add(ColorMode.BRIGHTNESS)
87 """Flag supported features."""
88 features = LightEntityFeature.TRANSITION
89 if "PROGRAM" in self.
_hmdevice_hmdevice.WRITENODE:
90 features |= LightEntityFeature.EFFECT
95 """Return the hue and saturation color value [float, float]."""
99 return hue * 360.0, sat * 100.0
103 """Return the color temp in mireds [int]."""
111 """Return the list of supported effects."""
114 return self.
_hmdevice_hmdevice.get_effect_list()
118 """Return the current color change program of the light."""
121 return self.
_hmdevice_hmdevice.get_effect()
124 """Turn the light on and/or change color or color effect settings."""
125 if ATTR_TRANSITION
in kwargs:
126 self.
_hmdevice_hmdevice.setValue(
"RAMP_TIME", kwargs[ATTR_TRANSITION], self.
_channel_channel)
128 if ATTR_BRIGHTNESS
in kwargs
and self.
_state_state_state ==
"LEVEL":
129 percent_bright =
float(kwargs[ATTR_BRIGHTNESS]) / 255
132 ATTR_HS_COLOR
not in kwargs
133 and ATTR_COLOR_TEMP
not in kwargs
134 and ATTR_EFFECT
not in kwargs
138 if ATTR_HS_COLOR
in kwargs:
140 hue=kwargs[ATTR_HS_COLOR][0] / 360.0,
141 saturation=kwargs[ATTR_HS_COLOR][1] / 100.0,
144 if ATTR_COLOR_TEMP
in kwargs:
145 hm_temp = (self.
max_miredsmax_mireds - kwargs[ATTR_COLOR_TEMP]) / (
148 self.
_hmdevice_hmdevice.set_color_temp(hm_temp)
149 if ATTR_EFFECT
in kwargs:
150 self.
_hmdevice_hmdevice.set_effect(kwargs[ATTR_EFFECT])
153 """Turn the light off."""
154 if ATTR_TRANSITION
in kwargs:
155 self.
_hmdevice_hmdevice.setValue(
"RAMP_TIME", kwargs[ATTR_TRANSITION], self.
_channel_channel)
160 """Generate a data dict (self._data) from the Homematic metadata."""
166 self._data.
update({
"COLOR":
None})
168 self._data.
update({
"PROGRAM":
None})
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
set[ColorMode] supported_color_modes(self)
def _init_data_struct(self)
ColorMode color_mode(self)
LightEntityFeature supported_features(self)
set[ColorMode]|set[str]|None supported_color_modes(self)
LightEntityFeature supported_features(self)
int|None supported_features(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)