mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add quality scale hassfest check for config-entry-unload (#131720)
* Add dataclass to hassfest quality_scale * Add basic check for config-entry-unloading * Future-proof with a list of errors
This commit is contained in:
15
script/hassfest/quality_scale_validation/__init__.py
Normal file
15
script/hassfest/quality_scale_validation/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""Integration quality scale rules."""
|
||||
|
||||
from typing import Protocol
|
||||
|
||||
from script.hassfest.model import Integration
|
||||
|
||||
|
||||
class RuleValidationProtocol(Protocol):
|
||||
"""Protocol for rule validation."""
|
||||
|
||||
def validate(self, integration: Integration) -> list[str] | None:
|
||||
"""Validate a quality scale rule.
|
||||
|
||||
Returns error (if any).
|
||||
"""
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Enforce that the integration implements entry unloading."""
|
||||
|
||||
import ast
|
||||
|
||||
from script.hassfest.model import Integration
|
||||
|
||||
|
||||
def _has_async_function(module: ast.Module, name: str) -> bool:
|
||||
"""Test if the module defines a function."""
|
||||
return any(
|
||||
type(item) is ast.AsyncFunctionDef and item.name == name for item in module.body
|
||||
)
|
||||
|
||||
|
||||
def validate(integration: Integration) -> list[str] | None:
|
||||
"""Validate that the integration has a config flow."""
|
||||
|
||||
init_file = integration.path / "__init__.py"
|
||||
init = ast.parse(init_file.read_text())
|
||||
|
||||
if not _has_async_function(init, "async_unload_entry"):
|
||||
return [
|
||||
"Integration does not support config entry unloading "
|
||||
"(is missing `async_unload_entry` in __init__.py)"
|
||||
]
|
||||
return None
|
||||
Reference in New Issue
Block a user