Adjust pylint plugin to enforce platform type hints (#64836)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/64854/head
parent
d15d081646
commit
78e92d1662
pylint/plugins
|
@ -105,7 +105,7 @@ SENSOR_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
):
|
||||
) -> None:
|
||||
"""Set up the Aussie Broadband sensor platform from a config entry."""
|
||||
|
||||
async_add_entities(
|
||||
|
@ -116,7 +116,6 @@ async def async_setup_entry(
|
|||
if description.key in service["coordinator"].data
|
||||
]
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
class AussieBroadandSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
|
|
|
@ -9,7 +9,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
@ -25,7 +25,7 @@ def setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities_callback: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the demo remotes."""
|
||||
add_entities_callback(
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Demo platform that has a couple of fake sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
|
@ -20,7 +18,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, StateType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
@ -29,7 +27,7 @@ async def async_setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Demo sensors."""
|
||||
async_add_entities(
|
||||
|
|
|
@ -10,7 +10,7 @@ from homeassistant.components.sensor import SensorEntity
|
|||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import (
|
||||
CONF_SENSORS,
|
||||
|
@ -56,7 +56,7 @@ async def async_setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, list[tuple[str, str]]] = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the eight sleep sensors."""
|
||||
if discovery_info is None:
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""This platform allows several binary sensor to be grouped into one binary sensor."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
|
@ -24,7 +22,7 @@ from homeassistant.core import Event, HomeAssistant, callback
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import GroupEntity
|
||||
|
||||
|
@ -48,7 +46,7 @@ async def async_setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Group Binary Sensor platform."""
|
||||
async_add_entities(
|
||||
|
|
|
@ -46,7 +46,7 @@ from homeassistant.core import Event, HomeAssistant, State, callback
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import GroupEntity
|
||||
from .util import attribute_equal, reduce_attribute
|
||||
|
@ -71,7 +71,7 @@ async def async_setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Group Cover platform."""
|
||||
async_add_entities(
|
||||
|
|
|
@ -38,7 +38,7 @@ from homeassistant.core import Event, HomeAssistant, State, callback
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import GroupEntity
|
||||
from .util import (
|
||||
|
@ -68,7 +68,7 @@ async def async_setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Group Cover platform."""
|
||||
async_add_entities(
|
||||
|
|
|
@ -51,7 +51,7 @@ from homeassistant.core import Event, HomeAssistant, State, callback
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import GroupEntity
|
||||
from .util import find_state_attributes, mean_tuple, reduce_attribute
|
||||
|
@ -77,7 +77,7 @@ async def async_setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Initialize light.group platform."""
|
||||
async_add_entities(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for GTFS (Google/General Transport Format Schema)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
|
@ -20,6 +19,7 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, CONF_OFFSET, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import slugify
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -480,7 +480,7 @@ def get_next_departure(
|
|||
def setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: Callable[[list], None],
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the GTFS sensor."""
|
||||
|
|
|
@ -25,7 +25,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.location import find_coordinates
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import dt
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -143,7 +143,7 @@ PLATFORM_SCHEMA = vol.All(
|
|||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, str | bool],
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
"""Support for MQTT lights."""
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import light
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.reload import async_setup_reload_service
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .. import DOMAIN, PLATFORMS
|
||||
from ..mixins import async_setup_entry_helper
|
||||
|
@ -60,8 +63,11 @@ PLATFORM_SCHEMA = vol.All(
|
|||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up MQTT light through configuration.yaml."""
|
||||
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
|
||||
await _async_setup_entity(hass, async_add_entities, config)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Provides a binary sensor which gets its values from a TCP socket."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Final
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
|
@ -9,7 +9,7 @@ from homeassistant.components.binary_sensor import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .common import TCP_PLATFORM_SCHEMA, TcpEntity
|
||||
from .const import CONF_VALUE_ON
|
||||
|
@ -21,7 +21,7 @@ def setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the TCP binary sensor."""
|
||||
add_entities([TcpBinarySensor(hass, config)])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Support for TCP socket based sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Final
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
|
@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.const import CONF_UNIT_OF_MEASUREMENT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, StateType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||
|
||||
from .common import TCP_PLATFORM_SCHEMA, TcpEntity
|
||||
|
||||
|
@ -21,7 +21,7 @@ def setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the TCP Sensor."""
|
||||
add_entities([TcpSensor(hass, config)])
|
||||
|
|
|
@ -8,11 +8,12 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.button import DEVICE_CLASSES_SCHEMA, ButtonEntity
|
||||
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME, CONF_UNIQUE_ID
|
||||
from homeassistant.core import Config, HomeAssistant
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.script import Script
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .template_entity import (
|
||||
|
@ -57,9 +58,9 @@ async def _async_create_entities(
|
|||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: Config,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the template button."""
|
||||
if "coordinator" in discovery_info:
|
||||
|
|
|
@ -17,10 +17,11 @@ from homeassistant.components.number.const import (
|
|||
DOMAIN as NUMBER_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, CONF_OPTIMISTIC, CONF_STATE, CONF_UNIQUE_ID
|
||||
from homeassistant.core import Config, HomeAssistant
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.script import Script
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import TriggerUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
@ -71,9 +72,9 @@ async def _async_create_entities(
|
|||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: Config,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the template number."""
|
||||
if discovery_info is None:
|
||||
|
|
|
@ -13,10 +13,11 @@ from homeassistant.components.select.const import (
|
|||
DOMAIN as SELECT_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, CONF_OPTIMISTIC, CONF_STATE, CONF_UNIQUE_ID
|
||||
from homeassistant.core import Config, HomeAssistant
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.script import Script
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import TriggerUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
@ -65,9 +66,9 @@ async def _async_create_entities(
|
|||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: Config,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the template select."""
|
||||
if discovery_info is None:
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
"""Entity to track connections to websocket API."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import (
|
||||
DATA_CONNECTIONS,
|
||||
|
@ -19,7 +17,7 @@ async def async_setup_platform(
|
|||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the API streams platform."""
|
||||
entity = APICount()
|
||||
|
|
|
@ -9,6 +9,8 @@ from pylint.checkers import BaseChecker
|
|||
from pylint.interfaces import IAstroidChecker
|
||||
from pylint.lint import PyLinter
|
||||
|
||||
from homeassistant.const import Platform
|
||||
|
||||
|
||||
@dataclass
|
||||
class TypeHintMatch:
|
||||
|
@ -22,7 +24,10 @@ class TypeHintMatch:
|
|||
|
||||
_MODULE_FILTERS: dict[str, re.Pattern] = {
|
||||
# init matches only in the package root (__init__.py)
|
||||
"init": re.compile(r"^homeassistant.components.\w+$"),
|
||||
"init": re.compile(r"^homeassistant\.components\.\w+$"),
|
||||
"any_platform": re.compile(
|
||||
f"^homeassistant\\.components\\.\\w+\\.({'|'.join([platform.value for platform in Platform])})$"
|
||||
),
|
||||
}
|
||||
|
||||
_METHOD_MATCH: list[TypeHintMatch] = [
|
||||
|
@ -80,6 +85,38 @@ _METHOD_MATCH: list[TypeHintMatch] = [
|
|||
},
|
||||
return_type="bool",
|
||||
),
|
||||
TypeHintMatch(
|
||||
module_filter=_MODULE_FILTERS["any_platform"],
|
||||
function_name="setup_platform",
|
||||
arg_types={
|
||||
0: "HomeAssistant",
|
||||
1: "ConfigType",
|
||||
2: "AddEntitiesCallback",
|
||||
3: "DiscoveryInfoType | None",
|
||||
},
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
module_filter=_MODULE_FILTERS["any_platform"],
|
||||
function_name="async_setup_platform",
|
||||
arg_types={
|
||||
0: "HomeAssistant",
|
||||
1: "ConfigType",
|
||||
2: "AddEntitiesCallback",
|
||||
3: "DiscoveryInfoType | None",
|
||||
},
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
module_filter=_MODULE_FILTERS["any_platform"],
|
||||
function_name="async_setup_entry",
|
||||
arg_types={
|
||||
0: "HomeAssistant",
|
||||
1: "ConfigEntry",
|
||||
2: "AddEntitiesCallback",
|
||||
},
|
||||
return_type=None,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
@ -89,6 +126,14 @@ def _is_valid_type(expected_type: str | None, node: astroid.NodeNG) -> bool:
|
|||
if expected_type is None:
|
||||
return isinstance(node, astroid.Const) and node.value is None
|
||||
|
||||
# Special case for DiscoveryInfoType | None"
|
||||
if expected_type == "DiscoveryInfoType | None":
|
||||
return (
|
||||
isinstance(node, astroid.BinOp)
|
||||
and _is_valid_type("DiscoveryInfoType", node.left)
|
||||
and _is_valid_type(None, node.right)
|
||||
)
|
||||
|
||||
# Name occurs when a namespace is not used, eg. "HomeAssistant"
|
||||
if isinstance(node, astroid.Name) and node.name == expected_type:
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue