1 """Support for Nanoleaf Lights."""
3 from __future__
import annotations
21 color_temperature_kelvin_to_mired
as kelvin_to_mired,
22 color_temperature_mired_to_kelvin
as mired_to_kelvin,
25 from .
import NanoleafConfigEntry
26 from .coordinator
import NanoleafCoordinator
27 from .entity
import NanoleafEntity
29 RESERVED_EFFECTS = (
"*Solid*",
"*Static*",
"*Dynamic*")
30 DEFAULT_NAME =
"Nanoleaf"
35 entry: NanoleafConfigEntry,
36 async_add_entities: AddEntitiesCallback,
38 """Set up the Nanoleaf light."""
43 """Representation of a Nanoleaf Light."""
45 _attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
46 _attr_supported_features = LightEntityFeature.EFFECT | LightEntityFeature.TRANSITION
48 _attr_translation_key =
"light"
50 def __init__(self, coordinator: NanoleafCoordinator) ->
None:
51 """Initialize the Nanoleaf light."""
55 1000000 / self.
_nanoleaf_nanoleaf.color_temperature_max
61 """Return the brightness of the light."""
66 """Return the current color temperature."""
67 return kelvin_to_mired(self.
_nanoleaf_nanoleaf.color_temperature)
71 """Return the current effect."""
77 None if self.
_nanoleaf_nanoleaf.effect
in RESERVED_EFFECTS
else self.
_nanoleaf_nanoleaf.effect
82 """Return the list of supported effects."""
83 return self.
_nanoleaf_nanoleaf.effects_list
87 """Return true if light is on."""
92 """Return the color in HS."""
97 """Return the color mode of the light."""
100 if self.
_nanoleaf_nanoleaf.color_mode ==
"ct":
101 return ColorMode.COLOR_TEMP
106 """Instruct the light to turn on."""
107 brightness = kwargs.get(ATTR_BRIGHTNESS)
108 hs_color = kwargs.get(ATTR_HS_COLOR)
109 color_temp_mired = kwargs.get(ATTR_COLOR_TEMP)
110 effect = kwargs.get(ATTR_EFFECT)
111 transition = kwargs.get(ATTR_TRANSITION)
116 f
"Attempting to apply effect not in the effect list: '{effect}'"
118 await self.
_nanoleaf_nanoleaf.set_effect(effect)
120 hue, saturation = hs_color
122 await self.
_nanoleaf_nanoleaf.set_saturation(
int(saturation))
123 elif color_temp_mired:
124 await self.
_nanoleaf_nanoleaf.set_color_temperature(
125 mired_to_kelvin(color_temp_mired)
129 await self.
_nanoleaf_nanoleaf.set_brightness(
130 int(brightness / 2.55), transition=
int(kwargs[ATTR_TRANSITION])
133 await self.
_nanoleaf_nanoleaf.set_brightness(100, transition=
int(transition))
137 await self.
_nanoleaf_nanoleaf.set_brightness(
int(brightness / 2.55))
140 """Instruct the light to turn off."""
141 transition: float |
None = kwargs.get(ATTR_TRANSITION)
list[str]|None effect_list(self)
list[str] effect_list(self)
None async_turn_on(self, **Any kwargs)
tuple[int, int] hs_color(self)
None async_turn_off(self, **Any kwargs)
ColorMode|None color_mode(self)
None __init__(self, NanoleafCoordinator coordinator)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, NanoleafConfigEntry entry, AddEntitiesCallback async_add_entities)