mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27: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
|
||||
|
||||
import math
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_EFFECT,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_TRANSITION,
|
||||
@ -17,10 +16,6 @@ from homeassistant.components.light import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
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 .coordinator import NanoleafCoordinator
|
||||
@ -51,10 +46,8 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
||||
"""Initialize the Nanoleaf light."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = self._nanoleaf.serial_no
|
||||
self._attr_min_mireds = math.ceil(
|
||||
1000000 / self._nanoleaf.color_temperature_max
|
||||
)
|
||||
self._attr_max_mireds = kelvin_to_mired(self._nanoleaf.color_temperature_min)
|
||||
self._attr_max_color_temp_kelvin = self._nanoleaf.color_temperature_max
|
||||
self._attr_min_color_temp_kelvin = self._nanoleaf.color_temperature_min
|
||||
|
||||
@property
|
||||
def brightness(self) -> int:
|
||||
@ -62,9 +55,9 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
||||
return int(self._nanoleaf.brightness * 2.55)
|
||||
|
||||
@property
|
||||
def color_temp(self) -> int:
|
||||
"""Return the current color temperature."""
|
||||
return kelvin_to_mired(self._nanoleaf.color_temperature)
|
||||
def color_temp_kelvin(self) -> int | None:
|
||||
"""Return the color temperature value in Kelvin."""
|
||||
return self._nanoleaf.color_temperature
|
||||
|
||||
@property
|
||||
def effect(self) -> str | None:
|
||||
@ -106,7 +99,7 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
||||
"""Instruct the light to turn on."""
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
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)
|
||||
transition = kwargs.get(ATTR_TRANSITION)
|
||||
|
||||
@ -120,10 +113,8 @@ class NanoleafLight(NanoleafEntity, LightEntity):
|
||||
hue, saturation = hs_color
|
||||
await self._nanoleaf.set_hue(int(hue))
|
||||
await self._nanoleaf.set_saturation(int(saturation))
|
||||
elif color_temp_mired:
|
||||
await self._nanoleaf.set_color_temperature(
|
||||
mired_to_kelvin(color_temp_mired)
|
||||
)
|
||||
elif color_temp_kelvin:
|
||||
await self._nanoleaf.set_color_temperature(color_temp_kelvin)
|
||||
if transition:
|
||||
if brightness: # tune to the required brightness in n seconds
|
||||
await self._nanoleaf.set_brightness(
|
||||
|
Loading…
x
Reference in New Issue
Block a user