Migrate flux to use Kelvin over Mireds ()

pull/132836/head^2
epenet 2024-12-11 08:55:23 +01:00 committed by GitHub
parent af838077cc
commit b780f31e63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 12 deletions
homeassistant/components/flux
tests/components/flux

View File

@ -13,7 +13,7 @@ import voluptuous as vol
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_RGB_COLOR,
ATTR_TRANSITION,
ATTR_XY_COLOR,
@ -43,7 +43,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import slugify
from homeassistant.util.color import (
color_RGB_to_xy_brightness,
color_temperature_kelvin_to_mired,
color_temperature_to_rgb,
)
from homeassistant.util.dt import as_local, utcnow as dt_utcnow
@ -109,13 +108,13 @@ async def async_set_lights_xy(hass, lights, x_val, y_val, brightness, transition
await hass.services.async_call(LIGHT_DOMAIN, SERVICE_TURN_ON, service_data)
async def async_set_lights_temp(hass, lights, mired, brightness, transition):
async def async_set_lights_temp(hass, lights, kelvin, brightness, transition):
"""Set color of array of lights."""
for light in lights:
if is_on(hass, light):
service_data = {ATTR_ENTITY_ID: light}
if mired is not None:
service_data[ATTR_COLOR_TEMP] = int(mired)
if kelvin is not None:
service_data[ATTR_COLOR_TEMP_KELVIN] = kelvin
if brightness is not None:
service_data[ATTR_BRIGHTNESS] = brightness
if transition is not None:
@ -350,17 +349,15 @@ class FluxSwitch(SwitchEntity, RestoreEntity):
now,
)
else:
# Convert to mired and clamp to allowed values
mired = color_temperature_kelvin_to_mired(temp)
await async_set_lights_temp(
self.hass, self._lights, mired, brightness, self._transition
self.hass, self._lights, int(temp), brightness, self._transition
)
_LOGGER.debug(
(
"Lights updated to mired:%s brightness:%s, %s%% "
"Lights updated to kelvin:%s brightness:%s, %s%% "
"of %s cycle complete at %s"
),
mired,
temp,
brightness,
round(percentage_complete * 100),
time_state,

View File

@ -1164,7 +1164,7 @@ async def test_flux_with_multiple_lights(
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
async def test_flux_with_mired(
async def test_flux_with_temp(
hass: HomeAssistant,
mock_light_entities: list[MockLight],
) -> None:
@ -1224,7 +1224,7 @@ async def test_flux_with_mired(
async_fire_time_changed(hass, test_time)
await hass.async_block_till_done()
call = turn_on_calls[-1]
assert call.data[light.ATTR_COLOR_TEMP] == 269
assert call.data[light.ATTR_COLOR_TEMP_KELVIN] == 3708
async def test_flux_with_rgb(