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):