From 2daea92379712af2642962f9471decf35762da8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Osb=C3=A4ck?= Date: Mon, 27 Nov 2017 11:31:35 +0100 Subject: [PATCH] make RGB values consistent as int. fixes #10766 (#10782) * make RGB consitant as int. fixes #10766 * fix rounding and only change for hex convertion --- homeassistant/util/color.py | 2 +- tests/util/test_color.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/util/color.py b/homeassistant/util/color.py index 794f6546113..9c7fa0d70e7 100644 --- a/homeassistant/util/color.py +++ b/homeassistant/util/color.py @@ -357,7 +357,7 @@ def color_rgbw_to_rgb(r, g, b, w): def color_rgb_to_hex(r, g, b): """Return a RGB color from a hex color string.""" - return '{0:02x}{1:02x}{2:02x}'.format(r, g, b) + return '{0:02x}{1:02x}{2:02x}'.format(round(r), round(g), round(b)) def rgb_hex_to_rgb_list(hex_string): diff --git a/tests/util/test_color.py b/tests/util/test_color.py index 4c14258f2f2..8b75e9e9e3f 100644 --- a/tests/util/test_color.py +++ b/tests/util/test_color.py @@ -212,6 +212,7 @@ class TestColorUtil(unittest.TestCase): assert color_util.color_rgb_to_hex(255, 255, 255) == 'ffffff' assert color_util.color_rgb_to_hex(0, 0, 0) == '000000' assert color_util.color_rgb_to_hex(51, 153, 255) == '3399ff' + assert color_util.color_rgb_to_hex(255, 67.9204190, 0) == 'ff4400' class ColorTemperatureMiredToKelvinTests(unittest.TestCase):