mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Migrate flux to use Kelvin over Mireds (#132839)
This commit is contained in:
parent
af838077cc
commit
b780f31e63
@ -13,7 +13,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
ATTR_XY_COLOR,
|
ATTR_XY_COLOR,
|
||||||
@ -43,7 +43,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
from homeassistant.util.color import (
|
from homeassistant.util.color import (
|
||||||
color_RGB_to_xy_brightness,
|
color_RGB_to_xy_brightness,
|
||||||
color_temperature_kelvin_to_mired,
|
|
||||||
color_temperature_to_rgb,
|
color_temperature_to_rgb,
|
||||||
)
|
)
|
||||||
from homeassistant.util.dt import as_local, utcnow as dt_utcnow
|
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)
|
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."""
|
"""Set color of array of lights."""
|
||||||
for light in lights:
|
for light in lights:
|
||||||
if is_on(hass, light):
|
if is_on(hass, light):
|
||||||
service_data = {ATTR_ENTITY_ID: light}
|
service_data = {ATTR_ENTITY_ID: light}
|
||||||
if mired is not None:
|
if kelvin is not None:
|
||||||
service_data[ATTR_COLOR_TEMP] = int(mired)
|
service_data[ATTR_COLOR_TEMP_KELVIN] = kelvin
|
||||||
if brightness is not None:
|
if brightness is not None:
|
||||||
service_data[ATTR_BRIGHTNESS] = brightness
|
service_data[ATTR_BRIGHTNESS] = brightness
|
||||||
if transition is not None:
|
if transition is not None:
|
||||||
@ -350,17 +349,15 @@ class FluxSwitch(SwitchEntity, RestoreEntity):
|
|||||||
now,
|
now,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Convert to mired and clamp to allowed values
|
|
||||||
mired = color_temperature_kelvin_to_mired(temp)
|
|
||||||
await async_set_lights_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(
|
_LOGGER.debug(
|
||||||
(
|
(
|
||||||
"Lights updated to mired:%s brightness:%s, %s%% "
|
"Lights updated to kelvin:%s brightness:%s, %s%% "
|
||||||
"of %s cycle complete at %s"
|
"of %s cycle complete at %s"
|
||||||
),
|
),
|
||||||
mired,
|
temp,
|
||||||
brightness,
|
brightness,
|
||||||
round(percentage_complete * 100),
|
round(percentage_complete * 100),
|
||||||
time_state,
|
time_state,
|
||||||
|
@ -1164,7 +1164,7 @@ async def test_flux_with_multiple_lights(
|
|||||||
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
|
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,
|
hass: HomeAssistant,
|
||||||
mock_light_entities: list[MockLight],
|
mock_light_entities: list[MockLight],
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -1224,7 +1224,7 @@ async def test_flux_with_mired(
|
|||||||
async_fire_time_changed(hass, test_time)
|
async_fire_time_changed(hass, test_time)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
call = turn_on_calls[-1]
|
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(
|
async def test_flux_with_rgb(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user