Skip to content

Improve validation of device trigger config#26910

Merged
emontnemery merged 7 commits into
home-assistant:devfrom
emontnemery:device_trigger_config_validation
Sep 27, 2019
Merged

Improve validation of device trigger config#26910
emontnemery merged 7 commits into
home-assistant:devfrom
emontnemery:device_trigger_config_validation

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

Description:

Improve validation of device trigger config.
This only includes trigger part from #26830

Improve both when loading at startup, and when an automation is modified through the automation editor UI.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the [development checklist][dev-checklist]

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

return {CONF_ID: self._id}


async def async_validate_config_item(hass, config, full_config):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's move this into a new file config.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

return config


async def async_validate_config(hass, config):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This too .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed


# mypy: allow-untyped-defs, no-check-untyped-defs

TRIGGER_SCHEMA = vol.Schema(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should expand the TRIGGER_BASE_SCHEMA from device_automation and add extra=vol.ALLOW_EXTRA

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
TRIGGER_SCHEMA = vol.Schema(
TRIGGER_SCHEMA = device_automation.TRIGGER_BASE_SCHEMA.extend(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed


async def async_validate_trigger_config(hass, config):
"""Validate config."""
return await device_automation.async_validate_trigger_config(hass, config)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's inline this function here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread homeassistant/config.py
# Check if the integration has a custom config validator
config_validator = None
try:
config_validator = integration.get_platform("config")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note, we should add dev docs for this right away.

@emontnemery emontnemery merged commit e57e7e8 into home-assistant:dev Sep 27, 2019
@lock lock Bot locked and limited conversation to collaborators Sep 28, 2019
@emontnemery emontnemery deleted the device_trigger_config_validation branch October 3, 2019 16:35
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