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:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user