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

Intent: Set light color #12633

Merged
merged 8 commits into from
Feb 28, 2018
Merged

Intent: Set light color #12633

merged 8 commits into from
Feb 28, 2018

Conversation

balloob
Copy link
Member

@balloob balloob commented Feb 24, 2018

Description:

Add an intent for changing the color of a light.

I initially tried to add this logic into helpers.intent.ServiceIntentHandler but failed miserably. I realized that for the set color service to be supported, I needed to add support for:

  • define custom slot schema (add color)
  • customize entities that we match (because we only want to match light entities)
  • customize service data based on slots
  • define custom response formatting (in case we want to add color to the response)

So after hacking it into it, I realized that I made it only more confusing. So instead, I went with another approach: make reusable pieces of functionality to quickly add together a new intent handler.

I borrowed a trick from aiohttp: if you raise IntentHandlerError, it should be converted to speech for the end user (Snips, Alexa, etc). That way we can have reusable helper methods that can trigger a response when they encounter an error.

CC @tschmidty69

Related issue (if applicable): #12087

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>

Checklist:

  • The code change is tested and works locally.

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.

@balloob balloob requested a review from a team as a code owner February 24, 2018 02:08
@balloob balloob changed the title Light color intent Intent: Set light color Feb 24, 2018
params[ATTR_RGB_COLOR] = color_util.color_name_to_rgb(color_name)
try:
params[ATTR_RGB_COLOR] = color_util.color_name_to_rgb(color_name)
except ValueError:
Copy link
Member Author

Choose a reason for hiding this comment

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

color_name_to_rgb will now raise instead of silently returning white if no match found. I've added that logic back in the only place that depended on it.

@tschmidty69
Copy link
Contributor

The two things I would change would be to change it to HassTurnOnSet and have it support turning on the light and setting brightness as well as color since you wouldn't want to have to Turn it on, Set it to green, and set brightness to 50% as three intents, you would want an intent to handle all of those as one step. "Turn the living room light to green and fifty percent" (turn on implied). And I apologize I won't have too much time to work on the snips side since I am traveling for a conference over the next couple weeks.

@balloob
Copy link
Member Author

balloob commented Feb 24, 2018

Thanks for the feedback and that's a great point! Will address it.

@balloob
Copy link
Member Author

balloob commented Feb 24, 2018

Alright, so I made it now so that you can pass in brightness and color. Response will also be based on whatever was set. This makes even a better case for not basing it off the ServiceIntentHandler. I do wonder if we can generalize it a bit more but we'll see that once we have added a couple more to other components.

@home-assistant home-assistant deleted a comment from houndci-bot Feb 24, 2018
@home-assistant home-assistant deleted a comment from houndci-bot Feb 24, 2018
@balloob balloob merged commit efd155d into dev Feb 28, 2018
@balloob balloob deleted the light-color-intent branch February 28, 2018 02:02
@balloob balloob mentioned this pull request Mar 9, 2018
@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants