hass-core/script/hassfest/manifest.py
Paulus Schoutsen e8343452cd
Validate component usage (#23037)
* Update manifest validator

* Update circle

* Update text

* Typo

* fix link to codeowners

* Merge CODEOWNERS into hassfest

* Annotate errors with fixable

* Convert error to warning

* Lint

* Make abs path

* Python 3.5...

* Typo

* Fix tests
2019-04-13 13:17:01 -07:00

40 lines
1.1 KiB
Python

"""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,
vol.Required('documentation'): str,
vol.Required('requirements'): [str],
vol.Required('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(
'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)