Adapt group to color temperature in K (#79719)
* Adapt group to color temperature in K * Adjust tests * Adjust tests
This commit is contained in:
parent
1e5908d3a8
commit
2ee6ea9877
4 changed files with 41 additions and 38 deletions
|
@ -12,13 +12,13 @@ from homeassistant.components import light
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_MODE,
|
ATTR_COLOR_MODE,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_EFFECT_LIST,
|
ATTR_EFFECT_LIST,
|
||||||
ATTR_FLASH,
|
ATTR_FLASH,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_MAX_MIREDS,
|
ATTR_MAX_COLOR_TEMP_KELVIN,
|
||||||
ATTR_MIN_MIREDS,
|
ATTR_MIN_COLOR_TEMP_KELVIN,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ATTR_RGBW_COLOR,
|
ATTR_RGBW_COLOR,
|
||||||
ATTR_RGBWW_COLOR,
|
ATTR_RGBWW_COLOR,
|
||||||
|
@ -114,7 +114,7 @@ async def async_setup_entry(
|
||||||
FORWARDED_ATTRIBUTES = frozenset(
|
FORWARDED_ATTRIBUTES = frozenset(
|
||||||
{
|
{
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_FLASH,
|
ATTR_FLASH,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
|
@ -133,8 +133,8 @@ class LightGroup(GroupEntity, LightEntity):
|
||||||
|
|
||||||
_attr_available = False
|
_attr_available = False
|
||||||
_attr_icon = "mdi:lightbulb-group"
|
_attr_icon = "mdi:lightbulb-group"
|
||||||
_attr_max_mireds = 500
|
_attr_max_color_temp_kelvin = 6500
|
||||||
_attr_min_mireds = 154
|
_attr_min_color_temp_kelvin = 2000
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -239,12 +239,14 @@ class LightGroup(GroupEntity, LightEntity):
|
||||||
on_states, ATTR_XY_COLOR, reduce=mean_tuple
|
on_states, ATTR_XY_COLOR, reduce=mean_tuple
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_color_temp = reduce_attribute(on_states, ATTR_COLOR_TEMP)
|
self._attr_color_temp_kelvin = reduce_attribute(
|
||||||
self._attr_min_mireds = reduce_attribute(
|
on_states, ATTR_COLOR_TEMP_KELVIN
|
||||||
states, ATTR_MIN_MIREDS, default=154, reduce=min
|
|
||||||
)
|
)
|
||||||
self._attr_max_mireds = reduce_attribute(
|
self._attr_min_color_temp_kelvin = reduce_attribute(
|
||||||
states, ATTR_MAX_MIREDS, default=500, reduce=max
|
states, ATTR_MIN_COLOR_TEMP_KELVIN, default=2000, reduce=min
|
||||||
|
)
|
||||||
|
self._attr_max_color_temp_kelvin = reduce_attribute(
|
||||||
|
states, ATTR_MAX_COLOR_TEMP_KELVIN, default=6500, reduce=max
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_effect_list = None
|
self._attr_effect_list = None
|
||||||
|
|
|
@ -13,12 +13,13 @@ from homeassistant.components.light import (
|
||||||
ATTR_COLOR_MODE,
|
ATTR_COLOR_MODE,
|
||||||
ATTR_COLOR_NAME,
|
ATTR_COLOR_NAME,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP,
|
||||||
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_EFFECT_LIST,
|
ATTR_EFFECT_LIST,
|
||||||
ATTR_FLASH,
|
ATTR_FLASH,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_MAX_MIREDS,
|
ATTR_MAX_COLOR_TEMP_KELVIN,
|
||||||
ATTR_MIN_MIREDS,
|
ATTR_MIN_COLOR_TEMP_KELVIN,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ATTR_RGBW_COLOR,
|
ATTR_RGBW_COLOR,
|
||||||
ATTR_RGBWW_COLOR,
|
ATTR_RGBWW_COLOR,
|
||||||
|
@ -76,7 +77,7 @@ async def test_default_state(hass):
|
||||||
assert state.attributes.get(ATTR_ENTITY_ID) == ["light.kitchen", "light.bedroom"]
|
assert state.attributes.get(ATTR_ENTITY_ID) == ["light.kitchen", "light.bedroom"]
|
||||||
assert state.attributes.get(ATTR_BRIGHTNESS) is None
|
assert state.attributes.get(ATTR_BRIGHTNESS) is None
|
||||||
assert state.attributes.get(ATTR_HS_COLOR) is None
|
assert state.attributes.get(ATTR_HS_COLOR) is None
|
||||||
assert state.attributes.get(ATTR_COLOR_TEMP) is None
|
assert state.attributes.get(ATTR_COLOR_TEMP_KELVIN) is None
|
||||||
assert state.attributes.get(ATTR_EFFECT_LIST) is None
|
assert state.attributes.get(ATTR_EFFECT_LIST) is None
|
||||||
assert state.attributes.get(ATTR_EFFECT) is None
|
assert state.attributes.get(ATTR_EFFECT) is None
|
||||||
|
|
||||||
|
@ -685,7 +686,7 @@ async def test_color_temp(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.brightness = 255
|
entity0.brightness = 255
|
||||||
entity0.color_temp = 2
|
entity0.color_temp_kelvin = 2
|
||||||
|
|
||||||
entity1 = platform.ENTITIES[1]
|
entity1 = platform.ENTITIES[1]
|
||||||
entity1.supported_features = SUPPORT_COLOR_TEMP
|
entity1.supported_features = SUPPORT_COLOR_TEMP
|
||||||
|
@ -710,20 +711,20 @@ async def test_color_temp(hass, enable_custom_integrations):
|
||||||
|
|
||||||
state = hass.states.get("light.light_group")
|
state = hass.states.get("light.light_group")
|
||||||
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
||||||
assert state.attributes[ATTR_COLOR_TEMP] == 2
|
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 2
|
||||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp"]
|
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp"]
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
"turn_on",
|
"turn_on",
|
||||||
{"entity_id": [entity1.entity_id], ATTR_COLOR_TEMP: 1000},
|
{"entity_id": [entity1.entity_id], ATTR_COLOR_TEMP_KELVIN: 1000},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("light.light_group")
|
state = hass.states.get("light.light_group")
|
||||||
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
||||||
assert state.attributes[ATTR_COLOR_TEMP] == 501
|
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 501
|
||||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp"]
|
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp"]
|
||||||
|
|
||||||
|
@ -736,7 +737,7 @@ async def test_color_temp(hass, enable_custom_integrations):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("light.light_group")
|
state = hass.states.get("light.light_group")
|
||||||
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
assert state.attributes[ATTR_COLOR_MODE] == "color_temp"
|
||||||
assert state.attributes[ATTR_COLOR_TEMP] == 1000
|
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 1000
|
||||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp"]
|
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp"]
|
||||||
|
|
||||||
|
@ -819,14 +820,14 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
|
||||||
entity0 = platform.ENTITIES[0]
|
entity0 = platform.ENTITIES[0]
|
||||||
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 = 2
|
entity0.color_temp_kelvin = 2
|
||||||
entity0.min_mireds = 2
|
entity0.min_color_temp_kelvin = 2
|
||||||
entity0.max_mireds = 5
|
entity0.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_mireds = 1
|
entity1.min_color_temp_kelvin = 1
|
||||||
entity1.max_mireds = 1234567890
|
entity1.max_color_temp_kelvin = 1234567890
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -848,8 +849,8 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("light.light_group")
|
state = hass.states.get("light.light_group")
|
||||||
assert state.attributes[ATTR_MIN_MIREDS] == 1
|
assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 1
|
||||||
assert state.attributes[ATTR_MAX_MIREDS] == 1234567890
|
assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 1234567890
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
|
@ -859,8 +860,8 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("light.light_group")
|
state = hass.states.get("light.light_group")
|
||||||
assert state.attributes[ATTR_MIN_MIREDS] == 1
|
assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 1
|
||||||
assert state.attributes[ATTR_MAX_MIREDS] == 1234567890
|
assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 1234567890
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
|
@ -870,8 +871,8 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("light.light_group")
|
state = hass.states.get("light.light_group")
|
||||||
assert state.attributes[ATTR_MIN_MIREDS] == 1
|
assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 1
|
||||||
assert state.attributes[ATTR_MAX_MIREDS] == 1234567890
|
assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 1234567890
|
||||||
|
|
||||||
|
|
||||||
async def test_effect_list(hass):
|
async def test_effect_list(hass):
|
||||||
|
@ -1448,7 +1449,7 @@ async def test_invalid_service_calls(hass):
|
||||||
ATTR_BRIGHTNESS: 150,
|
ATTR_BRIGHTNESS: 150,
|
||||||
ATTR_XY_COLOR: (0.5, 0.42),
|
ATTR_XY_COLOR: (0.5, 0.42),
|
||||||
ATTR_RGB_COLOR: (80, 120, 50),
|
ATTR_RGB_COLOR: (80, 120, 50),
|
||||||
ATTR_COLOR_TEMP: 1234,
|
ATTR_COLOR_TEMP_KELVIN: 1234,
|
||||||
ATTR_EFFECT: "Sunshine",
|
ATTR_EFFECT: "Sunshine",
|
||||||
ATTR_TRANSITION: 4,
|
ATTR_TRANSITION: 4,
|
||||||
ATTR_FLASH: "long",
|
ATTR_FLASH: "long",
|
||||||
|
|
|
@ -1193,7 +1193,7 @@ async def test_light_backwards_compatibility_color_mode(
|
||||||
|
|
||||||
entity2 = platform.ENTITIES[2]
|
entity2 = platform.ENTITIES[2]
|
||||||
entity2.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR_TEMP
|
entity2.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR_TEMP
|
||||||
entity2.color_temp = 100
|
entity2.color_temp_kelvin = 10000
|
||||||
|
|
||||||
entity3 = platform.ENTITIES[3]
|
entity3 = platform.ENTITIES[3]
|
||||||
entity3.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR
|
entity3.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR
|
||||||
|
@ -1204,7 +1204,7 @@ async def test_light_backwards_compatibility_color_mode(
|
||||||
light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR | light.SUPPORT_COLOR_TEMP
|
light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR | light.SUPPORT_COLOR_TEMP
|
||||||
)
|
)
|
||||||
entity4.hs_color = (240, 100)
|
entity4.hs_color = (240, 100)
|
||||||
entity4.color_temp = 100
|
entity4.color_temp_kelvin = 10000
|
||||||
|
|
||||||
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -1893,7 +1893,7 @@ async def test_light_service_call_color_temp_conversion(
|
||||||
assert entity1.min_mireds == 153
|
assert entity1.min_mireds == 153
|
||||||
assert entity1.max_mireds == 500
|
assert entity1.max_mireds == 500
|
||||||
assert entity1.min_color_temp_kelvin == 2000
|
assert entity1.min_color_temp_kelvin == 2000
|
||||||
assert entity1.max_color_temp_kelvin == 6535
|
assert entity1.max_color_temp_kelvin == 6500
|
||||||
|
|
||||||
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
|
@ -37,13 +37,13 @@ class MockLight(MockToggleEntity, LightEntity):
|
||||||
"""Mock light class."""
|
"""Mock light class."""
|
||||||
|
|
||||||
color_mode = None
|
color_mode = None
|
||||||
max_mireds = 500
|
max_color_temp_kelvin = 6500
|
||||||
min_mireds = 153
|
min_color_temp_kelvin = 2000
|
||||||
supported_color_modes = None
|
supported_color_modes = None
|
||||||
supported_features = 0
|
supported_features = 0
|
||||||
|
|
||||||
brightness = None
|
brightness = None
|
||||||
color_temp = None
|
color_temp_kelvin = None
|
||||||
hs_color = None
|
hs_color = None
|
||||||
rgb_color = None
|
rgb_color = None
|
||||||
rgbw_color = None
|
rgbw_color = None
|
||||||
|
@ -61,7 +61,7 @@ class MockLight(MockToggleEntity, LightEntity):
|
||||||
"rgb_color",
|
"rgb_color",
|
||||||
"rgbw_color",
|
"rgbw_color",
|
||||||
"rgbww_color",
|
"rgbww_color",
|
||||||
"color_temp",
|
"color_temp_kelvin",
|
||||||
]:
|
]:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
if key == "white":
|
if key == "white":
|
||||||
|
|
Loading…
Add table
Reference in a new issue