Add parallel-updates rule to quality_scale validation (#132041)

This commit is contained in:
epenet
2024-12-06 22:40:29 +01:00
committed by GitHub
parent 5bae000db5
commit 12be82fdbc
20 changed files with 89 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ from .quality_scale_validation import (
config_flow,
diagnostics,
discovery,
parallel_updates,
reauthentication_flow,
reconfiguration_flow,
runtime_data,
@@ -67,7 +68,7 @@ ALL_RULES = [
Rule("entity-unavailable", ScaledQualityScaleTiers.SILVER),
Rule("integration-owner", ScaledQualityScaleTiers.SILVER),
Rule("log-when-unavailable", ScaledQualityScaleTiers.SILVER),
Rule("parallel-updates", ScaledQualityScaleTiers.SILVER),
Rule("parallel-updates", ScaledQualityScaleTiers.SILVER, parallel_updates),
Rule(
"reauthentication-flow", ScaledQualityScaleTiers.SILVER, reauthentication_flow
),

View File

@@ -0,0 +1,35 @@
"""Enforce that the integration sets PARALLEL_UPDATES constant.
https://developers.home-assistant.io/docs/core/integration-quality-scale/rules/parallel-updates
"""
import ast
from homeassistant.const import Platform
from script.hassfest.model import Integration
def _has_parallel_updates_defined(module: ast.Module) -> bool:
"""Test if the module defines `PARALLEL_UPDATES` constant."""
return any(
type(item) is ast.Assign and item.targets[0].id == "PARALLEL_UPDATES"
for item in module.body
)
def validate(integration: Integration) -> list[str] | None:
"""Validate that the integration sets PARALLEL_UPDATES constant."""
errors = []
for platform in Platform:
module_file = integration.path / f"{platform}.py"
if not module_file.exists():
continue
module = ast.parse(module_file.read_text())
if not _has_parallel_updates_defined(module):
errors.append(
f"Integration does not set `PARALLEL_UPDATES` in {module_file}"
)
return errors