mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Correct min/max mireds for lights which use K for color temp (#79998)
This commit is contained in:
parent
2ee6ea9877
commit
7b247a79cf
@ -911,11 +911,20 @@ class LightEntity(ToggleEntity):
|
|||||||
supported_color_modes = self._light_internal_supported_color_modes
|
supported_color_modes = self._light_internal_supported_color_modes
|
||||||
|
|
||||||
if ColorMode.COLOR_TEMP in supported_color_modes:
|
if ColorMode.COLOR_TEMP in supported_color_modes:
|
||||||
data[ATTR_MIN_MIREDS] = self.min_mireds
|
|
||||||
data[ATTR_MAX_MIREDS] = self.max_mireds
|
|
||||||
data[ATTR_MIN_COLOR_TEMP_KELVIN] = self.min_color_temp_kelvin
|
data[ATTR_MIN_COLOR_TEMP_KELVIN] = self.min_color_temp_kelvin
|
||||||
data[ATTR_MAX_COLOR_TEMP_KELVIN] = self.max_color_temp_kelvin
|
data[ATTR_MAX_COLOR_TEMP_KELVIN] = self.max_color_temp_kelvin
|
||||||
|
if not self.max_color_temp_kelvin:
|
||||||
|
data[ATTR_MIN_MIREDS] = None
|
||||||
|
else:
|
||||||
|
data[ATTR_MIN_MIREDS] = color_util.color_temperature_kelvin_to_mired(
|
||||||
|
self.max_color_temp_kelvin
|
||||||
|
)
|
||||||
|
if not self.min_color_temp_kelvin:
|
||||||
|
data[ATTR_MAX_MIREDS] = None
|
||||||
|
else:
|
||||||
|
data[ATTR_MAX_MIREDS] = color_util.color_temperature_kelvin_to_mired(
|
||||||
|
self.min_color_temp_kelvin
|
||||||
|
)
|
||||||
if supported_features & LightEntityFeature.EFFECT:
|
if supported_features & LightEntityFeature.EFFECT:
|
||||||
data[ATTR_EFFECT_LIST] = self.effect_list
|
data[ATTR_EFFECT_LIST] = self.effect_list
|
||||||
|
|
||||||
|
@ -821,13 +821,13 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
|
|||||||
entity0.supported_color_modes = {ColorMode.COLOR_TEMP}
|
entity0.supported_color_modes = {ColorMode.COLOR_TEMP}
|
||||||
entity0.color_mode = ColorMode.COLOR_TEMP
|
entity0.color_mode = ColorMode.COLOR_TEMP
|
||||||
entity0.color_temp_kelvin = 2
|
entity0.color_temp_kelvin = 2
|
||||||
entity0.min_color_temp_kelvin = 2
|
entity0._attr_min_color_temp_kelvin = 2
|
||||||
entity0.max_color_temp_kelvin = 5
|
entity0._attr_max_color_temp_kelvin = 5
|
||||||
|
|
||||||
entity1 = platform.ENTITIES[1]
|
entity1 = platform.ENTITIES[1]
|
||||||
entity1.supported_features = SUPPORT_COLOR_TEMP
|
entity1.supported_features = SUPPORT_COLOR_TEMP
|
||||||
entity1.min_color_temp_kelvin = 1
|
entity1._attr_min_color_temp_kelvin = 1
|
||||||
entity1.max_color_temp_kelvin = 1234567890
|
entity1._attr_max_color_temp_kelvin = 1234567890
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -1903,6 +1903,10 @@ async def test_light_service_call_color_temp_conversion(
|
|||||||
light.ColorMode.COLOR_TEMP,
|
light.ColorMode.COLOR_TEMP,
|
||||||
light.ColorMode.RGBWW,
|
light.ColorMode.RGBWW,
|
||||||
]
|
]
|
||||||
|
assert state.attributes["min_mireds"] == 153
|
||||||
|
assert state.attributes["max_mireds"] == 500
|
||||||
|
assert state.attributes["min_color_temp_kelvin"] == 2000
|
||||||
|
assert state.attributes["max_color_temp_kelvin"] == 6500
|
||||||
|
|
||||||
state = hass.states.get(entity1.entity_id)
|
state = hass.states.get(entity1.entity_id)
|
||||||
assert state.attributes["supported_color_modes"] == [light.ColorMode.RGBWW]
|
assert state.attributes["supported_color_modes"] == [light.ColorMode.RGBWW]
|
||||||
@ -2001,6 +2005,52 @@ async def test_light_service_call_color_temp_conversion(
|
|||||||
assert data == {"brightness": 255, "rgbww_color": (0, 0, 0, 66, 189)}
|
assert data == {"brightness": 255, "rgbww_color": (0, 0, 0, 66, 189)}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_light_mired_color_temp_conversion(hass, enable_custom_integrations):
|
||||||
|
"""Test color temp conversion from K to legacy mired."""
|
||||||
|
platform = getattr(hass.components, "test.light")
|
||||||
|
platform.init(empty=True)
|
||||||
|
|
||||||
|
platform.ENTITIES.append(platform.MockLight("Test_rgbww_ct", STATE_ON))
|
||||||
|
platform.ENTITIES.append(platform.MockLight("Test_rgbww", STATE_ON))
|
||||||
|
|
||||||
|
entity0 = platform.ENTITIES[0]
|
||||||
|
entity0.supported_color_modes = {
|
||||||
|
light.ColorMode.COLOR_TEMP,
|
||||||
|
}
|
||||||
|
entity0._attr_min_color_temp_kelvin = 1800
|
||||||
|
entity0._attr_max_color_temp_kelvin = 6700
|
||||||
|
|
||||||
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get(entity0.entity_id)
|
||||||
|
assert state.attributes["supported_color_modes"] == [light.ColorMode.COLOR_TEMP]
|
||||||
|
assert state.attributes["min_mireds"] == 149
|
||||||
|
assert state.attributes["max_mireds"] == 555
|
||||||
|
assert state.attributes["min_color_temp_kelvin"] == 1800
|
||||||
|
assert state.attributes["max_color_temp_kelvin"] == 6700
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
"light",
|
||||||
|
"turn_on",
|
||||||
|
{
|
||||||
|
"entity_id": [
|
||||||
|
entity0.entity_id,
|
||||||
|
],
|
||||||
|
"brightness_pct": 100,
|
||||||
|
"color_temp_kelvin": 3500,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
_, data = entity0.last_call("turn_on")
|
||||||
|
assert data == {"brightness": 255, "color_temp": 285, "color_temp_kelvin": 3500}
|
||||||
|
|
||||||
|
state = hass.states.get(entity0.entity_id)
|
||||||
|
assert state.attributes["color_mode"] == light.ColorMode.COLOR_TEMP
|
||||||
|
assert state.attributes["color_temp"] == 285
|
||||||
|
assert state.attributes["color_temp_kelvin"] == 3500
|
||||||
|
|
||||||
|
|
||||||
async def test_light_service_call_white_mode(hass, enable_custom_integrations):
|
async def test_light_service_call_white_mode(hass, enable_custom_integrations):
|
||||||
"""Test color_mode white in service calls."""
|
"""Test color_mode white in service calls."""
|
||||||
platform = getattr(hass.components, "test.light")
|
platform = getattr(hass.components, "test.light")
|
||||||
|
@ -37,8 +37,8 @@ class MockLight(MockToggleEntity, LightEntity):
|
|||||||
"""Mock light class."""
|
"""Mock light class."""
|
||||||
|
|
||||||
color_mode = None
|
color_mode = None
|
||||||
max_color_temp_kelvin = 6500
|
_attr_max_color_temp_kelvin = 6500
|
||||||
min_color_temp_kelvin = 2000
|
_attr_min_color_temp_kelvin = 2000
|
||||||
supported_color_modes = None
|
supported_color_modes = None
|
||||||
supported_features = 0
|
supported_features = 0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user