mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add tests for color util
This commit is contained in:
parent
05cbe54db3
commit
ef132e4583
@ -47,6 +47,7 @@ def color_RGB_to_xy(R, G, B):
|
||||
|
||||
# taken from
|
||||
# https://github.com/benknight/hue-python-rgb-converter/blob/master/rgb_cie.py
|
||||
# Copyright (c) 2014 Benjamin Knight / MIT License.
|
||||
# pylint: disable=bad-builtin
|
||||
def color_xy_brightness_to_RGB(vX, vY, brightness):
|
||||
'''
|
||||
@ -57,12 +58,12 @@ def color_xy_brightness_to_RGB(vX, vY, brightness):
|
||||
return (0, 0, 0)
|
||||
|
||||
Y = brightness
|
||||
if vY != 0:
|
||||
X = (Y / vY) * vX
|
||||
Z = (Y / vY) * (1 - vX - vY)
|
||||
else:
|
||||
X = 0
|
||||
Z = 0
|
||||
|
||||
if vY == 0:
|
||||
vY += 0.00000000001
|
||||
|
||||
X = (Y / vY) * vX
|
||||
Z = (Y / vY) * (1 - vX - vY)
|
||||
|
||||
# Convert to RGB using Wide RGB D65 conversion.
|
||||
r = X * 1.612 - Y * 0.203 - Z * 0.302
|
||||
|
@ -20,3 +20,20 @@ class TestColorUtil(unittest.TestCase):
|
||||
|
||||
self.assertEqual((0.6400744994567747, 0.3299705106316933),
|
||||
color_util.color_RGB_to_xy(255, 0, 0))
|
||||
|
||||
def test_color_xy_brightness_to_RGB(self):
|
||||
""" Test color_RGB_to_xy. """
|
||||
self.assertEqual((0, 0, 0),
|
||||
color_util.color_xy_brightness_to_RGB(1, 1, 0))
|
||||
|
||||
self.assertEqual((255, 235, 214),
|
||||
color_util.color_xy_brightness_to_RGB(.35, .35, 255))
|
||||
|
||||
self.assertEqual((255, 0, 45),
|
||||
color_util.color_xy_brightness_to_RGB(1, 0, 255))
|
||||
|
||||
self.assertEqual((0, 255, 0),
|
||||
color_util.color_xy_brightness_to_RGB(0, 1, 255))
|
||||
|
||||
self.assertEqual((0, 83, 255),
|
||||
color_util.color_xy_brightness_to_RGB(0, 0, 255))
|
||||
|
Loading…
x
Reference in New Issue
Block a user