Improve color conversion for RGBWW lights (#49807)

This commit is contained in:
Erik Montnemery 2021-04-28 15:46:41 +02:00 committed by GitHub
parent 9e1042d9e0
commit e96cbccc92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 31 deletions

View file

@ -1202,6 +1202,39 @@ async def test_light_state_rgbw(hass):
}
async def test_light_state_rgbww(hass):
"""Test rgbww color conversion in state updates."""
platform = getattr(hass.components, "test.light")
platform.init(empty=True)
platform.ENTITIES.append(platform.MockLight("Test_rgbww", STATE_ON))
entity0 = platform.ENTITIES[0]
entity0.supported_color_modes = {light.COLOR_MODE_RGBWW}
entity0.color_mode = light.COLOR_MODE_RGBWW
entity0.hs_color = "Invalid" # Should be ignored
entity0.rgb_color = "Invalid" # Should be ignored
entity0.rgbw_color = "Invalid" # Should be ignored
entity0.rgbww_color = (1, 2, 3, 4, 5)
entity0.white_value = "Invalid" # Should be ignored
entity0.xy_color = "Invalid" # Should be ignored
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
await hass.async_block_till_done()
state = hass.states.get(entity0.entity_id)
assert dict(state.attributes) == {
"color_mode": light.COLOR_MODE_RGBWW,
"friendly_name": "Test_rgbww",
"supported_color_modes": [light.COLOR_MODE_RGBWW],
"supported_features": 0,
"hs_color": (60.0, 20.0),
"rgb_color": (5, 5, 4),
"rgbww_color": (1, 2, 3, 4, 5),
"xy_color": (0.339, 0.354),
}
async def test_light_service_call_color_conversion(hass):
"""Test color conversion in service calls."""
platform = getattr(hass.components, "test.light")
@ -1332,7 +1365,8 @@ async def test_light_service_call_color_conversion(hass):
_, data = entity5.last_call("turn_on")
assert data == {"brightness": 255, "rgbw_color": (0, 0, 0, 255)}
_, data = entity6.last_call("turn_on")
assert data == {"brightness": 255, "rgbww_color": (255, 255, 255, 0, 0)}
# The midpoint the the white channels is warm, compensated by adding green + blue
assert data == {"brightness": 255, "rgbww_color": (0, 76, 141, 255, 255)}
await hass.services.async_call(
"light",
@ -1398,7 +1432,8 @@ async def test_light_service_call_color_conversion(hass):
_, data = entity5.last_call("turn_on")
assert data == {"brightness": 128, "rgbw_color": (0, 0, 0, 255)}
_, data = entity6.last_call("turn_on")
assert data == {"brightness": 128, "rgbww_color": (255, 255, 255, 0, 0)}
# The midpoint the the white channels is warm, compensated by adding green + blue
assert data == {"brightness": 128, "rgbww_color": (0, 76, 141, 255, 255)}
await hass.services.async_call(
"light",
@ -1464,7 +1499,8 @@ async def test_light_service_call_color_conversion(hass):
_, data = entity5.last_call("turn_on")
assert data == {"brightness": 128, "rgbw_color": (1, 0, 0, 255)}
_, data = entity6.last_call("turn_on")
assert data == {"brightness": 128, "rgbww_color": (255, 254, 254, 0, 0)}
# The midpoint the the white channels is warm, compensated by adding green + blue
assert data == {"brightness": 128, "rgbww_color": (0, 75, 140, 255, 255)}
async def test_light_state_color_conversion(hass):