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 ATTR_XY_COLOR in kwargs:
if self.info.get('manufacturername') == "OSRAM": if self.info.get('manufacturername') == "OSRAM":
hsv = color_util.color_xy_brightness_to_hsv( hue, sat = color_util.color_xy_to_hs(*kwargs[ATTR_XY_COLOR])
*kwargs[ATTR_XY_COLOR], command['hue'] = hue
ibrightness=self.info['bri']) command['sat'] = sat
command['hue'] = hsv[0] command['bri'] = self.info['bri']
command['sat'] = hsv[1]
command['bri'] = hsv[2]
else: else:
command['xy'] = kwargs[ATTR_XY_COLOR] command['xy'] = kwargs[ATTR_XY_COLOR]
elif ATTR_RGB_COLOR in kwargs: elif ATTR_RGB_COLOR in kwargs:

View File

@ -354,10 +354,7 @@ class LIFXLight(Light):
brightness = self._bri brightness = self._bri
if ATTR_XY_COLOR in kwargs: if ATTR_XY_COLOR in kwargs:
hue, saturation, _ = \ hue, saturation = color_util.color_xy_to_hs(*kwargs[ATTR_XY_COLOR])
color_util.color_xy_brightness_to_hsv(
*kwargs[ATTR_XY_COLOR],
ibrightness=255)
saturation = saturation * (BYTE_MAX + 1) saturation = saturation * (BYTE_MAX + 1)
changed_color = True 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 # pylint: disable=invalid-sequence-index
def color_xy_brightness_to_hsv(vX: float, vY: float, def color_xy_to_hs(vX: float, vY: float) -> Tuple[int, int]:
ibrightness: int) -> Tuple[int, int, int]: """Convert an xy color to its hs representation."""
"""Convert an xy brightness color to its hsv representation.""" h, s, _ = color_RGB_to_hsv(*color_xy_brightness_to_RGB(vX, vY, 255))
return color_RGB_to_hsv(*color_xy_brightness_to_RGB(vX, vY, ibrightness)) return (h, s)
# pylint: disable=invalid-sequence-index # pylint: disable=invalid-sequence-index

View File

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