diff --git a/homeassistant/components/maxcube/binary_sensor.py b/homeassistant/components/maxcube/binary_sensor.py index f24f56e52d7..f674ec38d37 100644 --- a/homeassistant/components/maxcube/binary_sensor.py +++ b/homeassistant/components/maxcube/binary_sensor.py @@ -1,16 +1,26 @@ """Support for MAX! binary sensors via MAX! Cube.""" +from __future__ import annotations + from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, BinarySensorEntity, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory +from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType 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.""" - devices = [] + devices: list[MaxCubeBinarySensorBase] = [] for handler in hass.data[DATA_KEY].values(): for device in handler.cube.devices: devices.append(MaxCubeBattery(handler, device)) diff --git a/homeassistant/components/mazda/sensor.py b/homeassistant/components/mazda/sensor.py index 6ef0d160b3b..ee42b989c49 100644 --- a/homeassistant/components/mazda/sensor.py +++ b/homeassistant/components/mazda/sensor.py @@ -1,22 +1,31 @@ """Platform for Mazda sensor integration.""" +from __future__ import annotations + from homeassistant.components.sensor import SensorEntity +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( LENGTH_KILOMETERS, LENGTH_MILES, PERCENTAGE, PRESSURE_PSI, ) +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import MazdaEntity 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.""" client = hass.data[DOMAIN][config_entry.entry_id][DATA_CLIENT] coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR] - entities = [] + entities: list[SensorEntity] = [] for index, _ in enumerate(coordinator.data): entities.append(MazdaFuelRemainingSensor(client, coordinator, index)) diff --git a/homeassistant/components/mcp23017/switch.py b/homeassistant/components/mcp23017/switch.py index 5c4c06a585a..f9211538f56 100644 --- a/homeassistant/components/mcp23017/switch.py +++ b/homeassistant/components/mcp23017/switch.py @@ -1,4 +1,6 @@ """Support for switch sensor using I2C MCP23017 chip.""" +from __future__ import annotations + import logging from adafruit_mcp230xx.mcp23017 import MCP23017 @@ -9,8 +11,11 @@ import voluptuous as vol from homeassistant.components.switch import PLATFORM_SCHEMA from homeassistant.const import DEVICE_DEFAULT_NAME +from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv 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_I2C_ADDRESS = "i2c_address" @@ -33,7 +38,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( _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.""" _LOGGER.warning( "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) switches = [] - pins = config.get(CONF_PINS) + pins = config[CONF_PINS] for pin_num, pin_name in pins.items(): pin = mcp.get_pin(pin_num) switches.append(MCP23017Switch(pin_name, pin, invert_logic)) diff --git a/homeassistant/components/microsoft_face/__init__.py b/homeassistant/components/microsoft_face/__init__.py index 1604c77614f..19bfef1349c 100644 --- a/homeassistant/components/microsoft_face/__init__.py +++ b/homeassistant/components/microsoft_face/__init__.py @@ -1,4 +1,6 @@ """Support for Microsoft face recognition.""" +from __future__ import annotations + import asyncio import json import logging @@ -9,11 +11,12 @@ import async_timeout import voluptuous as vol 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.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity +from homeassistant.helpers.typing import ConfigType from homeassistant.util import slugify _LOGGER = logging.getLogger(__name__) @@ -67,9 +70,9 @@ SCHEMA_FACE_SERVICE = vol.Schema( 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.""" - entities = {} + entities: dict[str, MicrosoftFaceGroupEntity] = {} face = MicrosoftFace( hass, config[DOMAIN].get(CONF_AZURE_REGION), diff --git a/homeassistant/components/mochad/__init__.py b/homeassistant/components/mochad/__init__.py index 6f560aa9ed6..114ade17740 100644 --- a/homeassistant/components/mochad/__init__.py +++ b/homeassistant/components/mochad/__init__.py @@ -11,7 +11,9 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, ) +from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.typing import ConfigType _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.""" conf = config[DOMAIN] host = conf.get(CONF_HOST) @@ -42,8 +44,8 @@ def setup(hass, config): try: mochad_controller = MochadCtrl(host, port) - except exceptions.ConfigurationError: - _LOGGER.exception() + except exceptions.ConfigurationError as err: + _LOGGER.exception(str(err)) return False def stop_mochad(event): diff --git a/homeassistant/components/mochad/light.py b/homeassistant/components/mochad/light.py index a3a06a58ea5..a966d0ad9f6 100644 --- a/homeassistant/components/mochad/light.py +++ b/homeassistant/components/mochad/light.py @@ -1,4 +1,6 @@ """Support for X10 dimmer over Mochad.""" +from __future__ import annotations + import logging from pymochad import device @@ -12,7 +14,10 @@ from homeassistant.components.light import ( LightEntity, ) 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.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType 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.""" 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]) - return True class MochadLight(LightEntity): diff --git a/homeassistant/components/mochad/switch.py b/homeassistant/components/mochad/switch.py index d23d46c8392..7175955d81a 100644 --- a/homeassistant/components/mochad/switch.py +++ b/homeassistant/components/mochad/switch.py @@ -1,4 +1,6 @@ """Support for X10 switch over Mochad.""" +from __future__ import annotations + import logging from pymochad import device @@ -7,7 +9,10 @@ import voluptuous as vol from homeassistant.components.switch import SwitchEntity 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.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType 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.""" 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]) - return True class MochadSwitch(SwitchEntity): diff --git a/homeassistant/components/mqtt_statestream/__init__.py b/homeassistant/components/mqtt_statestream/__init__.py index d0a13a7384b..5213f675460 100644 --- a/homeassistant/components/mqtt_statestream/__init__.py +++ b/homeassistant/components/mqtt_statestream/__init__.py @@ -6,6 +6,7 @@ import voluptuous as vol from homeassistant.components import mqtt from homeassistant.components.mqtt import valid_publish_topic from homeassistant.const import MATCH_ALL +from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entityfilter import ( 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.json import JSONEncoder +from homeassistant.helpers.typing import ConfigType CONF_BASE_TOPIC = "base_topic" 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.""" - conf = config.get(DOMAIN) + conf = config[DOMAIN] publish_filter = convert_include_exclude_filter(conf) base_topic = conf.get(CONF_BASE_TOPIC) publish_attributes = conf.get(CONF_PUBLISH_ATTRIBUTES) diff --git a/homeassistant/components/mvglive/sensor.py b/homeassistant/components/mvglive/sensor.py index 29554e89c5d..d3405d0cce7 100644 --- a/homeassistant/components/mvglive/sensor.py +++ b/homeassistant/components/mvglive/sensor.py @@ -1,4 +1,6 @@ """Support for departure information for public transport in Munich.""" +from __future__ import annotations + from copy import deepcopy from datetime import timedelta import logging @@ -8,7 +10,10 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, TIME_MINUTES +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__) @@ -40,7 +45,7 @@ SCAN_INTERVAL = timedelta(seconds=30) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { - vol.Optional(CONF_NEXT_DEPARTURE): [ + vol.Required(CONF_NEXT_DEPARTURE): [ { vol.Required(CONF_STATION): cv.string, 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.""" sensors = [] - for nextdeparture in config.get(CONF_NEXT_DEPARTURE): + for nextdeparture in config[CONF_NEXT_DEPARTURE]: sensors.append( MVGLiveSensor( nextdeparture.get(CONF_STATION),