Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed webcolors dependency in favor of dictionary lookup. #2215

Merged
merged 4 commits into from
Jun 9, 2016

Conversation

mikebarris
Copy link
Contributor

@mikebarris mikebarris commented Jun 2, 2016

Description:
Removed webcolors module in favor of dictionary lookup.

Related issue (if applicable): fixes #
https://www.pivotaltracker.com/story/show/120785401

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#

Example entry for configuration.yaml (if applicable):

Checklist:

If user exposed functionality or configuration variables are added/changed:

If code communicates with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.


HASS_COLOR_MAX = 500 # mireds (inverted)
HASS_COLOR_MIN = 154


def color_name_to_rgb(color_name):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

farcy v1.1

  • D202: No blank lines allowed after function docstring (found 1)
  • D210: No whitespaces allowed surrounding docstring text
  • D401: First line should be in imperative mood ('Convert', not 'Converts')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


HASS_COLOR_MAX = 500 # mireds (inverted)
HASS_COLOR_MIN = 154


def color_name_to_rgb(color_name):
"""Convert color name to RGB hex value."""
colors = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a constant in this module so that the Python interpreter will not be required to rebuild it every time this function is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Moved to module. Thanks

'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)}
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this without a try.

hex_value = colors.get(color_name.lower())

if not hex_value:
    _LOGGER.....
    hex_value = (255, 255, 255)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with this suggestion to keep log message.

@balloob
Copy link
Member

balloob commented Jun 9, 2016

Looks good! 🐬

@balloob balloob merged commit 5223d20 into home-assistant:dev Jun 9, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants