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

pull/132538/head
epenet 2024-12-06 22:40:29 +01:00 committed by GitHub
parent 5bae000db5
commit 12be82fdbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 89 additions and 3 deletions

View File

@ -16,6 +16,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .coordinator import AcaiaConfigEntry
from .entity import AcaiaEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(kw_only=True, frozen=True)
class AcaiaBinarySensorEntityDescription(BinarySensorEntityDescription):

View File

@ -21,6 +21,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .coordinator import AcaiaConfigEntry
from .entity import AcaiaEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(kw_only=True, frozen=True)
class AcaiaSensorEntityDescription(SensorEntityDescription):

View File

@ -33,7 +33,10 @@ rules:
entity-unavailable: done
integration-owner: done
log-when-unavailable: done
parallel-updates: done
parallel-updates:
status: todo
comment: |
Does not set parallel-updates on button/switch action calls.
reauthentication-flow:
status: exempt
comment: |

View File

@ -25,6 +25,9 @@ from . import ElgatorConfigEntry
from .coordinator import ElgatoData, ElgatoDataUpdateCoordinator
from .entity import ElgatoEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(frozen=True, kw_only=True)
class ElgatoSensorEntityDescription(SensorEntityDescription):

View File

@ -30,6 +30,8 @@ from .coordinator import AutomowerDataUpdateCoordinator
from .entity import AutomowerBaseEntity
_LOGGER = logging.getLogger(__name__)
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
def entity_used_in(hass: HomeAssistant, entity_id: str) -> list[str]:

View File

@ -15,6 +15,8 @@ from .coordinator import AutomowerDataUpdateCoordinator
from .entity import AutomowerBaseEntity
_LOGGER = logging.getLogger(__name__)
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
async def async_setup_entry(

View File

@ -8,6 +8,9 @@ from . import AutomowerConfigEntry
from .coordinator import AutomowerDataUpdateCoordinator
from .entity import AutomowerBaseEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
async def async_setup_entry(
hass: HomeAssistant,

View File

@ -35,6 +35,8 @@ from .entity import (
)
_LOGGER = logging.getLogger(__name__)
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
ATTR_WORK_AREA_ID_ASSIGNMENT = "work_area_id_assignment"

View File

@ -17,6 +17,9 @@ from . import ImapConfigEntry
from .const import DOMAIN
from .coordinator import ImapDataUpdateCoordinator
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
IMAP_MAIL_COUNT_DESCRIPTION = SensorEntityDescription(
key="imap_mail_count",
entity_category=EntityCategory.DIAGNOSTIC,

View File

@ -30,6 +30,9 @@ from . import IronOSConfigEntry
from .const import OHM
from .entity import IronOSBaseEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
class PinecilSensor(StrEnum):
"""Pinecil Sensors."""

View File

@ -40,6 +40,8 @@ from .coordinator import IstaCoordinator
from .util import IstaConsumptionType, IstaValueType, get_native_value, get_statistics
_LOGGER = logging.getLogger(__name__)
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(kw_only=True, frozen=True)

View File

@ -17,6 +17,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .coordinator import LaMarzoccoConfigEntry
from .entity import LaMarzoccoEntity, LaMarzoccoEntityDescription
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(frozen=True, kw_only=True)
class LaMarzoccoBinarySensorEntityDescription(

View File

@ -13,6 +13,9 @@ from homeassistant.util import dt as dt_util
from .coordinator import LaMarzoccoConfigEntry, LaMarzoccoUpdateCoordinator
from .entity import LaMarzoccoBaseEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
CALENDAR_KEY = "auto_on_off_schedule"
DAY_OF_WEEK = [

View File

@ -19,6 +19,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .coordinator import LaMarzoccoConfigEntry
from .entity import LaMarzoccoEntity, LaMarzoccoEntityDescription
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(frozen=True, kw_only=True)
class LaMarzoccoSensorEntityDescription(

View File

@ -39,7 +39,10 @@ rules:
entity-unavailable: done
integration-owner: done
log-when-unavailable: done
parallel-updates: done
parallel-updates:
status: todo
comment: |
Does not set parallel-updates on notify platform.
reauthentication-flow:
status: todo
comment: |

View File

@ -23,6 +23,9 @@ from .const import (
)
from .entity import MastodonEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(frozen=True, kw_only=True)
class MastodonSensorEntityDescription(SensorEntityDescription):

View File

@ -18,6 +18,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .coordinator import TedeeConfigEntry
from .entity import TedeeDescriptionEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(frozen=True, kw_only=True)
class TedeeBinarySensorEntityDescription(

View File

@ -18,6 +18,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .coordinator import TedeeConfigEntry
from .entity import TedeeDescriptionEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
@dataclass(frozen=True, kw_only=True)
class TedeeSensorEntityDescription(SensorEntityDescription):

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