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
17 changes: 7 additions & 10 deletions homeassistant/components/flux/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_RGB_COLOR,
ATTR_TRANSITION,
ATTR_XY_COLOR,
Expand Down Expand Up @@ -43,7 +43,6 @@
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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -350,17 +349,15 @@ async def async_flux_update(self, utcnow=None):
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,
Expand Down
4 changes: 2 additions & 2 deletions tests/components/flux/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ def event_date(
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:
Expand Down Expand Up @@ -1224,7 +1224,7 @@ def event_date(
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(
Expand Down