mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 03:35:09 +02:00
Add parallel-updates rule to quality_scale validation (#132041)
This commit is contained in:
@@ -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
|
||||
),
|
||||
|
35
script/hassfest/quality_scale_validation/parallel_updates.py
Normal file
35
script/hassfest/quality_scale_validation/parallel_updates.py
Normal 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
|
Reference in New Issue
Block a user