2019-04-13 20:17:01 +00:00
|
|
|
"""Manifest validation."""
|
|
|
|
from typing import Dict
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
from voluptuous.humanize import humanize_error
|
|
|
|
|
|
|
|
from .model import Integration
|
|
|
|
|
|
|
|
|
|
|
|
MANIFEST_SCHEMA = vol.Schema({
|
|
|
|
vol.Required('domain'): str,
|
|
|
|
vol.Required('name'): str,
|
2019-05-13 08:16:55 +00:00
|
|
|
vol.Optional('config_flow'): bool,
|
2019-05-21 22:36:26 +00:00
|
|
|
vol.Optional('zeroconf'): [str],
|
2019-05-27 02:48:27 +00:00
|
|
|
vol.Optional('ssdp'): vol.Schema({
|
|
|
|
vol.Optional('st'): [str],
|
|
|
|
vol.Optional('manufacturer'): [str],
|
|
|
|
vol.Optional('device_type'): [str],
|
|
|
|
}),
|
2019-05-31 18:58:48 +00:00
|
|
|
vol.Optional('homekit'): vol.Schema({
|
|
|
|
vol.Optional('models'): [str],
|
|
|
|
}),
|
2019-04-13 20:17:01 +00:00
|
|
|
vol.Required('documentation'): str,
|
|
|
|
vol.Required('requirements'): [str],
|
|
|
|
vol.Required('dependencies'): [str],
|
2019-04-16 20:40:21 +00:00
|
|
|
vol.Optional('after_dependencies'): [str],
|
2019-04-13 20:17:01 +00:00
|
|
|
vol.Required('codeowners'): [str],
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
def validate_manifest(integration: Integration):
|
|
|
|
"""Validate manifest."""
|
|
|
|
try:
|
|
|
|
MANIFEST_SCHEMA(integration.manifest)
|
|
|
|
except vol.Invalid as err:
|
|
|
|
integration.add_error(
|
|
|
|
'manifest',
|
|
|
|
"Invalid manifest: {}".format(
|
|
|
|
humanize_error(integration.manifest, err)))
|
|
|
|
integration.manifest = None
|
|
|
|
return
|
|
|
|
|
|
|
|
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)
|