Improve Philips Hue color conversion 2 (#20118)
* Add gamut capability to color util * Include gamut in hue_test * Improve Philips Hue color conversion * correct import for new location hue.light * include file changes between PR's * update aiohue version * update aiohue version * update aiohue version * fix hue_test Now Idea why it failed compared to the previous time * Include gamut in hue_test * fix hue_test * Try to test hue gamut conversion supply a color that is well outside the color gamut of the light, and see if the response is correctly converted to within the reach of the light. * switch from gamut A to gamut B for the tests. * remove white space in blanck line * Fix gamut hue test * Add Gamut tests for the util.color * fix hue gamut test * fix hue gamut test * Improve Philips Hue color conversion
This commit is contained in:
1 parent
a3f0d55737
commit
11602c1da0
7 files changed
+342
-34
No files matched your search
@@ -85,6 +85,16 @@ LIGHT_1_ON = {
|
||||
"colormode": "xy",
|
||||
"reachable": True
|
||||
},
|
||||
"capabilities": {
|
||||
"control": {
|
||||
"colorgamuttype": "A",
|
||||
"colorgamut": [
|
||||
[0.704, 0.296],
|
||||
[0.2151, 0.7106],
|
||||
[0.138, 0.08]
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "Extended color light",
|
||||
"name": "Hue Lamp 1",
|
||||
"modelid": "LCT001",
|
||||
@@ -105,6 +115,16 @@ LIGHT_1_OFF = {
|
||||
"colormode": "xy",
|
||||
"reachable": True
|
||||
},
|
||||
"capabilities": {
|
||||
"control": {
|
||||
"colorgamuttype": "A",
|
||||
"colorgamut": [
|
||||
[0.704, 0.296],
|
||||
[0.2151, 0.7106],
|
||||
[0.138, 0.08]
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "Extended color light",
|
||||
"name": "Hue Lamp 1",
|
||||
"modelid": "LCT001",
|
||||
@@ -125,6 +145,16 @@ LIGHT_2_OFF = {
|
||||
"colormode": "hs",
|
||||
"reachable": True
|
||||
},
|
||||
"capabilities": {
|
||||
"control": {
|
||||
"colorgamuttype": "A",
|
||||
"colorgamut": [
|
||||
[0.704, 0.296],
|
||||
[0.2151, 0.7106],
|
||||
[0.138, 0.08]
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "Extended color light",
|
||||
"name": "Hue Lamp 2",
|
||||
"modelid": "LCT001",
|
||||
@@ -145,6 +175,16 @@ LIGHT_2_ON = {
|
||||
"colormode": "hs",
|
||||
"reachable": True
|
||||
},
|
||||
"capabilities": {
|
||||
"control": {
|
||||
"colorgamuttype": "A",
|
||||
"colorgamut": [
|
||||
[0.704, 0.296],
|
||||
[0.2151, 0.7106],
|
||||
[0.138, 0.08]
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "Extended color light",
|
||||
"name": "Hue Lamp 2 new",
|
||||
"modelid": "LCT001",
|
||||
@@ -156,6 +196,23 @@ LIGHT_RESPONSE = {
|
||||
"1": LIGHT_1_ON,
|
||||
"2": LIGHT_2_OFF,
|
||||
}
|
||||
LIGHT_RAW = {
|
||||
"capabilities": {
|
||||
"control": {
|
||||
"colorgamuttype": "A",
|
||||
"colorgamut": [
|
||||
[0.704, 0.296],
|
||||
[0.2151, 0.7106],
|
||||
[0.138, 0.08]
|
||||
]
|
||||
}
|
||||
},
|
||||
"swversion": "66009461",
|
||||
}
|
||||
LIGHT_GAMUT = color.GamutType(color.XYPoint(0.704, 0.296),
|
||||
color.XYPoint(0.2151, 0.7106),
|
||||
color.XYPoint(0.138, 0.08))
|
||||
LIGHT_GAMUT_TYPE = 'A'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -380,6 +437,16 @@ async def test_new_light_discovered(hass, mock_bridge):
|
||||
"colormode": "hs",
|
||||
"reachable": True
|
||||
},
|
||||
"capabilities": {
|
||||
"control": {
|
||||
"colorgamuttype": "A",
|
||||
"colorgamut": [
|
||||
[0.704, 0.296],
|
||||
[0.2151, 0.7106],
|
||||
[0.138, 0.08]
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "Extended color light",
|
||||
"name": "Hue Lamp 3",
|
||||
"modelid": "LCT001",
|
||||
@@ -493,6 +560,16 @@ async def test_other_light_update(hass, mock_bridge):
|
||||
"colormode": "hs",
|
||||
"reachable": True
|
||||
},
|
||||
"capabilities": {
|
||||
"control": {
|
||||
"colorgamuttype": "A",
|
||||
"colorgamut": [
|
||||
[0.704, 0.296],
|
||||
[0.2151, 0.7106],
|
||||
[0.138, 0.08]
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "Extended color light",
|
||||
"name": "Hue Lamp 2 new",
|
||||
"modelid": "LCT001",
|
||||
@@ -573,6 +650,21 @@ async def test_light_turn_on_service(hass, mock_bridge):
|
||||
assert light is not None
|
||||
assert light.state == 'on'
|
||||
|
||||
# test hue gamut in turn_on service
|
||||
await hass.services.async_call('light', 'turn_on', {
|
||||
'entity_id': 'light.hue_lamp_2',
|
||||
'rgb_color': [0, 0, 255],
|
||||
}, blocking=True)
|
||||
|
||||
assert len(mock_bridge.mock_requests) == 5
|
||||
|
||||
assert mock_bridge.mock_requests[3]['json'] == {
|
||||
'on': True,
|
||||
'xy': (0.138, 0.08),
|
||||
'effect': 'none',
|
||||
'alert': 'none',
|
||||
}
|
||||
|
||||
|
||||
async def test_light_turn_off_service(hass, mock_bridge):
|
||||
"""Test calling the turn on service on a light."""
|
||||
@@ -608,7 +700,8 @@ async def test_light_turn_off_service(hass, mock_bridge):
|
||||
def test_available():
|
||||
"""Test available property."""
|
||||
light = hue_light.HueLight(
|
||||
light=Mock(state={'reachable': False}),
|
||||
light=Mock(state={'reachable': False},
|
||||
raw=LIGHT_RAW),
|
||||
request_bridge_update=None,
|
||||
bridge=Mock(allow_unreachable=False),
|
||||
is_group=False,
|
||||
@@ -617,7 +710,8 @@ def test_available():
|
||||
assert light.available is False
|
||||
|
||||
light = hue_light.HueLight(
|
||||
light=Mock(state={'reachable': False}),
|
||||
light=Mock(state={'reachable': False},
|
||||
raw=LIGHT_RAW),
|
||||
request_bridge_update=None,
|
||||
bridge=Mock(allow_unreachable=True),
|
||||
is_group=False,
|
||||
@@ -626,7 +720,8 @@ def test_available():
|
||||
assert light.available is True
|
||||
|
||||
light = hue_light.HueLight(
|
||||
light=Mock(state={'reachable': False}),
|
||||
light=Mock(state={'reachable': False},
|
||||
raw=LIGHT_RAW),
|
||||
request_bridge_update=None,
|
||||
bridge=Mock(allow_unreachable=False),
|
||||
is_group=True,
|
||||
@@ -639,10 +734,13 @@ def test_hs_color():
|
||||
"""Test hs_color property."""
|
||||
light = hue_light.HueLight(
|
||||
light=Mock(state={
|
||||
'colormode': 'ct',
|
||||
'hue': 1234,
|
||||
'sat': 123,
|
||||
}),
|
||||
'colormode': 'ct',
|
||||
'hue': 1234,
|
||||
'sat': 123,
|
||||
},
|
||||
raw=LIGHT_RAW,
|
||||
colorgamuttype=LIGHT_GAMUT_TYPE,
|
||||
colorgamut=LIGHT_GAMUT),
|
||||
request_bridge_update=None,
|
||||
bridge=Mock(),
|
||||
is_group=False,
|
||||
@@ -652,10 +750,13 @@ def test_hs_color():
|
||||
|
||||
light = hue_light.HueLight(
|
||||
light=Mock(state={
|
||||
'colormode': 'hs',
|
||||
'hue': 1234,
|
||||
'sat': 123,
|
||||
}),
|
||||
'colormode': 'hs',
|
||||
'hue': 1234,
|
||||
'sat': 123,
|
||||
},
|
||||
raw=LIGHT_RAW,
|
||||
colorgamuttype=LIGHT_GAMUT_TYPE,
|
||||
colorgamut=LIGHT_GAMUT),
|
||||
request_bridge_update=None,
|
||||
bridge=Mock(),
|
||||
is_group=False,
|
||||
@@ -665,14 +766,17 @@ def test_hs_color():
|
||||
|
||||
light = hue_light.HueLight(
|
||||
light=Mock(state={
|
||||
'colormode': 'xy',
|
||||
'hue': 1234,
|
||||
'sat': 123,
|
||||
'xy': [0.4, 0.5]
|
||||
}),
|
||||
'colormode': 'xy',
|
||||
'hue': 1234,
|
||||
'sat': 123,
|
||||
'xy': [0.4, 0.5]
|
||||
},
|
||||
raw=LIGHT_RAW,
|
||||
colorgamuttype=LIGHT_GAMUT_TYPE,
|
||||
colorgamut=LIGHT_GAMUT),
|
||||
request_bridge_update=None,
|
||||
bridge=Mock(),
|
||||
is_group=False,
|
||||
)
|
||||
|
||||
assert light.hs_color == color.color_xy_to_hs(0.4, 0.5)
|
||||
assert light.hs_color == color.color_xy_to_hs(0.4, 0.5, LIGHT_GAMUT)
|
||||
@@ -5,6 +5,10 @@ import homeassistant.util.color as color_util
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
GAMUT = color_util.GamutType(color_util.XYPoint(0.704, 0.296),
|
||||
color_util.XYPoint(0.2151, 0.7106),
|
||||
color_util.XYPoint(0.138, 0.08))
|
||||
|
||||
|
||||
class TestColorUtil(unittest.TestCase):
|
||||
"""Test color util methods."""
|
||||
@@ -29,6 +33,15 @@ class TestColorUtil(unittest.TestCase):
|
||||
assert (0.701, 0.299, 16) == \
|
||||
color_util.color_RGB_to_xy_brightness(128, 0, 0)
|
||||
|
||||
assert (0.7, 0.299, 72) == \
|
||||
color_util.color_RGB_to_xy_brightness(255, 0, 0, GAMUT)
|
||||
|
||||
assert (0.215, 0.711, 170) == \
|
||||
color_util.color_RGB_to_xy_brightness(0, 255, 0, GAMUT)
|
||||
|
||||
assert (0.138, 0.08, 12) == \
|
||||
color_util.color_RGB_to_xy_brightness(0, 0, 255, GAMUT)
|
||||
|
||||
def test_color_RGB_to_xy(self):
|
||||
"""Test color_RGB_to_xy."""
|
||||
assert (0, 0) == \
|
||||
@@ -48,6 +61,15 @@ class TestColorUtil(unittest.TestCase):
|
||||
assert (0.701, 0.299) == \
|
||||
color_util.color_RGB_to_xy(128, 0, 0)
|
||||
|
||||
assert (0.138, 0.08) == \
|
||||
color_util.color_RGB_to_xy(0, 0, 255, GAMUT)
|
||||
|
||||
assert (0.215, 0.711) == \
|
||||
color_util.color_RGB_to_xy(0, 255, 0, GAMUT)
|
||||
|
||||
assert (0.7, 0.299) == \
|
||||
color_util.color_RGB_to_xy(255, 0, 0, GAMUT)
|
||||
|
||||
def test_color_xy_brightness_to_RGB(self):
|
||||
"""Test color_xy_brightness_to_RGB."""
|
||||
assert (0, 0, 0) == \
|
||||
@@ -68,6 +90,15 @@ class TestColorUtil(unittest.TestCase):
|
||||
assert (0, 63, 255) == \
|
||||
color_util.color_xy_brightness_to_RGB(0, 0, 255)
|
||||
|
||||
assert (255, 0, 3) == \
|
||||
color_util.color_xy_brightness_to_RGB(1, 0, 255, GAMUT)
|
||||
|
||||
assert (82, 255, 0) == \
|
||||
color_util.color_xy_brightness_to_RGB(0, 1, 255, GAMUT)
|
||||
|
||||
assert (9, 85, 255) == \
|
||||
color_util.color_xy_brightness_to_RGB(0, 0, 255, GAMUT)
|
||||
|
||||
def test_color_xy_to_RGB(self):
|
||||
"""Test color_xy_to_RGB."""
|
||||
assert (255, 243, 222) == \
|
||||
@@ -82,6 +113,15 @@ class TestColorUtil(unittest.TestCase):
|
||||
assert (0, 63, 255) == \
|
||||
color_util.color_xy_to_RGB(0, 0)
|
||||
|
||||
assert (255, 0, 3) == \
|
||||
color_util.color_xy_to_RGB(1, 0, GAMUT)
|
||||
|
||||
assert (82, 255, 0) == \
|
||||
color_util.color_xy_to_RGB(0, 1, GAMUT)
|
||||
|
||||
assert (9, 85, 255) == \
|
||||
color_util.color_xy_to_RGB(0, 0, GAMUT)
|
||||
|
||||
def test_color_RGB_to_hsv(self):
|
||||
"""Test color_RGB_to_hsv."""
|
||||
assert (0, 0, 0) == \
|
||||
@@ -150,6 +190,15 @@ class TestColorUtil(unittest.TestCase):
|
||||
assert (225.176, 100) == \
|
||||
color_util.color_xy_to_hs(0, 0)
|
||||
|
||||
assert (359.294, 100) == \
|
||||
color_util.color_xy_to_hs(1, 0, GAMUT)
|
||||
|
||||
assert (100.706, 100) == \
|
||||
color_util.color_xy_to_hs(0, 1, GAMUT)
|
||||
|
||||
assert (221.463, 96.471) == \
|
||||
color_util.color_xy_to_hs(0, 0, GAMUT)
|
||||
|
||||
def test_color_hs_to_xy(self):
|
||||
"""Test color_hs_to_xy."""
|
||||
assert (0.151, 0.343) == \
|
||||
@@ -167,6 +216,21 @@ class TestColorUtil(unittest.TestCase):
|
||||
assert (0.323, 0.329) == \
|
||||
color_util.color_hs_to_xy(360, 0)
|
||||
|
||||
assert (0.7, 0.299) == \
|
||||
color_util.color_hs_to_xy(0, 100, GAMUT)
|
||||
|
||||
assert (0.215, 0.711) == \
|
||||
color_util.color_hs_to_xy(120, 100, GAMUT)
|
||||
|
||||
assert (0.17, 0.34) == \
|
||||
color_util.color_hs_to_xy(180, 100, GAMUT)
|
||||
|
||||
assert (0.138, 0.08) == \
|
||||
color_util.color_hs_to_xy(240, 100, GAMUT)
|
||||
|
||||
assert (0.7, 0.299) == \
|
||||
color_util.color_hs_to_xy(360, 100, GAMUT)
|
||||
|
||||
def test_rgb_hex_to_rgb_list(self):
|
||||
"""Test rgb_hex_to_rgb_list."""
|
||||
assert [255, 255, 255] == \
|
||||
|
||||
Reference in new issue
Block a user