Use AddEntitiesCallback type, pt.4 (#49955)

This commit is contained in:
Ruslan Sayfutdinov 2021-05-04 13:50:06 +01:00 committed by GitHub
parent a0feee083c
commit 786c5db5be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 37 additions and 48 deletions

View file

@ -3,7 +3,6 @@ from __future__ import annotations
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
from typing import Callable
import herepy import herepy
import voluptuous as vol import voluptuous as vol
@ -26,6 +25,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, State, callback from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers import location from homeassistant.helpers import location
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import DiscoveryInfoType from homeassistant.helpers.typing import DiscoveryInfoType
import homeassistant.util.dt as dt import homeassistant.util.dt as dt
@ -145,7 +145,7 @@ PLATFORM_SCHEMA = vol.All(
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: dict[str, str | bool], config: dict[str, str | bool],
async_add_entities: Callable, async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up the HERE travel time platform.""" """Set up the HERE travel time platform."""

View file

@ -1,14 +1,13 @@
"""Support for KNX/IP binary sensors.""" """Support for KNX/IP binary sensors."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable from typing import Any
from typing import Any, Callable
from xknx.devices import BinarySensor as XknxBinarySensor from xknx.devices import BinarySensor as XknxBinarySensor
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import dt from homeassistant.util import dt
@ -19,7 +18,7 @@ from .knx_entity import KnxEntity
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up binary sensor(s) for KNX platform.""" """Set up binary sensor(s) for KNX platform."""

View file

@ -1,8 +1,7 @@
"""Support for KNX/IP climate devices.""" """Support for KNX/IP climate devices."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable from typing import Any
from typing import Any, Callable
from xknx.devices import Climate as XknxClimate from xknx.devices import Climate as XknxClimate
from xknx.dpt.dpt_hvac_mode import HVACControllerMode, HVACOperationMode from xknx.dpt.dpt_hvac_mode import HVACControllerMode, HVACOperationMode
@ -19,7 +18,7 @@ from homeassistant.components.climate.const import (
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import CONTROLLER_MODES, DOMAIN, PRESET_MODES from .const import CONTROLLER_MODES, DOMAIN, PRESET_MODES
@ -33,7 +32,7 @@ PRESET_MODES_INV = {value: key for key, value in PRESET_MODES.items()}
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up climate(s) for KNX platform.""" """Set up climate(s) for KNX platform."""

View file

@ -1,7 +1,6 @@
"""Support for KNX/IP covers.""" """Support for KNX/IP covers."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable
from datetime import datetime from datetime import datetime
from typing import Any, Callable from typing import Any, Callable
@ -25,7 +24,7 @@ from homeassistant.components.cover import (
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_utc_time_change from homeassistant.helpers.event import async_track_utc_time_change
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -37,7 +36,7 @@ from .schema import CoverSchema
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up cover(s) for KNX platform.""" """Set up cover(s) for KNX platform."""

View file

@ -1,15 +1,14 @@
"""Support for KNX/IP fans.""" """Support for KNX/IP fans."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable
import math import math
from typing import Any, Callable from typing import Any
from xknx.devices import Fan as XknxFan from xknx.devices import Fan as XknxFan
from homeassistant.components.fan import SUPPORT_OSCILLATE, SUPPORT_SET_SPEED, FanEntity from homeassistant.components.fan import SUPPORT_OSCILLATE, SUPPORT_SET_SPEED, FanEntity
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util.percentage import ( from homeassistant.util.percentage import (
int_states_in_range, int_states_in_range,
@ -26,7 +25,7 @@ DEFAULT_PERCENTAGE = 50
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up fans for KNX platform.""" """Set up fans for KNX platform."""

View file

@ -1,8 +1,7 @@
"""Support for KNX/IP lights.""" """Support for KNX/IP lights."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable from typing import Any, cast
from typing import Any, Callable, cast
from xknx.devices import Light as XknxLight from xknx.devices import Light as XknxLight
from xknx.telegram.address import parse_device_group_address from xknx.telegram.address import parse_device_group_address
@ -21,7 +20,7 @@ from homeassistant.components.light import (
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.color as color_util import homeassistant.util.color as color_util
@ -33,7 +32,7 @@ from .schema import LightSchema
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up lights for KNX platform.""" """Set up lights for KNX platform."""

View file

@ -1,14 +1,13 @@
"""Support for KNX scenes.""" """Support for KNX scenes."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable from typing import Any
from typing import Any, Callable
from xknx.devices import Scene as XknxScene from xknx.devices import Scene as XknxScene
from homeassistant.components.scene import Scene from homeassistant.components.scene import Scene
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DOMAIN from .const import DOMAIN
@ -18,7 +17,7 @@ from .knx_entity import KnxEntity
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up the scenes for KNX platform.""" """Set up the scenes for KNX platform."""

View file

@ -1,14 +1,13 @@
"""Support for KNX/IP sensors.""" """Support for KNX/IP sensors."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable from typing import Any
from typing import Any, Callable
from xknx.devices import Sensor as XknxSensor from xknx.devices import Sensor as XknxSensor
from homeassistant.components.sensor import DEVICE_CLASSES, SensorEntity from homeassistant.components.sensor import DEVICE_CLASSES, SensorEntity
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
from homeassistant.util import dt from homeassistant.util import dt
@ -19,7 +18,7 @@ from .knx_entity import KnxEntity
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up sensor(s) for KNX platform.""" """Set up sensor(s) for KNX platform."""

View file

@ -1,8 +1,7 @@
"""Support for KNX/IP switches.""" """Support for KNX/IP switches."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable from typing import Any
from typing import Any, Callable
from xknx import XKNX from xknx import XKNX
from xknx.devices import Switch as XknxSwitch from xknx.devices import Switch as XknxSwitch
@ -10,7 +9,7 @@ from xknx.devices import Switch as XknxSwitch
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DOMAIN, KNX_ADDRESS from .const import DOMAIN, KNX_ADDRESS
@ -21,7 +20,7 @@ from .schema import SwitchSchema
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up switch(es) for KNX platform.""" """Set up switch(es) for KNX platform."""

View file

@ -1,15 +1,12 @@
"""Support for KNX/IP weather station.""" """Support for KNX/IP weather station."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable
from typing import Callable
from xknx.devices import Weather as XknxWeather from xknx.devices import Weather as XknxWeather
from homeassistant.components.weather import WeatherEntity from homeassistant.components.weather import WeatherEntity
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DOMAIN from .const import DOMAIN
@ -19,7 +16,7 @@ from .knx_entity import KnxEntity
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Iterable[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up weather entities for KNX platform.""" """Set up weather entities for KNX platform."""

View file

@ -21,6 +21,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
@ -98,7 +99,7 @@ PLATFORM_SCHEMA = vol.All(
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigEntry, config: ConfigEntry,
async_add_entities: Callable[[], Coroutine], async_add_entities: AddEntitiesCallback,
discovery_info=None, discovery_info=None,
) -> None: ) -> None:
"""Import the platform into a config entry.""" """Import the platform into a config entry."""

View file

@ -1,8 +1,7 @@
"""Light support for switch entities.""" """Light support for switch entities."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Sequence from typing import Any, cast
from typing import Any, Callable, cast
import voluptuous as vol import voluptuous as vol
@ -17,7 +16,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant, State, callback from homeassistant.core import HomeAssistant, State, callback
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -36,7 +35,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable[[Sequence[Entity]], None], async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Initialize Light Switch platform.""" """Initialize Light Switch platform."""

View file

@ -1,8 +1,6 @@
"""Home Assistant Switcher Component Switch platform.""" """Home Assistant Switcher Component Switch platform."""
from __future__ import annotations from __future__ import annotations
from typing import Callable
from aioswitcher.api import SwitcherV2Api from aioswitcher.api import SwitcherV2Api
from aioswitcher.api.messages import SwitcherV2ControlResponseMSG from aioswitcher.api.messages import SwitcherV2ControlResponseMSG
from aioswitcher.consts import ( from aioswitcher.consts import (
@ -19,6 +17,7 @@ from homeassistant.components.switch import ATTR_CURRENT_POWER_W, SwitchEntity
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ( from . import (
ATTR_AUTO_OFF_SET, ATTR_AUTO_OFF_SET,
@ -55,7 +54,7 @@ SERVICE_TURN_ON_WITH_TIMER_SCHEMA = {
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: dict, config: dict,
async_add_entities: Callable, async_add_entities: AddEntitiesCallback,
discovery_info: dict, discovery_info: dict,
) -> None: ) -> None:
"""Set up the switcher platform for the switch component.""" """Set up the switcher platform for the switch component."""

View file

@ -9,7 +9,7 @@ import logging
import os import os
import socket import socket
import sys import sys
from typing import Any, Callable, cast from typing import Any, cast
import psutil import psutil
import voluptuous as vol import voluptuous as vol
@ -36,6 +36,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity_component import DEFAULT_SCAN_INTERVAL from homeassistant.helpers.entity_component import DEFAULT_SCAN_INTERVAL
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from homeassistant.util import slugify from homeassistant.util import slugify
@ -198,7 +199,7 @@ class SensorData:
async def async_setup_platform( async def async_setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
async_add_entities: Callable, async_add_entities: AddEntitiesCallback,
discovery_info: Any | None = None, discovery_info: Any | None = None,
) -> None: ) -> None:
"""Set up the system monitor sensors.""" """Set up the system monitor sensors."""