1 """Demo light platform that implements lights."""
3 from __future__
import annotations
27 LIGHT_COLORS = [(56, 86), (345, 75)]
29 LIGHT_EFFECT_LIST = [
"rainbow",
"none"]
31 LIGHT_TEMPS = [240, 380]
33 SUPPORT_DEMO = {ColorMode.HS, ColorMode.COLOR_TEMP}
34 SUPPORT_DEMO_HS_WHITE = {ColorMode.HS, ColorMode.WHITE}
39 config_entry: ConfigEntry,
40 async_add_entities: AddEntitiesCallback,
42 """Set up the demo light platform."""
47 effect_list=LIGHT_EFFECT_LIST,
48 effect=LIGHT_EFFECT_LIST[0],
49 device_name=
"Bed Light",
56 device_name=
"Ceiling Lights",
62 hs_color=LIGHT_COLORS[1],
63 device_name=
"Kitchen Lights",
70 device_name=
"Office RGBW Lights",
71 rgbw_color=(255, 0, 0, 255),
73 supported_color_modes={ColorMode.RGBW},
78 device_name=
"Living Room RGBWW Lights",
79 rgbww_color=(255, 0, 0, 255, 0),
81 supported_color_modes={ColorMode.RGBWW},
86 device_name=
"Entrance Color + White Lights",
87 hs_color=LIGHT_COLORS[1],
89 supported_color_modes=SUPPORT_DEMO_HS_WHITE,
97 """Representation of a demo light."""
99 _attr_has_entity_name =
True
101 _attr_should_poll =
False
108 available: bool =
False,
109 brightness: int = 180,
110 ct: int |
None =
None,
111 effect_list: list[str] |
None =
None,
112 effect: str |
None =
None,
113 hs_color: tuple[int, int] |
None =
None,
114 rgbw_color: tuple[int, int, int, int] |
None =
None,
115 rgbww_color: tuple[int, int, int, int, int] |
None =
None,
116 supported_color_modes: set[ColorMode] |
None =
None,
118 """Initialize the light."""
121 self.
_ct_ct = ct
or random.choice(LIGHT_TEMPS)
137 if not supported_color_modes:
138 supported_color_modes = SUPPORT_DEMO
141 self._attr_supported_features |= LightEntityFeature.EFFECT
152 """Return unique ID for light."""
157 """Return availability."""
164 """Return the brightness of this light between 0..255."""
169 """Return the color mode of the light."""
174 """Return the hs color value."""
179 """Return the rgbw color value."""
184 """Return the rgbww color value."""
189 """Return the CT color temperature."""
194 """Return the list of supported effects."""
199 """Return the current effect."""
204 """Return true if light is on."""
209 """Flag supported color modes."""
213 """Turn the light on."""
216 if ATTR_BRIGHTNESS
in kwargs:
217 self.
_brightness_brightness = kwargs[ATTR_BRIGHTNESS]
219 if ATTR_COLOR_TEMP
in kwargs:
221 self.
_ct_ct = kwargs[ATTR_COLOR_TEMP]
223 if ATTR_EFFECT
in kwargs:
224 self.
_effect_effect = kwargs[ATTR_EFFECT]
226 if ATTR_HS_COLOR
in kwargs:
228 self.
_hs_color_hs_color = kwargs[ATTR_HS_COLOR]
230 if ATTR_RGBW_COLOR
in kwargs:
232 self.
_rgbw_color_rgbw_color = kwargs[ATTR_RGBW_COLOR]
234 if ATTR_RGBWW_COLOR
in kwargs:
236 self.
_rgbww_color_rgbww_color = kwargs[ATTR_RGBWW_COLOR]
238 if ATTR_WHITE
in kwargs:
247 """Turn the light off."""
tuple[int, int, int, int, int]|None rgbww_color(self)
str|None color_mode(self)
tuple[int, int, int, int]|None rgbw_color(self)
list[str]|None effect_list(self)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
tuple[int, int]|None hs_color(self)
set[ColorMode] supported_color_modes(self)
None __init__(self, str unique_id, str device_name, bool state, bool available=False, int brightness=180, int|None ct=None, list[str]|None effect_list=None, str|None effect=None, tuple[int, int]|None hs_color=None, tuple[int, int, int, int]|None rgbw_color=None, tuple[int, int, int, int, int]|None rgbww_color=None, set[ColorMode]|None supported_color_modes=None)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)