Reduce color_xy_brightness_to_hsv to color_xy_to_hs (#7320)

This makes more sense because the input and output brightness is the same.

We currently convert through RGB which does contain a brightness so we supply
an arbitrary value as input and discard the output.
This commit is contained in:
Anders Melchiorsen 2017-04-27 09:59:49 +02:00 committed by Paulus Schoutsen
parent 9527390736
commit d1121478ab
4 changed files with 21 additions and 26 deletions

View File

@ -380,12 +380,10 @@ class HueLight(Light):
if ATTR_XY_COLOR in kwargs:
if self.info.get('manufacturername') == "OSRAM":
hsv = color_util.color_xy_brightness_to_hsv(
*kwargs[ATTR_XY_COLOR],
ibrightness=self.info['bri'])
command['hue'] = hsv[0]
command['sat'] = hsv[1]
command['bri'] = hsv[2]
hue, sat = color_util.color_xy_to_hs(*kwargs[ATTR_XY_COLOR])
command['hue'] = hue
command['sat'] = sat
command['bri'] = self.info['bri']
else:
command['xy'] = kwargs[ATTR_XY_COLOR]
elif ATTR_RGB_COLOR in kwargs:

View File

@ -354,10 +354,7 @@ class LIFXLight(Light):
brightness = self._bri
if ATTR_XY_COLOR in kwargs:
hue, saturation, _ = \
color_util.color_xy_brightness_to_hsv(
*kwargs[ATTR_XY_COLOR],
ibrightness=255)
hue, saturation = color_util.color_xy_to_hs(*kwargs[ATTR_XY_COLOR])
saturation = saturation * (BYTE_MAX + 1)
changed_color = True

View File

@ -268,10 +268,10 @@ def color_RGB_to_hsv(iR: int, iG: int, iB: int) -> Tuple[int, int, int]:
# pylint: disable=invalid-sequence-index
def color_xy_brightness_to_hsv(vX: float, vY: float,
ibrightness: int) -> Tuple[int, int, int]:
"""Convert an xy brightness color to its hsv representation."""
return color_RGB_to_hsv(*color_xy_brightness_to_RGB(vX, vY, ibrightness))
def color_xy_to_hs(vX: float, vY: float) -> Tuple[int, int]:
"""Convert an xy color to its hs representation."""
h, s, _ = color_RGB_to_hsv(*color_xy_brightness_to_RGB(vX, vY, 255))
return (h, s)
# pylint: disable=invalid-sequence-index

View File

@ -56,22 +56,22 @@ class TestColorUtil(unittest.TestCase):
self.assertEqual((0, 255, 255),
color_util.color_RGB_to_hsv(255, 0, 0))
def test_color_xy_brightness_to_hsv(self):
"""Test color_RGB_to_xy."""
self.assertEqual(color_util.color_RGB_to_hsv(0, 0, 0),
color_util.color_xy_brightness_to_hsv(1, 1, 0))
def test_color_xy_to_hs(self):
"""Test color_xy_to_hs."""
self.assertEqual((8609, 255),
color_util.color_xy_to_hs(1, 1))
self.assertEqual(color_util.color_RGB_to_hsv(255, 243, 222),
color_util.color_xy_brightness_to_hsv(.35, .35, 255))
self.assertEqual((6950, 32),
color_util.color_xy_to_hs(.35, .35))
self.assertEqual(color_util.color_RGB_to_hsv(255, 0, 60),
color_util.color_xy_brightness_to_hsv(1, 0, 255))
self.assertEqual((62965, 255),
color_util.color_xy_to_hs(1, 0))
self.assertEqual(color_util.color_RGB_to_hsv(0, 255, 0),
color_util.color_xy_brightness_to_hsv(0, 1, 255))
self.assertEqual((21845, 255),
color_util.color_xy_to_hs(0, 1))
self.assertEqual(color_util.color_RGB_to_hsv(0, 63, 255),
color_util.color_xy_brightness_to_hsv(0, 0, 255))
self.assertEqual((40992, 255),
color_util.color_xy_to_hs(0, 0))
def test_rgb_hex_to_rgb_list(self):
"""Test rgb_hex_to_rgb_list."""