2020-11-02 14:00:13 +00:00
|
|
|
"""Schemas for the blueprint integration."""
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from homeassistant.const import CONF_DOMAIN, CONF_NAME, CONF_PATH
|
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.helpers import config_validation as cv
|
|
|
|
|
2020-11-11 22:32:46 +00:00
|
|
|
from .const import (
|
|
|
|
CONF_BLUEPRINT,
|
|
|
|
CONF_DESCRIPTION,
|
|
|
|
CONF_INPUT,
|
|
|
|
CONF_SOURCE_URL,
|
|
|
|
CONF_USE_BLUEPRINT,
|
|
|
|
)
|
2020-11-02 14:00:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def is_blueprint_config(config: Any) -> bool:
|
|
|
|
"""Return if it is a blueprint config."""
|
|
|
|
return isinstance(config, dict) and CONF_BLUEPRINT in config
|
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def is_blueprint_instance_config(config: Any) -> bool:
|
|
|
|
"""Return if it is a blueprint instance config."""
|
|
|
|
return isinstance(config, dict) and CONF_USE_BLUEPRINT in config
|
|
|
|
|
|
|
|
|
2020-11-11 22:32:46 +00:00
|
|
|
BLUEPRINT_INPUT_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Optional(CONF_NAME): str,
|
|
|
|
vol.Optional(CONF_DESCRIPTION): str,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-11-02 14:00:13 +00:00
|
|
|
BLUEPRINT_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_BLUEPRINT): vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_NAME): str,
|
|
|
|
vol.Required(CONF_DOMAIN): str,
|
2020-11-11 22:32:46 +00:00
|
|
|
vol.Optional(CONF_SOURCE_URL): cv.url,
|
|
|
|
vol.Optional(CONF_INPUT, default=dict): {
|
|
|
|
str: vol.Any(
|
|
|
|
None,
|
|
|
|
BLUEPRINT_INPUT_SCHEMA,
|
|
|
|
)
|
|
|
|
},
|
2020-11-02 14:00:13 +00:00
|
|
|
}
|
|
|
|
),
|
|
|
|
},
|
|
|
|
extra=vol.ALLOW_EXTRA,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def validate_yaml_suffix(value: str) -> str:
|
|
|
|
"""Validate value has a YAML suffix."""
|
|
|
|
if not value.endswith(".yaml"):
|
|
|
|
raise vol.Invalid("Path needs to end in .yaml")
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
BLUEPRINT_INSTANCE_FIELDS = vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_USE_BLUEPRINT): vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_PATH): vol.All(cv.path, validate_yaml_suffix),
|
|
|
|
vol.Required(CONF_INPUT): {str: cv.match_all},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
extra=vol.ALLOW_EXTRA,
|
|
|
|
)
|