Add base Entity class to enforce-class-module pylint plugin (#126026)

* Add base Entity class to enforcé-class-module pylint plugin

* Ignore bluetooth

* Ignore hue

* Ignore dominos

* Ignore ffmpeg

* Ignore mqtt

* Ignore microsoft_face

* Ignore plant

* Ignore point

* Ignore rfxtrx

* Ignore template

* Ignore tag

* Ignore deconz
This commit is contained in:
epenet
2024-09-18 20:38:45 +02:00
committed by GitHub
parent 5fcdcbf9b9
commit 6bc2d11c5e
16 changed files with 102 additions and 15 deletions

View File

@@ -8,6 +8,8 @@ from astroid import nodes
from pylint.checkers import BaseChecker
from pylint.lint import PyLinter
from homeassistant.const import Platform
_MODULES: dict[str, set[str]] = {
"air_quality": {"AirQualityEntity"},
"alarm_control_panel": {
@@ -63,6 +65,7 @@ _MODULES: dict[str, set[str]] = {
"WeatherEntityDescription",
},
}
_PLATFORMS: set[str] = {platform.value for platform in Platform}
class HassEnforceClassModule(BaseChecker):
@@ -89,6 +92,18 @@ class HassEnforceClassModule(BaseChecker):
current_integration = parts[2]
current_module = parts[3] if len(parts) > 3 else ""
if current_module != "entity" and current_integration not in _PLATFORMS:
top_level_ancestors = list(node.ancestors(recurs=False))
for ancestor in top_level_ancestors:
if ancestor.name == "Entity":
self.add_message(
"hass-enforce-class-module",
node=node,
args=(ancestor.name, "entity"),
)
return
ancestors: list[ClassDef] | None = None
for expected_module, classes in _MODULES.items():