Add coverage for color_rgbww_to_rgb, fix divzero case (#65721)

This commit is contained in:
J. Nick Koston 2022-02-05 10:59:32 -06:00 committed by GitHub
parent adbc0e5955
commit 676edb610f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -472,7 +472,10 @@ def color_rgbww_to_rgb(
except ZeroDivisionError:
ct_ratio = 0.5
color_temp_mired = min_mireds + ct_ratio * mired_range
color_temp_kelvin = color_temperature_mired_to_kelvin(color_temp_mired)
if color_temp_mired:
color_temp_kelvin = color_temperature_mired_to_kelvin(color_temp_mired)
else:
color_temp_kelvin = 0
w_r, w_g, w_b = color_temperature_to_rgb(color_temp_kelvin)
white_level = max(cw, ww) / 255

View File

@ -405,6 +405,49 @@ def test_color_rgb_to_rgbww():
assert color_util.color_rgb_to_rgbww(255, 255, 255, 1, 5) == (103, 69, 0, 255, 255)
def test_color_rgbww_to_rgb():
"""Test color_rgbww_to_rgb conversions."""
assert color_util.color_rgbww_to_rgb(0, 54, 98, 255, 255, 154, 370) == (
255,
255,
255,
)
assert color_util.color_rgbww_to_rgb(255, 255, 255, 0, 0, 154, 370) == (
255,
255,
255,
)
assert color_util.color_rgbww_to_rgb(0, 118, 241, 255, 255, 154, 370) == (
163,
204,
255,
)
assert color_util.color_rgbww_to_rgb(0, 27, 49, 128, 128, 154, 370) == (
128,
128,
128,
)
assert color_util.color_rgbww_to_rgb(0, 14, 25, 64, 64, 154, 370) == (64, 64, 64)
assert color_util.color_rgbww_to_rgb(9, 64, 0, 38, 38, 154, 370) == (32, 64, 16)
assert color_util.color_rgbww_to_rgb(0, 0, 0, 0, 0, 154, 370) == (0, 0, 0)
assert color_util.color_rgbww_to_rgb(103, 69, 0, 255, 255, 153, 370) == (
255,
193,
112,
)
assert color_util.color_rgbww_to_rgb(255, 255, 255, 0, 0, 0, 0) == (255, 255, 255)
assert color_util.color_rgbww_to_rgb(255, 255, 255, 255, 255, 0, 0) == (
255,
161,
128,
)
assert color_util.color_rgbww_to_rgb(255, 255, 255, 255, 255, 0, 370) == (
255,
245,
237,
)
def test_color_temperature_to_rgbww():
"""Test color temp to warm, cold conversion.