Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions homeassistant/components/lifx/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import asyncio
from datetime import datetime, timedelta
import math
from typing import Any

import aiolifx_effects as aiolifx_effects_module
Expand All @@ -26,7 +25,6 @@
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,
Expand Down Expand Up @@ -130,16 +128,13 @@ def __init__(
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
Expand All @@ -151,11 +146,9 @@ def brightness(self) -> int:
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:
Expand Down
10 changes: 4 additions & 6 deletions homeassistant/components/lifx/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
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
Expand Down Expand Up @@ -98,10 +97,10 @@
)
),
),
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),
Expand Down Expand Up @@ -250,7 +249,6 @@ async def start_effect(
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:
Expand Down
11 changes: 3 additions & 8 deletions homeassistant/components/lifx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions tests/components/lifx/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ATTR_BRIGHTNESS,
ATTR_COLOR_MODE,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_HS_COLOR,
ATTR_RGB_COLOR,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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()


Expand Down