Migrate the LIFX integration to use kelvin for color temp (#79775)
parent
45a30546ec
commit
41595b0cba
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
import math
|
||||
from typing import Any
|
||||
|
||||
import aiolifx_effects as aiolifx_effects_module
|
||||
|
@ -26,7 +25,6 @@ from homeassistant.helpers import entity_platform
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
|
@ -130,16 +128,13 @@ class LIFXLight(LIFXEntity, LightEntity):
|
|||
self.entry = entry
|
||||
self._attr_unique_id = self.coordinator.serial_number
|
||||
self._attr_name = self.bulb.label
|
||||
self._attr_min_mireds = math.floor(
|
||||
color_util.color_temperature_kelvin_to_mired(bulb_features["max_kelvin"])
|
||||
)
|
||||
self._attr_max_mireds = math.ceil(
|
||||
color_util.color_temperature_kelvin_to_mired(bulb_features["min_kelvin"])
|
||||
)
|
||||
self._attr_min_color_temp_kelvin = bulb_features["min_kelvin"]
|
||||
self._attr_max_color_temp_kelvin = bulb_features["max_kelvin"]
|
||||
if bulb_features["min_kelvin"] != bulb_features["max_kelvin"]:
|
||||
color_mode = ColorMode.COLOR_TEMP
|
||||
else:
|
||||
color_mode = ColorMode.BRIGHTNESS
|
||||
|
||||
self._attr_color_mode = color_mode
|
||||
self._attr_supported_color_modes = {color_mode}
|
||||
self._attr_effect = None
|
||||
|
@ -151,11 +146,9 @@ class LIFXLight(LIFXEntity, LightEntity):
|
|||
return convert_16_to_8(int(fade * self.bulb.color[HSBK_BRIGHTNESS]))
|
||||
|
||||
@property
|
||||
def color_temp(self) -> int | None:
|
||||
"""Return the color temperature."""
|
||||
return color_util.color_temperature_kelvin_to_mired(
|
||||
self.bulb.color[HSBK_KELVIN]
|
||||
)
|
||||
def color_temp_kelvin(self) -> int | None:
|
||||
"""Return the color temperature of this light in kelvin."""
|
||||
return int(self.bulb.color[HSBK_KELVIN])
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
|
|
|
@ -14,15 +14,14 @@ from homeassistant.components.light import (
|
|||
ATTR_BRIGHTNESS_PCT,
|
||||
ATTR_COLOR_NAME,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_KELVIN,
|
||||
ATTR_RGB_COLOR,
|
||||
ATTR_TRANSITION,
|
||||
ATTR_XY_COLOR,
|
||||
COLOR_GROUP,
|
||||
VALID_BRIGHTNESS,
|
||||
VALID_BRIGHTNESS_PCT,
|
||||
preprocess_turn_on_alternatives,
|
||||
)
|
||||
from homeassistant.const import ATTR_MODE
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
|
@ -98,10 +97,10 @@ LIFX_EFFECT_PULSE_SCHEMA = cv.make_entity_service_schema(
|
|||
)
|
||||
),
|
||||
),
|
||||
vol.Exclusive(ATTR_COLOR_TEMP, COLOR_GROUP): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=1)
|
||||
vol.Exclusive(ATTR_COLOR_TEMP_KELVIN, COLOR_GROUP): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=1500, max=9000)
|
||||
),
|
||||
vol.Exclusive(ATTR_KELVIN, COLOR_GROUP): cv.positive_int,
|
||||
vol.Exclusive(ATTR_COLOR_TEMP, COLOR_GROUP): cv.positive_int,
|
||||
ATTR_PERIOD: vol.All(vol.Coerce(float), vol.Range(min=0.05)),
|
||||
ATTR_CYCLES: vol.All(vol.Coerce(float), vol.Range(min=1)),
|
||||
ATTR_MODE: vol.In(PULSE_MODES),
|
||||
|
@ -250,7 +249,6 @@ class LIFXManager:
|
|||
await self.effects_conductor.start(effect, bulbs)
|
||||
|
||||
elif service == SERVICE_EFFECT_COLORLOOP:
|
||||
preprocess_turn_on_alternatives(self.hass, kwargs)
|
||||
|
||||
brightness = None
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
|
|
|
@ -14,11 +14,10 @@ from awesomeversion import AwesomeVersion
|
|||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_RGB_COLOR,
|
||||
ATTR_XY_COLOR,
|
||||
preprocess_turn_on_alternatives,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -81,8 +80,6 @@ def find_hsbk(hass: HomeAssistant, **kwargs: Any) -> list[float | int | None] |
|
|||
"""
|
||||
hue, saturation, brightness, kelvin = [None] * 4
|
||||
|
||||
preprocess_turn_on_alternatives(hass, kwargs)
|
||||
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
hue, saturation = kwargs[ATTR_HS_COLOR]
|
||||
elif ATTR_RGB_COLOR in kwargs:
|
||||
|
@ -96,10 +93,8 @@ def find_hsbk(hass: HomeAssistant, **kwargs: Any) -> list[float | int | None] |
|
|||
saturation = int(saturation / 100 * 65535)
|
||||
kelvin = 3500
|
||||
|
||||
if ATTR_COLOR_TEMP in kwargs:
|
||||
kelvin = int(
|
||||
color_util.color_temperature_mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])
|
||||
)
|
||||
if ATTR_COLOR_TEMP_KELVIN in kwargs:
|
||||
kelvin = kwargs.pop(ATTR_COLOR_TEMP_KELVIN)
|
||||
saturation = 0
|
||||
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.components.light import (
|
|||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_MODE,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_EFFECT,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_RGB_COLOR,
|
||||
|
@ -784,9 +785,9 @@ async def test_color_light_with_temp(
|
|||
ColorMode.COLOR_TEMP,
|
||||
ColorMode.HS,
|
||||
]
|
||||
assert attributes[ATTR_HS_COLOR] == (31.007, 6.862)
|
||||
assert attributes[ATTR_RGB_COLOR] == (255, 246, 237)
|
||||
assert attributes[ATTR_XY_COLOR] == (0.339, 0.338)
|
||||
assert attributes[ATTR_HS_COLOR] == (30.754, 7.122)
|
||||
assert attributes[ATTR_RGB_COLOR] == (255, 246, 236)
|
||||
assert attributes[ATTR_XY_COLOR] == (0.34, 0.339)
|
||||
bulb.color = [65535, 65535, 65535, 65535]
|
||||
|
||||
await hass.services.async_call(
|
||||
|
@ -911,7 +912,7 @@ async def test_white_bulb(hass: HomeAssistant) -> None:
|
|||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [
|
||||
ColorMode.COLOR_TEMP,
|
||||
]
|
||||
assert attributes[ATTR_COLOR_TEMP] == 166
|
||||
assert attributes[ATTR_COLOR_TEMP_KELVIN] == 6000
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN, "turn_off", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
||||
)
|
||||
|
@ -1012,10 +1013,10 @@ async def test_white_light_fails(hass):
|
|||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
"turn_on",
|
||||
{ATTR_ENTITY_ID: entity_id, ATTR_COLOR_TEMP: 153},
|
||||
{ATTR_ENTITY_ID: entity_id, ATTR_COLOR_TEMP_KELVIN: 6000},
|
||||
blocking=True,
|
||||
)
|
||||
assert bulb.set_color.calls[0][0][0] == [1, 0, 3, 6535]
|
||||
assert bulb.set_color.calls[0][0][0] == [1, 0, 3, 6000]
|
||||
bulb.set_color.reset_mock()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue