mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add setup type hints [s] (part 2) (#63479)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
d61a96f0ab
commit
992f9c3c6c
@ -1,9 +1,14 @@
|
||||
"""Support for monitoring a Smappee appliance binary sensor."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
@ -11,11 +16,15 @@ BINARY_SENSOR_PREFIX = "Appliance"
|
||||
PRESENCE_PREFIX = "Presence"
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Smappee binary sensor."""
|
||||
smappee_base = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities = []
|
||||
entities: list[BinarySensorEntity] = []
|
||||
for service_location in smappee_base.smappee.service_locations.values():
|
||||
for appliance_id, appliance in service_location.appliances.items():
|
||||
if appliance.type != "Find me" and appliance.source_type == "NILM":
|
||||
|
@ -8,7 +8,10 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import ATTR_ERRORS, ATTR_REMINDERS, DOMAIN, SMARTTUB_CONTROLLER
|
||||
from .entity import SmartTubEntity, SmartTubSensorBase
|
||||
@ -37,12 +40,14 @@ SNOOZE_REMINDER_SCHEMA = {
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up binary sensor entities for the binary sensors in the tub."""
|
||||
|
||||
controller = hass.data[DOMAIN][entry.entry_id][SMARTTUB_CONTROLLER]
|
||||
|
||||
entities = []
|
||||
entities: list[BinarySensorEntity] = []
|
||||
for spa in controller.spas:
|
||||
entities.append(SmartTubOnline(controller.coordinator, spa))
|
||||
entities.append(SmartTubError(controller.coordinator, spa))
|
||||
@ -53,7 +58,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
platform = entity_platform.current_platform.get()
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
"snooze_reminder",
|
||||
|
@ -5,7 +5,10 @@ import smarttub
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, SMARTTUB_CONTROLLER
|
||||
from .entity import SmartTubSensorBase
|
||||
@ -37,7 +40,9 @@ SET_SECONDARY_FILTRATION_SCHEMA = {
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up sensor entities for the sensors in the tub."""
|
||||
|
||||
controller = hass.data[DOMAIN][entry.entry_id][SMARTTUB_CONTROLLER]
|
||||
@ -65,7 +70,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
platform = entity_platform.current_platform.get()
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
"set_primary_filtration",
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Support for interacting with Snapcast clients."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import socket
|
||||
|
||||
@ -21,7 +23,10 @@ from homeassistant.const import (
|
||||
STATE_PLAYING,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import (
|
||||
ATTR_LATENCY,
|
||||
@ -52,7 +57,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Snapcast platform."""
|
||||
|
||||
host = config.get(CONF_HOST)
|
||||
@ -82,9 +92,10 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
# Note: Host part is needed, when using multiple snapservers
|
||||
hpid = f"{host}:{port}"
|
||||
|
||||
groups = [SnapcastGroupDevice(group, hpid) for group in server.groups]
|
||||
clients = [SnapcastClientDevice(client, hpid) for client in server.clients]
|
||||
devices = groups + clients
|
||||
devices: list[MediaPlayerEntity] = [
|
||||
SnapcastGroupDevice(group, hpid) for group in server.groups
|
||||
]
|
||||
devices.extend(SnapcastClientDevice(client, hpid) for client in server.clients)
|
||||
hass.data[DATA_KEY] = devices
|
||||
async_add_entities(devices)
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Support for displaying collected data over SNMP."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
@ -25,7 +27,10 @@ from homeassistant.const import (
|
||||
CONF_VALUE_TEMPLATE,
|
||||
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 .const import (
|
||||
CONF_ACCEPT_ERRORS,
|
||||
@ -78,7 +83,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the SNMP sensor."""
|
||||
name = config.get(CONF_NAME)
|
||||
host = config.get(CONF_HOST)
|
||||
@ -86,12 +96,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
community = config.get(CONF_COMMUNITY)
|
||||
baseoid = config.get(CONF_BASEOID)
|
||||
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
|
||||
version = config.get(CONF_VERSION)
|
||||
version = config[CONF_VERSION]
|
||||
username = config.get(CONF_USERNAME)
|
||||
authkey = config.get(CONF_AUTH_KEY)
|
||||
authproto = config.get(CONF_AUTH_PROTOCOL)
|
||||
authproto = config[CONF_AUTH_PROTOCOL]
|
||||
privkey = config.get(CONF_PRIV_KEY)
|
||||
privproto = config.get(CONF_PRIV_PROTOCOL)
|
||||
privproto = config[CONF_PRIV_PROTOCOL]
|
||||
accept_errors = config.get(CONF_ACCEPT_ERRORS)
|
||||
default_value = config.get(CONF_DEFAULT_VALUE)
|
||||
value_template = config.get(CONF_VALUE_TEMPLATE)
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Support for watching multiple cryptocurrencies."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from pysochain import ChainSo
|
||||
@ -6,8 +8,11 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_ADDRESS, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
ATTRIBUTION = "Data provided by chain.so"
|
||||
|
||||
@ -26,12 +31,17 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the sochain sensors."""
|
||||
|
||||
address = config.get(CONF_ADDRESS)
|
||||
network = config.get(CONF_NETWORK)
|
||||
name = config.get(CONF_NAME)
|
||||
address = config[CONF_ADDRESS]
|
||||
network = config[CONF_NETWORK]
|
||||
name = config[CONF_NAME]
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
chainso = ChainSo(network, address, hass.loop, session)
|
||||
|
@ -19,7 +19,9 @@ from homeassistant.const import (
|
||||
CONF_URL,
|
||||
)
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
ATTR_ADDRESS = "address"
|
||||
@ -232,7 +234,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Register the SpaceAPI with the HTTP interface."""
|
||||
hass.data[DATA_SPACEAPI] = config[DOMAIN]
|
||||
hass.http.register_view(APISpaceApiView)
|
||||
|
@ -1,19 +1,26 @@
|
||||
"""Support for Spider Powerplugs (energy & power)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Initialize a Spider Power Plug."""
|
||||
api = hass.data[DOMAIN][config.entry_id]
|
||||
entities = []
|
||||
entities: list[SensorEntity] = []
|
||||
|
||||
for entity in await hass.async_add_executor_job(api.get_power_plugs):
|
||||
entities.append(SpiderPowerPlugEnergy(api, entity))
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Sensor from an SQL Query."""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import logging
|
||||
@ -11,7 +13,10 @@ import voluptuous as vol
|
||||
from homeassistant.components.recorder import CONF_DB_URL, DEFAULT_DB_FILE, DEFAULT_URL
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import CONF_NAME, CONF_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE
|
||||
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
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -49,7 +54,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
def setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the SQL sensor platform."""
|
||||
if not (db_url := config.get(CONF_DB_URL)):
|
||||
db_url = DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE))
|
||||
@ -76,7 +86,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
queries = []
|
||||
|
||||
for query in config.get(CONF_QUERIES):
|
||||
for query in config[CONF_QUERIES]:
|
||||
name = query.get(CONF_NAME)
|
||||
query_str = query.get(CONF_QUERY)
|
||||
unit = query.get(CONF_UNIT_OF_MEASUREMENT)
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Sensor for Steam account status."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from time import mktime
|
||||
@ -8,9 +10,11 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import track_time_interval
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.dt import utc_from_timestamp
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -45,14 +49,19 @@ APP_LIST_KEY = "steam_online.app_list"
|
||||
BASE_INTERVAL = timedelta(minutes=1)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
def setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Steam platform."""
|
||||
|
||||
steam.api.key.set(config.get(CONF_API_KEY))
|
||||
steam.api.key.set(config[CONF_API_KEY])
|
||||
# Initialize steammods app list before creating sensors
|
||||
# to benefit from internal caching of the list.
|
||||
hass.data[APP_LIST_KEY] = steam.apps.app_list()
|
||||
entities = [SteamSensor(account, steam) for account in config.get(CONF_ACCOUNTS)]
|
||||
entities = [SteamSensor(account, steam) for account in config[CONF_ACCOUNTS]]
|
||||
if not entities:
|
||||
return
|
||||
add_entities(entities, True)
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Support for hydrological data from the Fed. Office for the Environment."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
@ -7,7 +9,10 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
|
||||
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 Throttle
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -52,10 +57,15 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
def setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Swiss hydrological sensor."""
|
||||
station = config.get(CONF_STATION)
|
||||
monitored_conditions = config.get(CONF_MONITORED_CONDITIONS)
|
||||
station = config[CONF_STATION]
|
||||
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
||||
|
||||
hydro_data = HydrologicalData(station)
|
||||
hydro_data.update()
|
||||
|
@ -4,8 +4,11 @@ from __future__ import annotations
|
||||
from pysyncthru import SyncThru, SyncthruState
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
@ -36,7 +39,11 @@ SYNCTHRU_STATE_HUMAN = {
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up from config entry."""
|
||||
|
||||
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
@ -48,7 +55,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
supp_output_tray = printer.output_tray_status()
|
||||
|
||||
name = config_entry.data[CONF_NAME]
|
||||
entities = [SyncThruMainSensor(coordinator, name)]
|
||||
entities: list[SyncThruSensor] = [SyncThruMainSensor(coordinator, name)]
|
||||
|
||||
for key in supp_toner:
|
||||
entities.append(SyncThruTonerSensor(coordinator, name, key))
|
||||
@ -56,8 +63,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
entities.append(SyncThruDrumSensor(coordinator, name, key))
|
||||
for key in supp_tray:
|
||||
entities.append(SyncThruInputTraySensor(coordinator, name, key))
|
||||
for key in supp_output_tray:
|
||||
entities.append(SyncThruOutputTraySensor(coordinator, name, key))
|
||||
for int_key in supp_output_tray:
|
||||
entities.append(SyncThruOutputTraySensor(coordinator, name, int_key))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user