mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Migrate nanoleaf lights to use Kelvin (#132797)
This commit is contained in:
parent
4880849074
commit
28d01d88a2
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import math
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
@ -17,10 +16,6 @@ from homeassistant.components.light import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.color import (
|
|
||||||
color_temperature_kelvin_to_mired as kelvin_to_mired,
|
|
||||||
color_temperature_mired_to_kelvin as mired_to_kelvin,
|
|
||||||
)
|
|
||||||
|
|
||||||
from . import NanoleafConfigEntry
|
from . import NanoleafConfigEntry
|
||||||
from .coordinator import NanoleafCoordinator
|
from .coordinator import NanoleafCoordinator
|
||||||
@ -51,10 +46,8 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
|||||||
"""Initialize the Nanoleaf light."""
|
"""Initialize the Nanoleaf light."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._attr_unique_id = self._nanoleaf.serial_no
|
self._attr_unique_id = self._nanoleaf.serial_no
|
||||||
self._attr_min_mireds = math.ceil(
|
self._attr_max_color_temp_kelvin = self._nanoleaf.color_temperature_max
|
||||||
1000000 / self._nanoleaf.color_temperature_max
|
self._attr_min_color_temp_kelvin = self._nanoleaf.color_temperature_min
|
||||||
)
|
|
||||||
self._attr_max_mireds = kelvin_to_mired(self._nanoleaf.color_temperature_min)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self) -> int:
|
def brightness(self) -> int:
|
||||||
@ -62,9 +55,9 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
|||||||
return int(self._nanoleaf.brightness * 2.55)
|
return int(self._nanoleaf.brightness * 2.55)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self) -> int:
|
def color_temp_kelvin(self) -> int | None:
|
||||||
"""Return the current color temperature."""
|
"""Return the color temperature value in Kelvin."""
|
||||||
return kelvin_to_mired(self._nanoleaf.color_temperature)
|
return self._nanoleaf.color_temperature
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effect(self) -> str | None:
|
def effect(self) -> str | None:
|
||||||
@ -106,7 +99,7 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
|||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
hs_color = kwargs.get(ATTR_HS_COLOR)
|
hs_color = kwargs.get(ATTR_HS_COLOR)
|
||||||
color_temp_mired = kwargs.get(ATTR_COLOR_TEMP)
|
color_temp_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)
|
||||||
effect = kwargs.get(ATTR_EFFECT)
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
transition = kwargs.get(ATTR_TRANSITION)
|
transition = kwargs.get(ATTR_TRANSITION)
|
||||||
|
|
||||||
@ -120,10 +113,8 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
|||||||
hue, saturation = hs_color
|
hue, saturation = hs_color
|
||||||
await self._nanoleaf.set_hue(int(hue))
|
await self._nanoleaf.set_hue(int(hue))
|
||||||
await self._nanoleaf.set_saturation(int(saturation))
|
await self._nanoleaf.set_saturation(int(saturation))
|
||||||
elif color_temp_mired:
|
elif color_temp_kelvin:
|
||||||
await self._nanoleaf.set_color_temperature(
|
await self._nanoleaf.set_color_temperature(color_temp_kelvin)
|
||||||
mired_to_kelvin(color_temp_mired)
|
|
||||||
)
|
|
||||||
if transition:
|
if transition:
|
||||||
if brightness: # tune to the required brightness in n seconds
|
if brightness: # tune to the required brightness in n seconds
|
||||||
await self._nanoleaf.set_brightness(
|
await self._nanoleaf.set_brightness(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user