forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.py
41 lines (32 loc) · 1.18 KB
/
manifest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""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.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(
'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)