Add JSON files validation to hassfest (#29799)

This commit is contained in:
Franck Nijhof 2019-12-09 22:43:38 +01:00 committed by GitHub
parent 454cc684e4
commit 38a6fffecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 2 deletions

29
script/hassfest/json.py Normal file
View file

@ -0,0 +1,29 @@
"""Validate integration JSON files."""
import json
from typing import Dict
from .model import Integration
def validate_json_files(integration: Integration):
"""Validate JSON files for integration."""
for json_file in integration.path.glob("**/*.json"):
if not json_file.is_file():
continue
try:
json.loads(json_file.read_text())
except json.JSONDecodeError:
relative_path = json_file.relative_to(integration.path)
integration.add_error("json", f"Invalid JSON file {relative_path}")
return
def validate(integrations: Dict[str, Integration], config):
"""Handle JSON files inside integrations."""
for integration in integrations.values():
if not integration.manifest:
continue
validate_json_files(integration)