1 """Support for Hue lights."""
3 from __future__
import annotations
5 from functools
import partial
8 from aiohue
import HueBridgeV2
9 from aiohue.v2.controllers.events
import EventType
10 from aiohue.v2.controllers.lights
import LightsController
11 from aiohue.v2.models.feature
import EffectStatus, TimedEffectStatus
12 from aiohue.v2.models.light
import Light
24 LightEntityDescription,
26 filter_supported_color_modes,
32 from ..bridge
import HueBridge
33 from ..const
import DOMAIN
34 from .entity
import HueBaseEntity
35 from .helpers
import (
36 normalize_hue_brightness,
37 normalize_hue_colortemp,
38 normalize_hue_transition,
42 FALLBACK_MIN_MIREDS = 153
43 FALLBACK_MAX_MIREDS = 500
49 config_entry: ConfigEntry,
50 async_add_entities: AddEntitiesCallback,
52 """Set up Hue Light from Config Entry."""
53 bridge: HueBridge = hass.data[DOMAIN][config_entry.entry_id]
54 api: HueBridgeV2 = bridge.api
55 controller: LightsController = api.lights
56 make_light_entity = partial(HueLight, bridge, controller)
59 def async_add_light(event_type: EventType, resource: Light) ->
None:
66 config_entry.async_on_unload(
67 controller.subscribe(async_add_light, event_filter=EventType.RESOURCE_ADDED)
73 """Representation of a Hue light."""
75 _fixed_color_mode: ColorMode |
None =
None
77 key=
"hue_light", has_entity_name=
True, name=
None
81 self, bridge: HueBridge, controller: LightsController, resource: Light
83 """Initialize the light."""
84 super().
__init__(bridge, controller, resource)
86 self._attr_supported_features |= LightEntityFeature.FLASH
89 supported_color_modes = {ColorMode.ONOFF}
91 supported_color_modes.add(ColorMode.XY)
93 supported_color_modes.add(ColorMode.COLOR_TEMP)
95 supported_color_modes.add(ColorMode.BRIGHTNESS)
97 self._attr_supported_features |= LightEntityFeature.TRANSITION
107 if effects := resource.effects:
109 x.value
for x
in effects.status_values
if x != EffectStatus.NO_EFFECT
111 if timed_effects := resource.timed_effects:
114 for x
in timed_effects.status_values
115 if x != TimedEffectStatus.NO_EFFECT
119 self._attr_supported_features |= LightEntityFeature.EFFECT
123 """Return the brightness of this light between 0..255."""
126 return round((dimming.brightness / 100) * 255)
131 """Return true if device is on (brightness above 0)."""
136 """Return the color mode of the light."""
144 return ColorMode.COLOR_TEMP
149 """Return if the light is in Color Temperature mode."""
151 if color_temp
is None or color_temp.mirek
is None:
155 if self.
devicedevice.product_data.certified:
161 """Return the xy color."""
163 return (color.xy.x, color.xy.y)
168 """Return the color temperature."""
170 return color_temp.mirek
172 return FALLBACK_MIREDS
176 """Return the coldest color_temp that this light supports."""
178 return color_temp.mirek_schema.mirek_minimum
180 return FALLBACK_MIN_MIREDS
184 """Return the warmest color_temp that this light supports."""
186 return color_temp.mirek_schema.mirek_maximum
188 return FALLBACK_MAX_MIREDS
192 """Return the optional state attributes."""
200 """Return the current effect."""
202 if effects.status != EffectStatus.NO_EFFECT:
203 return effects.status.value
205 if timed_effects.status != TimedEffectStatus.NO_EFFECT:
206 return timed_effects.status.value
210 """Turn the device on."""
212 xy_color = kwargs.get(ATTR_XY_COLOR)
227 flash = kwargs.get(ATTR_FLASH)
228 effect = effect_str = kwargs.get(ATTR_EFFECT)
229 if effect_str
in (EFFECT_NONE, EFFECT_NONE.lower()):
235 elif effect_str
is not None:
237 effect = EffectStatus(effect_str)
238 if effect == EffectStatus.UNKNOWN:
239 effect = TimedEffectStatus(effect_str)
240 if transition
is None:
247 if flash
is not None:
255 await self.
bridgebridge.async_request_call(
259 brightness=brightness,
261 color_temp=color_temp,
262 transition_time=transition,
267 """Turn the light off."""
271 flash = kwargs.get(ATTR_FLASH)
273 if flash
is not None:
280 await self.
bridgebridge.async_request_call(
284 transition_time=transition,
288 """Send flash command to light."""
289 await self.
bridgebridge.async_request_call(
292 short=flash == FLASH_SHORT,
None async_turn_off(self, **Any kwargs)
tuple[float, float]|None xy_color(self)
_attr_supported_color_modes
None __init__(self, HueBridge bridge, LightsController controller, Light resource)
None async_turn_on(self, **Any kwargs)
int|None brightness(self)
None async_set_flash(self, str flash)
dict[str, str]|None extra_state_attributes(self)
ColorMode color_mode(self)
bool color_temp_active(self)
float|None normalize_hue_brightness(float|None brightness)
float|None normalize_hue_transition(float|None transition)
int|None normalize_hue_colortemp(int|None colortemp)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
set[ColorMode] filter_supported_color_modes(Iterable[ColorMode] color_modes)