mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Make util.color._match_max_scale public (#59207)
This commit is contained in:
parent
61e4ebf155
commit
f8f060b72b
@ -404,8 +404,8 @@ def color_hs_to_xy(
|
||||
return color_RGB_to_xy(*color_hs_to_RGB(iH, iS), Gamut)
|
||||
|
||||
|
||||
def _match_max_scale(
|
||||
input_colors: tuple[int, ...], output_colors: tuple[int, ...]
|
||||
def match_max_scale(
|
||||
input_colors: tuple[int, ...], output_colors: tuple[float, ...]
|
||||
) -> tuple[int, ...]:
|
||||
"""Match the maximum value of the output to the input."""
|
||||
max_in = max(input_colors)
|
||||
@ -426,7 +426,7 @@ def color_rgb_to_rgbw(r: int, g: int, b: int) -> tuple[int, int, int, int]:
|
||||
|
||||
# Match the output maximum value to the input. This ensures the full
|
||||
# channel range is used.
|
||||
return _match_max_scale((r, g, b), rgbw) # type: ignore
|
||||
return match_max_scale((r, g, b), rgbw) # type: ignore[return-value]
|
||||
|
||||
|
||||
def color_rgbw_to_rgb(r: int, g: int, b: int, w: int) -> tuple[int, int, int]:
|
||||
@ -436,7 +436,7 @@ def color_rgbw_to_rgb(r: int, g: int, b: int, w: int) -> tuple[int, int, int]:
|
||||
|
||||
# Match the output maximum value to the input. This ensures the
|
||||
# output doesn't overflow.
|
||||
return _match_max_scale((r, g, b, w), rgb) # type: ignore
|
||||
return match_max_scale((r, g, b, w), rgb) # type: ignore[return-value]
|
||||
|
||||
|
||||
def color_rgb_to_rgbww(
|
||||
@ -458,7 +458,7 @@ def color_rgb_to_rgbww(
|
||||
|
||||
# Match the output maximum value to the input. This ensures the full
|
||||
# channel range is used.
|
||||
return _match_max_scale((r, g, b), rgbww) # type: ignore
|
||||
return match_max_scale((r, g, b), rgbww) # type: ignore[return-value]
|
||||
|
||||
|
||||
def color_rgbww_to_rgb(
|
||||
@ -481,7 +481,7 @@ def color_rgbww_to_rgb(
|
||||
|
||||
# Match the output maximum value to the input. This ensures the
|
||||
# output doesn't overflow.
|
||||
return _match_max_scale((r, g, b, cw, ww), rgb) # type: ignore
|
||||
return match_max_scale((r, g, b, cw, ww), rgb) # type: ignore[return-value]
|
||||
|
||||
|
||||
def color_rgb_to_hex(r: int, g: int, b: int) -> str:
|
||||
|
@ -279,6 +279,20 @@ def test_color_rgb_to_hex():
|
||||
assert color_util.color_rgb_to_hex(255, 67.9204190, 0) == "ff4400"
|
||||
|
||||
|
||||
def test_match_max_scale():
|
||||
"""Test match_max_scale."""
|
||||
match_max_scale = color_util.match_max_scale
|
||||
assert match_max_scale((255, 255, 255), (255, 255, 255)) == (255, 255, 255)
|
||||
assert match_max_scale((0, 0, 0), (0, 0, 0)) == (0, 0, 0)
|
||||
assert match_max_scale((255, 255, 255), (128, 128, 128)) == (255, 255, 255)
|
||||
assert match_max_scale((0, 255, 0), (64, 128, 128)) == (128, 255, 255)
|
||||
assert match_max_scale((0, 100, 0), (128, 64, 64)) == (100, 50, 50)
|
||||
assert match_max_scale((10, 20, 33), (100, 200, 333)) == (10, 20, 33)
|
||||
assert match_max_scale((255,), (100, 200, 333)) == (77, 153, 255)
|
||||
assert match_max_scale((128,), (10.5, 20.9, 30.4)) == (44, 88, 128)
|
||||
assert match_max_scale((10, 20, 30, 128), (100, 200, 333)) == (38, 77, 128)
|
||||
|
||||
|
||||
def test_gamut():
|
||||
"""Test gamut functions."""
|
||||
assert color_util.check_valid_gamut(GAMUT)
|
||||
|
Loading…
x
Reference in New Issue
Block a user