From d41832de5926f6d0e4f9e27bd6f5b1d5d98076cc Mon Sep 17 00:00:00 2001 From: Milan Meulemans Date: Sat, 2 Oct 2021 09:30:20 +0200 Subject: [PATCH] Get min and max color temperature for Nanoleaf light from library (#56863) --- homeassistant/components/nanoleaf/light.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/nanoleaf/light.py b/homeassistant/components/nanoleaf/light.py index 1bc1e4a69b9..414b2079485 100644 --- a/homeassistant/components/nanoleaf/light.py +++ b/homeassistant/components/nanoleaf/light.py @@ -1,6 +1,7 @@ """Support for Nanoleaf Lights.""" from __future__ import annotations +import math from typing import Any from aionanoleaf import Nanoleaf, Unavailable @@ -27,8 +28,8 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from homeassistant.util import color as color_util from homeassistant.util.color import ( + color_temperature_kelvin_to_mired as kelvin_to_mired, color_temperature_mired_to_kelvin as mired_to_kelvin, ) @@ -85,8 +86,10 @@ class NanoleafLight(LightEntity): model=self._nanoleaf.model, sw_version=self._nanoleaf.firmware_version, ) - self._attr_min_mireds = 154 - self._attr_max_mireds = 833 + self._attr_min_mireds = math.ceil( + 1000000 / self._nanoleaf.color_temperature_max + ) + self._attr_max_mireds = kelvin_to_mired(self._nanoleaf.color_temperature_min) @property def brightness(self) -> int: @@ -96,9 +99,7 @@ class NanoleafLight(LightEntity): @property def color_temp(self) -> int: """Return the current color temperature.""" - return color_util.color_temperature_kelvin_to_mired( - self._nanoleaf.color_temperature - ) + return kelvin_to_mired(self._nanoleaf.color_temperature) @property def effect(self) -> str | None: