Adapt group to color temperature in K (#79719)

* Adapt group to color temperature in K

* Adjust tests

* Adjust tests
This commit is contained in:
Erik Montnemery 2022-10-10 14:57:22 +02:00 committed by GitHub
parent 1e5908d3a8
commit 2ee6ea9877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 38 deletions

View File

@ -12,13 +12,13 @@ from homeassistant.components import light
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_MODE,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_EFFECT_LIST,
ATTR_FLASH,
ATTR_HS_COLOR,
ATTR_MAX_MIREDS,
ATTR_MIN_MIREDS,
ATTR_MAX_COLOR_TEMP_KELVIN,
ATTR_MIN_COLOR_TEMP_KELVIN,
ATTR_RGB_COLOR,
ATTR_RGBW_COLOR,
ATTR_RGBWW_COLOR,
@ -114,7 +114,7 @@ async def async_setup_entry(
FORWARDED_ATTRIBUTES = frozenset(
{
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_FLASH,
ATTR_HS_COLOR,
@ -133,8 +133,8 @@ class LightGroup(GroupEntity, LightEntity):
_attr_available = False
_attr_icon = "mdi:lightbulb-group"
_attr_max_mireds = 500
_attr_min_mireds = 154
_attr_max_color_temp_kelvin = 6500
_attr_min_color_temp_kelvin = 2000
_attr_should_poll = False
def __init__(
@ -239,12 +239,14 @@ class LightGroup(GroupEntity, LightEntity):
on_states, ATTR_XY_COLOR, reduce=mean_tuple
)
self._attr_color_temp = reduce_attribute(on_states, ATTR_COLOR_TEMP)
self._attr_min_mireds = reduce_attribute(
states, ATTR_MIN_MIREDS, default=154, reduce=min
self._attr_color_temp_kelvin = reduce_attribute(
on_states, ATTR_COLOR_TEMP_KELVIN
)
self._attr_max_mireds = reduce_attribute(
states, ATTR_MAX_MIREDS, default=500, reduce=max
self._attr_min_color_temp_kelvin = reduce_attribute(
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

View File

@ -13,12 +13,13 @@ from homeassistant.components.light import (
ATTR_COLOR_MODE,
ATTR_COLOR_NAME,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_EFFECT_LIST,
ATTR_FLASH,
ATTR_HS_COLOR,
ATTR_MAX_MIREDS,
ATTR_MIN_MIREDS,
ATTR_MAX_COLOR_TEMP_KELVIN,
ATTR_MIN_COLOR_TEMP_KELVIN,
ATTR_RGB_COLOR,
ATTR_RGBW_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_BRIGHTNESS) 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) is None
@ -685,7 +686,7 @@ async def test_color_temp(hass, enable_custom_integrations):
entity0.supported_color_modes = {ColorMode.COLOR_TEMP}
entity0.color_mode = ColorMode.COLOR_TEMP
entity0.brightness = 255
entity0.color_temp = 2
entity0.color_temp_kelvin = 2
entity1 = platform.ENTITIES[1]
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")
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_COLOR_MODES] == ["color_temp"]
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": [entity1.entity_id], ATTR_COLOR_TEMP: 1000},
{"entity_id": [entity1.entity_id], ATTR_COLOR_TEMP_KELVIN: 1000},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
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_COLOR_MODES] == ["color_temp"]
@ -736,7 +737,7 @@ async def test_color_temp(hass, enable_custom_integrations):
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
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_COLOR_MODES] == ["color_temp"]
@ -819,14 +820,14 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
entity0 = platform.ENTITIES[0]
entity0.supported_color_modes = {ColorMode.COLOR_TEMP}
entity0.color_mode = ColorMode.COLOR_TEMP
entity0.color_temp = 2
entity0.min_mireds = 2
entity0.max_mireds = 5
entity0.color_temp_kelvin = 2
entity0.min_color_temp_kelvin = 2
entity0.max_color_temp_kelvin = 5
entity1 = platform.ENTITIES[1]
entity1.supported_features = SUPPORT_COLOR_TEMP
entity1.min_mireds = 1
entity1.max_mireds = 1234567890
entity1.min_color_temp_kelvin = 1
entity1.max_color_temp_kelvin = 1234567890
assert await async_setup_component(
hass,
@ -848,8 +849,8 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_MIN_MIREDS] == 1
assert state.attributes[ATTR_MAX_MIREDS] == 1234567890
assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 1
assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 1234567890
await hass.services.async_call(
"light",
@ -859,8 +860,8 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_MIN_MIREDS] == 1
assert state.attributes[ATTR_MAX_MIREDS] == 1234567890
assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 1
assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 1234567890
await hass.services.async_call(
"light",
@ -870,8 +871,8 @@ async def test_min_max_mireds(hass, enable_custom_integrations):
)
await hass.async_block_till_done()
state = hass.states.get("light.light_group")
assert state.attributes[ATTR_MIN_MIREDS] == 1
assert state.attributes[ATTR_MAX_MIREDS] == 1234567890
assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 1
assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 1234567890
async def test_effect_list(hass):
@ -1448,7 +1449,7 @@ async def test_invalid_service_calls(hass):
ATTR_BRIGHTNESS: 150,
ATTR_XY_COLOR: (0.5, 0.42),
ATTR_RGB_COLOR: (80, 120, 50),
ATTR_COLOR_TEMP: 1234,
ATTR_COLOR_TEMP_KELVIN: 1234,
ATTR_EFFECT: "Sunshine",
ATTR_TRANSITION: 4,
ATTR_FLASH: "long",

View File

@ -1193,7 +1193,7 @@ async def test_light_backwards_compatibility_color_mode(
entity2 = platform.ENTITIES[2]
entity2.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR_TEMP
entity2.color_temp = 100
entity2.color_temp_kelvin = 10000
entity3 = platform.ENTITIES[3]
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
)
entity4.hs_color = (240, 100)
entity4.color_temp = 100
entity4.color_temp_kelvin = 10000
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
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.max_mireds == 500
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"}})
await hass.async_block_till_done()

View File

@ -37,13 +37,13 @@ class MockLight(MockToggleEntity, LightEntity):
"""Mock light class."""
color_mode = None
max_mireds = 500
min_mireds = 153
max_color_temp_kelvin = 6500
min_color_temp_kelvin = 2000
supported_color_modes = None
supported_features = 0
brightness = None
color_temp = None
color_temp_kelvin = None
hs_color = None
rgb_color = None
rgbw_color = None
@ -61,7 +61,7 @@ class MockLight(MockToggleEntity, LightEntity):
"rgb_color",
"rgbw_color",
"rgbww_color",
"color_temp",
"color_temp_kelvin",
]:
setattr(self, key, value)
if key == "white":