Add context to event trigger#40932
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with an integration ( |
| extra=vol.ALLOW_EXTRA, | ||
| ) | ||
| event_data_schema = _populate_schema(config, CONF_EVENT_DATA) | ||
| event_context_schema = _populate_schema(config, CONF_EVENT_CONTEXT) |
There was a problem hiding this comment.
Just realized that matching straight up on context like this is going to be annoying if one wants to match multiple users.
There was a problem hiding this comment.
Good point. How about something like:
if isinstance(value, list):
vol.Required(key): vol.In(value)
else:
vol.Required(key): valuewhen building the schema? This can also be used for event_data, not just context.
There was a problem hiding this comment.
Downside is that this could be a breaking change if the user intended to match a list.
There was a problem hiding this comment.
I changed it here:
#41036
To ensure backwards compatibility I only added this for context, not data, even though I think it could be a nice touch for data as well.
|
|
||
|
|
||
| def _populate_schema(config, config_parameter): | ||
| if config_parameter not in config: |
There was a problem hiding this comment.
The existing behavior was changed slightly with this check. The old check only set an event data schema if the config had a populated event data dict. The current check sets a schema as long as the event data key is in the config. It doesn't check for a truthy event data dict.
There was a problem hiding this comment.
Good catch. I'm not sure this makes any practical difference (since the schema will be empty), but I'll fix this together with the multiple user selection below.
There was a problem hiding this comment.
Proposed change
As proposed in home-assistant/architecture#436, this adds backend support for event triggers to filter by context.
Type of change
Example entry for
configuration.yaml:Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: