mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
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:
parent
9527390736
commit
d1121478ab
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user