mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add setup type hints [m] (#63456)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
47812575d0
commit
5196b75ed6
@ -1,16 +1,26 @@
|
|||||||
"""Support for MAX! binary sensors via MAX! Cube."""
|
"""Support for MAX! binary sensors via MAX! Cube."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import DATA_KEY
|
from . import DATA_KEY
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
"""Iterate through all MAX! Devices and add window shutters."""
|
"""Iterate through all MAX! Devices and add window shutters."""
|
||||||
devices = []
|
devices: list[MaxCubeBinarySensorBase] = []
|
||||||
for handler in hass.data[DATA_KEY].values():
|
for handler in hass.data[DATA_KEY].values():
|
||||||
for device in handler.cube.devices:
|
for device in handler.cube.devices:
|
||||||
devices.append(MaxCubeBattery(handler, device))
|
devices.append(MaxCubeBattery(handler, device))
|
||||||
|
@ -1,22 +1,31 @@
|
|||||||
"""Platform for Mazda sensor integration."""
|
"""Platform for Mazda sensor integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
LENGTH_KILOMETERS,
|
LENGTH_KILOMETERS,
|
||||||
LENGTH_MILES,
|
LENGTH_MILES,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
PRESSURE_PSI,
|
PRESSURE_PSI,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import MazdaEntity
|
from . import MazdaEntity
|
||||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
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 sensor platform."""
|
"""Set up the sensor platform."""
|
||||||
client = hass.data[DOMAIN][config_entry.entry_id][DATA_CLIENT]
|
client = hass.data[DOMAIN][config_entry.entry_id][DATA_CLIENT]
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR]
|
||||||
|
|
||||||
entities = []
|
entities: list[SensorEntity] = []
|
||||||
|
|
||||||
for index, _ in enumerate(coordinator.data):
|
for index, _ in enumerate(coordinator.data):
|
||||||
entities.append(MazdaFuelRemainingSensor(client, coordinator, index))
|
entities.append(MazdaFuelRemainingSensor(client, coordinator, index))
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for switch sensor using I2C MCP23017 chip."""
|
"""Support for switch sensor using I2C MCP23017 chip."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from adafruit_mcp230xx.mcp23017 import MCP23017
|
from adafruit_mcp230xx.mcp23017 import MCP23017
|
||||||
@ -9,8 +11,11 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.switch import PLATFORM_SCHEMA
|
from homeassistant.components.switch import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
CONF_INVERT_LOGIC = "invert_logic"
|
CONF_INVERT_LOGIC = "invert_logic"
|
||||||
CONF_I2C_ADDRESS = "i2c_address"
|
CONF_I2C_ADDRESS = "i2c_address"
|
||||||
@ -33,7 +38,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
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 MCP23017 devices."""
|
"""Set up the MCP23017 devices."""
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"The MCP23017 I/O Expander integration is deprecated and will be removed "
|
"The MCP23017 I/O Expander integration is deprecated and will be removed "
|
||||||
@ -48,7 +58,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
mcp = MCP23017(i2c, address=i2c_address)
|
mcp = MCP23017(i2c, address=i2c_address)
|
||||||
|
|
||||||
switches = []
|
switches = []
|
||||||
pins = config.get(CONF_PINS)
|
pins = config[CONF_PINS]
|
||||||
for pin_num, pin_name in pins.items():
|
for pin_num, pin_name in pins.items():
|
||||||
pin = mcp.get_pin(pin_num)
|
pin = mcp.get_pin(pin_num)
|
||||||
switches.append(MCP23017Switch(pin_name, pin, invert_logic))
|
switches.append(MCP23017Switch(pin_name, pin, invert_logic))
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for Microsoft face recognition."""
|
"""Support for Microsoft face recognition."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@ -9,11 +11,12 @@ import async_timeout
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import ATTR_NAME, CONF_API_KEY, CONF_TIMEOUT, CONTENT_TYPE_JSON
|
from homeassistant.const import ATTR_NAME, CONF_API_KEY, CONF_TIMEOUT, CONTENT_TYPE_JSON
|
||||||
from homeassistant.core import ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -67,9 +70,9 @@ SCHEMA_FACE_SERVICE = vol.Schema(
|
|||||||
SCHEMA_TRAIN_SERVICE = vol.Schema({vol.Required(ATTR_GROUP): cv.slugify})
|
SCHEMA_TRAIN_SERVICE = vol.Schema({vol.Required(ATTR_GROUP): cv.slugify})
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up Microsoft Face."""
|
"""Set up Microsoft Face."""
|
||||||
entities = {}
|
entities: dict[str, MicrosoftFaceGroupEntity] = {}
|
||||||
face = MicrosoftFace(
|
face = MicrosoftFace(
|
||||||
hass,
|
hass,
|
||||||
config[DOMAIN].get(CONF_AZURE_REGION),
|
config[DOMAIN].get(CONF_AZURE_REGION),
|
||||||
|
@ -11,7 +11,9 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the mochad component."""
|
"""Set up the mochad component."""
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
host = conf.get(CONF_HOST)
|
host = conf.get(CONF_HOST)
|
||||||
@ -42,8 +44,8 @@ def setup(hass, config):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
mochad_controller = MochadCtrl(host, port)
|
mochad_controller = MochadCtrl(host, port)
|
||||||
except exceptions.ConfigurationError:
|
except exceptions.ConfigurationError as err:
|
||||||
_LOGGER.exception()
|
_LOGGER.exception(str(err))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def stop_mochad(event):
|
def stop_mochad(event):
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for X10 dimmer over Mochad."""
|
"""Support for X10 dimmer over Mochad."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pymochad import device
|
from pymochad import device
|
||||||
@ -12,7 +14,10 @@ from homeassistant.components.light import (
|
|||||||
LightEntity,
|
LightEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_ADDRESS, CONF_DEVICES, CONF_NAME, CONF_PLATFORM
|
from homeassistant.const import CONF_ADDRESS, CONF_DEVICES, CONF_NAME, CONF_PLATFORM
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import CONF_COMM_TYPE, DOMAIN, REQ_LOCK
|
from . import CONF_COMM_TYPE, DOMAIN, REQ_LOCK
|
||||||
|
|
||||||
@ -36,12 +41,16 @@ 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 X10 dimmers over a mochad controller."""
|
"""Set up X10 dimmers over a mochad controller."""
|
||||||
mochad_controller = hass.data[DOMAIN]
|
mochad_controller = hass.data[DOMAIN]
|
||||||
devs = config.get(CONF_DEVICES)
|
devs = config[CONF_DEVICES]
|
||||||
add_entities([MochadLight(hass, mochad_controller.ctrl, dev) for dev in devs])
|
add_entities([MochadLight(hass, mochad_controller.ctrl, dev) for dev in devs])
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class MochadLight(LightEntity):
|
class MochadLight(LightEntity):
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for X10 switch over Mochad."""
|
"""Support for X10 switch over Mochad."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pymochad import device
|
from pymochad import device
|
||||||
@ -7,7 +9,10 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.const import CONF_ADDRESS, CONF_DEVICES, CONF_NAME, CONF_PLATFORM
|
from homeassistant.const import CONF_ADDRESS, CONF_DEVICES, CONF_NAME, CONF_PLATFORM
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import CONF_COMM_TYPE, DOMAIN, REQ_LOCK
|
from . import CONF_COMM_TYPE, DOMAIN, REQ_LOCK
|
||||||
|
|
||||||
@ -28,12 +33,16 @@ PLATFORM_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
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 X10 switches over a mochad controller."""
|
"""Set up X10 switches over a mochad controller."""
|
||||||
mochad_controller = hass.data[DOMAIN]
|
mochad_controller = hass.data[DOMAIN]
|
||||||
devs = config.get(CONF_DEVICES)
|
devs = config[CONF_DEVICES]
|
||||||
add_entities([MochadSwitch(hass, mochad_controller.ctrl, dev) for dev in devs])
|
add_entities([MochadSwitch(hass, mochad_controller.ctrl, dev) for dev in devs])
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class MochadSwitch(SwitchEntity):
|
class MochadSwitch(SwitchEntity):
|
||||||
|
@ -6,6 +6,7 @@ import voluptuous as vol
|
|||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
from homeassistant.components.mqtt import valid_publish_topic
|
from homeassistant.components.mqtt import valid_publish_topic
|
||||||
from homeassistant.const import MATCH_ALL
|
from homeassistant.const import MATCH_ALL
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entityfilter import (
|
from homeassistant.helpers.entityfilter import (
|
||||||
INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA,
|
INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA,
|
||||||
@ -13,6 +14,7 @@ from homeassistant.helpers.entityfilter import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.event import async_track_state_change
|
from homeassistant.helpers.event import async_track_state_change
|
||||||
from homeassistant.helpers.json import JSONEncoder
|
from homeassistant.helpers.json import JSONEncoder
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
CONF_BASE_TOPIC = "base_topic"
|
CONF_BASE_TOPIC = "base_topic"
|
||||||
CONF_PUBLISH_ATTRIBUTES = "publish_attributes"
|
CONF_PUBLISH_ATTRIBUTES = "publish_attributes"
|
||||||
@ -34,9 +36,9 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the MQTT state feed."""
|
"""Set up the MQTT state feed."""
|
||||||
conf = config.get(DOMAIN)
|
conf = config[DOMAIN]
|
||||||
publish_filter = convert_include_exclude_filter(conf)
|
publish_filter = convert_include_exclude_filter(conf)
|
||||||
base_topic = conf.get(CONF_BASE_TOPIC)
|
base_topic = conf.get(CONF_BASE_TOPIC)
|
||||||
publish_attributes = conf.get(CONF_PUBLISH_ATTRIBUTES)
|
publish_attributes = conf.get(CONF_PUBLISH_ATTRIBUTES)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for departure information for public transport in Munich."""
|
"""Support for departure information for public transport in Munich."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
@ -8,7 +10,10 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, TIME_MINUTES
|
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, TIME_MINUTES
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
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 ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -40,7 +45,7 @@ SCAN_INTERVAL = timedelta(seconds=30)
|
|||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_NEXT_DEPARTURE): [
|
vol.Required(CONF_NEXT_DEPARTURE): [
|
||||||
{
|
{
|
||||||
vol.Required(CONF_STATION): cv.string,
|
vol.Required(CONF_STATION): cv.string,
|
||||||
vol.Optional(CONF_DESTINATIONS, default=[""]): cv.ensure_list_csv,
|
vol.Optional(CONF_DESTINATIONS, default=[""]): cv.ensure_list_csv,
|
||||||
@ -58,10 +63,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 MVGLive sensor."""
|
"""Set up the MVGLive sensor."""
|
||||||
sensors = []
|
sensors = []
|
||||||
for nextdeparture in config.get(CONF_NEXT_DEPARTURE):
|
for nextdeparture in config[CONF_NEXT_DEPARTURE]:
|
||||||
sensors.append(
|
sensors.append(
|
||||||
MVGLiveSensor(
|
MVGLiveSensor(
|
||||||
nextdeparture.get(CONF_STATION),
|
nextdeparture.get(CONF_STATION),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user