core/script/hassfest/manifest.py

54 lines
1.6 KiB
Python
Raw Normal View History

"""Manifest validation."""
from typing import Dict
import voluptuous as vol
from voluptuous.humanize import humanize_error
from .model import Integration
2019-07-31 19:25:30 +00:00
MANIFEST_SCHEMA = vol.Schema(
{
vol.Required("domain"): str,
vol.Required("name"): str,
vol.Optional("config_flow"): bool,
vol.Optional("zeroconf"): [str],
vol.Optional("ssdp"): vol.Schema(
{
vol.Optional("st"): [str],
vol.Optional("manufacturer"): [str],
vol.Optional("device_type"): [str],
}
),
vol.Optional("homekit"): vol.Schema({vol.Optional("models"): [str]}),
vol.Required("documentation"): str,
vol.Required("requirements"): [str],
vol.Required("dependencies"): [str],
vol.Optional("after_dependencies"): [str],
vol.Required("codeowners"): [str],
}
)
def validate_manifest(integration: Integration):
"""Validate manifest."""
try:
MANIFEST_SCHEMA(integration.manifest)
except vol.Invalid as err:
integration.add_error(
2019-07-31 19:25:30 +00:00
"manifest",
"Invalid manifest: {}".format(humanize_error(integration.manifest, err)),
)
integration.manifest = None
return
2019-07-31 19:25:30 +00:00
if integration.manifest["domain"] != integration.path.name:
integration.add_error("manifest", "Domain does not match dir name")
def validate(integrations: Dict[str, Integration], config):
"""Handle all integrations manifests."""
for integration in integrations.values():
if integration.manifest:
validate_manifest(integration)