mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add JSON files validation to hassfest (#29799)
This commit is contained in:
parent
454cc684e4
commit
38a6fffecb
@ -2,10 +2,28 @@
|
|||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from . import codeowners, config_flow, dependencies, manifest, services, ssdp, zeroconf
|
from . import (
|
||||||
|
codeowners,
|
||||||
|
config_flow,
|
||||||
|
dependencies,
|
||||||
|
json,
|
||||||
|
manifest,
|
||||||
|
services,
|
||||||
|
ssdp,
|
||||||
|
zeroconf,
|
||||||
|
)
|
||||||
from .model import Config, Integration
|
from .model import Config, Integration
|
||||||
|
|
||||||
PLUGINS = [codeowners, config_flow, dependencies, manifest, services, ssdp, zeroconf]
|
PLUGINS = [
|
||||||
|
json,
|
||||||
|
codeowners,
|
||||||
|
config_flow,
|
||||||
|
dependencies,
|
||||||
|
manifest,
|
||||||
|
services,
|
||||||
|
ssdp,
|
||||||
|
zeroconf,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_config() -> Config:
|
def get_config() -> Config:
|
||||||
|
29
script/hassfest/json.py
Normal file
29
script/hassfest/json.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user