Add quality_scale.yaml to track IQS progress (#130953)

pull/131037/head
Joost Lekkerkerker 2024-11-20 13:49:02 +01:00 committed by GitHub
parent 5d804d3172
commit 2cd05e224a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,2 @@
rules:
IQS001: done

View File

@ -23,6 +23,7 @@ from . import (
metadata,
mqtt,
mypy_config,
quality_scale,
requirements,
services,
ssdp,
@ -43,6 +44,7 @@ INTEGRATION_PLUGINS = [
json,
manifest,
mqtt,
quality_scale,
requirements,
services,
ssdp,

View File

@ -0,0 +1,57 @@
"""Validate integration quality scale files."""
from __future__ import annotations
import voluptuous as vol
from voluptuous.humanize import humanize_error
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util.yaml import load_yaml_dict
from .model import Config, Integration
SCHEMA = vol.Schema(
{
vol.Required("rules"): vol.Schema(
{
str: vol.Any(
vol.In(["todo", "done"]),
vol.Schema(
{
vol.Required("status"): vol.In(["todo", "done", "exempt"]),
vol.Optional("comment"): str,
}
),
)
}
)
}
)
def validate_iqs_file(config: Config, integration: Integration) -> None:
"""Validate quality scale file for integration."""
iqs_file = integration.path / "quality_scale.yaml"
if not iqs_file.is_file():
return
name = str(iqs_file)
try:
data = load_yaml_dict(name)
except HomeAssistantError:
integration.add_error("quality_scale", "Invalid quality_scale.yaml")
return
try:
SCHEMA(data)
except vol.Invalid as err:
integration.add_error(
"quality_scale", f"Invalid {name}: {humanize_error(data, err)}"
)
def validate(integrations: dict[str, Integration], config: Config) -> None:
"""Handle YAML files inside integrations."""
for integration in integrations.values():
validate_iqs_file(config, integration)