mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Improve platforms pylint plugin (#164067)
This commit is contained in:
committed by
GitHub
parent
2cfafc04ce
commit
cb990823cd
@@ -20,11 +20,11 @@ from .coordinator import NintendoParentalControlsConfigEntry, NintendoUpdateCoor
|
||||
from .services import async_setup_services
|
||||
|
||||
_PLATFORMS: list[Platform] = [
|
||||
Platform.SENSOR,
|
||||
Platform.TIME,
|
||||
Platform.SWITCH,
|
||||
Platform.NUMBER,
|
||||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.TIME,
|
||||
]
|
||||
|
||||
PLATFORM_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
@@ -29,9 +29,9 @@ from .services import async_setup_services
|
||||
|
||||
_PLATFORMS: list[Platform] = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.BUTTON,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.BUTTON,
|
||||
]
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
@@ -10,9 +10,9 @@ from .coordinator import DeviceNotFound, ToGrillConfigEntry, ToGrillCoordinator
|
||||
|
||||
_PLATFORMS: list[Platform] = [
|
||||
Platform.EVENT,
|
||||
Platform.NUMBER,
|
||||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
Platform.NUMBER,
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ from .coordinator import ZinvoltConfigEntry, ZinvoltDeviceCoordinator
|
||||
|
||||
_PLATFORMS: list[Platform] = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.SENSOR,
|
||||
Platform.NUMBER,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class HassEnforceSortedPlatformsChecker(BaseChecker):
|
||||
"""Check for sorted PLATFORMS const."""
|
||||
if (
|
||||
isinstance(target, nodes.AssignName)
|
||||
and target.name == "PLATFORMS"
|
||||
and target.name in {"PLATFORMS", "_PLATFORMS"}
|
||||
and isinstance(node.value, nodes.List)
|
||||
):
|
||||
platforms = [v.as_string() for v in node.value.elts]
|
||||
|
||||
@@ -40,6 +40,30 @@ from . import assert_adds_messages, assert_no_messages
|
||||
""",
|
||||
id="typed_multiple_platform",
|
||||
),
|
||||
pytest.param(
|
||||
"""
|
||||
_PLATFORMS = [Platform.SENSOR]
|
||||
""",
|
||||
id="private_one_platform",
|
||||
),
|
||||
pytest.param(
|
||||
"""
|
||||
_PLATFORMS = [Platform.BINARY_SENSOR, Platform.BUTTON, Platform.SENSOR]
|
||||
""",
|
||||
id="private_multiple_platforms",
|
||||
),
|
||||
pytest.param(
|
||||
"""
|
||||
_PLATFORMS: list[str] = [Platform.SENSOR]
|
||||
""",
|
||||
id="private_typed_one_platform",
|
||||
),
|
||||
pytest.param(
|
||||
"""
|
||||
_PLATFORMS: list[str] = [Platform.BINARY_SENSOR, Platform.BUTTON, Platform.SENSOR]
|
||||
""",
|
||||
id="private_typed_multiple_platforms",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_enforce_sorted_platforms(
|
||||
@@ -110,3 +134,59 @@ def test_enforce_sorted_platforms_bad_typed(
|
||||
),
|
||||
):
|
||||
enforce_sorted_platforms_checker.visit_annassign(assign_node)
|
||||
|
||||
|
||||
def test_enforce_sorted_private_platforms_bad(
|
||||
linter: UnittestLinter,
|
||||
enforce_sorted_platforms_checker: BaseChecker,
|
||||
) -> None:
|
||||
"""Bad test case for private _PLATFORMS."""
|
||||
assign_node = astroid.extract_node(
|
||||
"""
|
||||
_PLATFORMS = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.BUTTON]
|
||||
""",
|
||||
"homeassistant.components.pylint_test",
|
||||
)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
MessageTest(
|
||||
msg_id="hass-enforce-sorted-platforms",
|
||||
line=2,
|
||||
node=assign_node,
|
||||
args=None,
|
||||
confidence=UNDEFINED,
|
||||
col_offset=0,
|
||||
end_line=2,
|
||||
end_col_offset=71,
|
||||
),
|
||||
):
|
||||
enforce_sorted_platforms_checker.visit_assign(assign_node)
|
||||
|
||||
|
||||
def test_enforce_sorted_private_platforms_bad_typed(
|
||||
linter: UnittestLinter,
|
||||
enforce_sorted_platforms_checker: BaseChecker,
|
||||
) -> None:
|
||||
"""Bad typed test case for private _PLATFORMS."""
|
||||
assign_node = astroid.extract_node(
|
||||
"""
|
||||
_PLATFORMS: list[str] = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.BUTTON]
|
||||
""",
|
||||
"homeassistant.components.pylint_test",
|
||||
)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
MessageTest(
|
||||
msg_id="hass-enforce-sorted-platforms",
|
||||
line=2,
|
||||
node=assign_node,
|
||||
args=None,
|
||||
confidence=UNDEFINED,
|
||||
col_offset=0,
|
||||
end_line=2,
|
||||
end_col_offset=82,
|
||||
),
|
||||
):
|
||||
enforce_sorted_platforms_checker.visit_annassign(assign_node)
|
||||
|
||||
Reference in New Issue
Block a user