mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Removed webcolors dependency in favor of dictionary lookup. (#2215)
* Removed webcolors dependency in favor of dictionary lookup. * Fixed code style errors. * Moved color dictionary to module per suggestion. * Removed try/except per suggestion.
This commit is contained in:
parent
ce829d194c
commit
5223d20668
@ -1,10 +1,35 @@
|
||||
"""Color util methods."""
|
||||
import logging
|
||||
import math
|
||||
# pylint: disable=unused-import
|
||||
from webcolors import html5_parse_legacy_color as color_name_to_rgb # noqa
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
HASS_COLOR_MAX = 500 # mireds (inverted)
|
||||
HASS_COLOR_MIN = 154
|
||||
COLORS = {
|
||||
'white': (255, 255, 255), 'beige': (245, 245, 220),
|
||||
'tan': (210, 180, 140), 'gray': (128, 128, 128),
|
||||
'navy blue': (0, 0, 128), 'royal blue': (8, 76, 158),
|
||||
'blue': (0, 0, 255), 'azure': (0, 127, 255), 'aqua': (127, 255, 212),
|
||||
'teal': (0, 128, 128), 'green': (0, 255, 0),
|
||||
'forest green': (34, 139, 34), 'olive': (128, 128, 0),
|
||||
'chartreuse': (127, 255, 0), 'lime': (191, 255, 0),
|
||||
'golden': (255, 215, 0), 'red': (255, 0, 0), 'coral': (0, 63, 72),
|
||||
'hot pink': (252, 15, 192), 'fuchsia': (255, 119, 255),
|
||||
'lavender': (181, 126, 220), 'indigo': (75, 0, 130),
|
||||
'maroon': (128, 0, 0), 'crimson': (220, 20, 60)}
|
||||
|
||||
|
||||
def color_name_to_rgb(color_name):
|
||||
"""Convert color name to RGB hex value."""
|
||||
hex_value = COLORS.get(color_name.lower())
|
||||
|
||||
if not hex_value:
|
||||
_LOGGER.error('unknown color supplied %s default to white', color_name)
|
||||
hex_value = COLORS['white']
|
||||
|
||||
return hex_value
|
||||
|
||||
|
||||
# Taken from:
|
||||
|
@ -5,7 +5,6 @@ pytz>=2016.4
|
||||
pip>=7.0.0
|
||||
jinja2>=2.8
|
||||
voluptuous==0.8.9
|
||||
webcolors==1.5
|
||||
|
||||
# homeassistant.components.isy994
|
||||
PyISY==1.0.6
|
||||
|
1
setup.py
1
setup.py
@ -17,7 +17,6 @@ REQUIRES = [
|
||||
'pip>=7.0.0',
|
||||
'jinja2>=2.8',
|
||||
'voluptuous==0.8.9',
|
||||
'webcolors==1.5',
|
||||
]
|
||||
|
||||
setup(
|
||||
|
@ -59,6 +59,22 @@ class TestColorUtil(unittest.TestCase):
|
||||
self.assertEqual([51, 153, 255, 0],
|
||||
color_util.rgb_hex_to_rgb_list('3399ff00'))
|
||||
|
||||
def test_color_name_to_rgb_valid_name(self):
|
||||
"""Test color_name_to_rgb."""
|
||||
self.assertEqual((255, 0, 0),
|
||||
color_util.color_name_to_rgb('red'))
|
||||
|
||||
self.assertEqual((0, 0, 255),
|
||||
color_util.color_name_to_rgb('blue'))
|
||||
|
||||
self.assertEqual((0, 255, 0),
|
||||
color_util.color_name_to_rgb('green'))
|
||||
|
||||
def test_color_name_to_rgb_unknown_name_default_white(self):
|
||||
"""Test color_name_to_rgb."""
|
||||
self.assertEqual((255, 255, 255),
|
||||
color_util.color_name_to_rgb('not a color'))
|
||||
|
||||
|
||||
class ColorTemperatureMiredToKelvinTests(unittest.TestCase):
|
||||
"""Test color_temperature_mired_to_kelvin."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user