Allow toggle to accept parameters#4745
Conversation
|
@michaelarnauts, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @jaharkes and @pvizeli to be potential reviewers. |
pvizeli
left a comment
There was a problem hiding this comment.
You solution look like a bit of hack. service_toggle is a core Service and used on many component.
So you need add unittest for your changes.
| ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]), | ||
| }) | ||
|
|
||
| LIGHT_TOGGLE_SCHEMA = vol.Schema({ |
There was a problem hiding this comment.
Don't remove this, extend your Schema.
There was a problem hiding this comment.
I copied the schema from turn_on
| hass.services.async_register( | ||
| DOMAIN, SERVICE_TOGGLE, async_handle_light_service, | ||
| descriptions.get(SERVICE_TOGGLE), schema=LIGHT_TOGGLE_SCHEMA) | ||
| descriptions.get(SERVICE_TOGGLE), schema=LIGHT_TURN_ON_SCHEMA) |
There was a problem hiding this comment.
Turn on is not toggle. see above.
There was a problem hiding this comment.
The point is that SERVICE_TOGGLE can do everything SERVICE_TURNON can do, therefore the LIGHT_TOGGLE_SCHEMA is identical to LIGHT_TOGGLE_SCHEMA. Do you still want to make a seperate schema for this? Should I do something like the following then?
LIGHT_TOGGLE_SCHEMA = LIGHT_TURN_ON_SCHEMA.extend()| description: Duration in seconds it takes to get to next state | ||
| example: 60 | ||
|
|
||
| rgb_color: |
There was a problem hiding this comment.
Don't copy stuff. Make a comment of possibility
There was a problem hiding this comment.
How should I do this?
|
This is going to affect every single component and platform that is using It's also going to be very difficult to actually implement in every component because now you need to create service parameter attribute validation for every toggle platform that validates as both TURN_ON and TURN_OFF schemas. Having a bunch of attributes be either used for turn on or turn off seems like a bad idea to me. |
|
@balloob should all calls be modified? The tests are running fine. Currently, they are not passing parameters, so if I'm correctly, nothing has to change if the component doesn't want to pass parameters to toggle. Before my change, there was a parameter |
|
What about passing only the parameters to Do note that ToggleEntity used to behave this way before Nov 4. |
|
In your referenced commit I made sure that the signature was exactly the same as the signature from the method that it was overriding in I think that the solution here is to make This will make it backwards compatible with the existing toggle and will make sure that platforms only have to expect 1 set of data in their platforms. |
|
Hmm, sounds logical, but I'm afraid that's something I can't do without some help. Shouldn't voloptuous filter out wrong parameters automatically? Should the SCHEMA for toggle be dropped then, since it will be the one from toggle on or toggle off? |
|
Once the toggle service gets called, we're inside the entity. Data validation happens before toggle gets called so we don't know if it is to turn on or off. |
|
We could circumvent this by having |
|
Yeah, I think also we should call the service for handle this case. But the challenge is to handle/filter params to right service... |
|
I think it will mean that toggle is no longer handled on an entity but instead 100% handled inside a service. |
| return self.async_turn_off(**kwargs) | ||
| else: | ||
| return self.async_turn_on() | ||
| return self.async_turn_on(**kwargs) No newline at end of file |
| else: | ||
| return self.async_turn_on() | ||
| return self.async_turn_on(**kwargs) | ||
|
|
| else: | ||
| return self.async_turn_on() | ||
| return self.async_turn_on(**kwargs) | ||
|
|
|
Hmm, aren't "no newline at end of file" and "blank line at end of file" two conflicting remarks? |
|
No, there is a difference between nothing, |
|
This PR seems to have gone stale. Closing it. You can reopen it when you're ready to finish it. |
Description:
This PR modifies the
toggleservice to accept parameters. Those parameters could be used to toggle a light and turn it on full brightness if it was dimmed before it was turned off.See #4360 for a use case.
Basicly, it allows you to do this:
instead of this workaround:
Related issue (if applicable): fixes #4360
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>
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass