From 545e321002fd4edd349083a4a6aa057e42280ea7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 31 Dec 2021 06:17:05 +0100 Subject: [PATCH] Add init type hints [a] (#63098) Co-authored-by: epenet --- homeassistant/components/agent_dvr/__init__.py | 7 ++++--- homeassistant/components/alert/__init__.py | 5 +++-- homeassistant/components/ambiclimate/__init__.py | 3 ++- homeassistant/components/android_ip_webcam/__init__.py | 5 +++-- homeassistant/components/androidtv/__init__.py | 5 +++-- homeassistant/components/apache_kafka/__init__.py | 4 +++- homeassistant/components/apcupsd/__init__.py | 4 +++- homeassistant/components/apple_tv/__init__.py | 7 ++++--- homeassistant/components/aqualogic/__init__.py | 4 +++- homeassistant/components/arcam_fmj/__init__.py | 2 +- homeassistant/components/arduino/__init__.py | 4 +++- homeassistant/components/arlo/__init__.py | 5 +++-- homeassistant/components/asuswrt/__init__.py | 4 ++-- homeassistant/components/atag/__init__.py | 2 +- homeassistant/components/auth/__init__.py | 3 ++- homeassistant/components/automation/__init__.py | 4 ++-- homeassistant/components/awair/__init__.py | 6 ++++-- homeassistant/components/axis/__init__.py | 8 ++++---- 18 files changed, 50 insertions(+), 32 deletions(-) diff --git a/homeassistant/components/agent_dvr/__init__.py b/homeassistant/components/agent_dvr/__init__.py index 373b5c2e291..a2831fe301e 100644 --- a/homeassistant/components/agent_dvr/__init__.py +++ b/homeassistant/components/agent_dvr/__init__.py @@ -1,9 +1,10 @@ """Support for Agent.""" - from agent import AgentError from agent.a import Agent +from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform +from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -16,7 +17,7 @@ DEFAULT_BRAND = "Agent DVR by ispyconnect.com" PLATFORMS = [Platform.ALARM_CONTROL_PANEL, Platform.CAMERA] -async def async_setup_entry(hass, config_entry): +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up the Agent component.""" hass.data.setdefault(AGENT_DOMAIN, {}) @@ -52,7 +53,7 @@ async def async_setup_entry(hass, config_entry): return True -async def async_unload_entry(hass, config_entry): +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload a config entry.""" unload_ok = await hass.config_entries.async_unload_platforms( config_entry, PLATFORMS diff --git a/homeassistant/components/alert/__init__.py b/homeassistant/components/alert/__init__.py index 871778a9c11..252bba54b1c 100644 --- a/homeassistant/components/alert/__init__.py +++ b/homeassistant/components/alert/__init__.py @@ -23,10 +23,11 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, ) -from homeassistant.core import ServiceCall +from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import event, service import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import ToggleEntity +from homeassistant.helpers.typing import ConfigType from homeassistant.util.dt import now _LOGGER = logging.getLogger(__name__) @@ -77,7 +78,7 @@ def is_on(hass, entity_id): return hass.states.is_state(entity_id, STATE_ON) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Alert component.""" entities = [] diff --git a/homeassistant/components/ambiclimate/__init__.py b/homeassistant/components/ambiclimate/__init__.py index 18cf8c177d9..acab01e30d1 100644 --- a/homeassistant/components/ambiclimate/__init__.py +++ b/homeassistant/components/ambiclimate/__init__.py @@ -5,6 +5,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType from . import config_flow from .const import DOMAIN @@ -24,7 +25,7 @@ CONFIG_SCHEMA = vol.Schema( PLATFORMS = [Platform.CLIMATE] -async def async_setup(hass, config) -> bool: +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up Ambiclimate components.""" if DOMAIN not in config: return True diff --git a/homeassistant/components/android_ip_webcam/__init__.py b/homeassistant/components/android_ip_webcam/__init__.py index 54a281feacd..7ea5d3c774e 100644 --- a/homeassistant/components/android_ip_webcam/__init__.py +++ b/homeassistant/components/android_ip_webcam/__init__.py @@ -18,7 +18,7 @@ from homeassistant.const import ( CONF_TIMEOUT, CONF_USERNAME, ) -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import discovery from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv @@ -28,6 +28,7 @@ from homeassistant.helpers.dispatcher import ( ) from homeassistant.helpers.entity import Entity from homeassistant.helpers.event import async_track_point_in_utc_time +from homeassistant.helpers.typing import ConfigType from homeassistant.util.dt import utcnow ATTR_AUD_CONNS = "Audio Connections" @@ -183,7 +184,7 @@ CONFIG_SCHEMA = vol.Schema( ) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the IP Webcam component.""" webcams = hass.data[DATA_IP_WEBCAM] = {} diff --git a/homeassistant/components/androidtv/__init__.py b/homeassistant/components/androidtv/__init__.py index d64329526b8..e52e37df88e 100644 --- a/homeassistant/components/androidtv/__init__.py +++ b/homeassistant/components/androidtv/__init__.py @@ -20,6 +20,7 @@ from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.storage import STORAGE_DIR +from homeassistant.helpers.typing import ConfigType from .const import ( ANDROID_DEV, @@ -125,7 +126,7 @@ def _migrate_aftv_entity(hass, aftv, entry_unique_id): _LOGGER.warning("Migration of old entity failed: %s", exp) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Android TV integration.""" return True @@ -163,7 +164,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): aftv = hass.data[DOMAIN][entry.entry_id][ANDROID_DEV] diff --git a/homeassistant/components/apache_kafka/__init__.py b/homeassistant/components/apache_kafka/__init__.py index 5be3732757f..1b293bd2c04 100644 --- a/homeassistant/components/apache_kafka/__init__.py +++ b/homeassistant/components/apache_kafka/__init__.py @@ -15,8 +15,10 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) +from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entityfilter import FILTER_SCHEMA +from homeassistant.helpers.typing import ConfigType from homeassistant.util import ssl as ssl_util DOMAIN = "apache_kafka" @@ -45,7 +47,7 @@ CONFIG_SCHEMA = vol.Schema( ) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Activate the Apache Kafka integration.""" conf = config[DOMAIN] diff --git a/homeassistant/components/apcupsd/__init__.py b/homeassistant/components/apcupsd/__init__.py index 181f70d725a..7cbf33f8b47 100644 --- a/homeassistant/components/apcupsd/__init__.py +++ b/homeassistant/components/apcupsd/__init__.py @@ -6,7 +6,9 @@ from apcaccess import status import voluptuous as vol from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.typing import ConfigType from homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -34,7 +36,7 @@ CONFIG_SCHEMA = vol.Schema( ) -def setup(hass, config): +def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Use config values to set up a function enabling status retrieval.""" conf = config[DOMAIN] host = conf[CONF_HOST] diff --git a/homeassistant/components/apple_tv/__init__.py b/homeassistant/components/apple_tv/__init__.py index 200984ca883..af581db1a18 100644 --- a/homeassistant/components/apple_tv/__init__.py +++ b/homeassistant/components/apple_tv/__init__.py @@ -9,6 +9,7 @@ from pyatv.convert import model_str from homeassistant.components.media_player import DOMAIN as MP_DOMAIN from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_CONNECTIONS, ATTR_IDENTIFIERS, @@ -21,7 +22,7 @@ from homeassistant.const import ( CONF_NAME, EVENT_HOMEASSISTANT_STOP, ) -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.dispatcher import ( @@ -45,7 +46,7 @@ SIGNAL_DISCONNECTED = "apple_tv_disconnected" PLATFORMS = [MP_DOMAIN, REMOTE_DOMAIN] -async def async_setup_entry(hass, entry): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up a config entry for Apple TV.""" manager = AppleTVManager(hass, entry) hass.data.setdefault(DOMAIN, {})[entry.unique_id] = manager @@ -73,7 +74,7 @@ async def async_setup_entry(hass, entry): return True -async def async_unload_entry(hass, entry): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload an Apple TV config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/aqualogic/__init__.py b/homeassistant/components/aqualogic/__init__.py index 0878419a792..0c4ecaa1683 100644 --- a/homeassistant/components/aqualogic/__init__.py +++ b/homeassistant/components/aqualogic/__init__.py @@ -13,7 +13,9 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) @@ -32,7 +34,7 @@ CONFIG_SCHEMA = vol.Schema( ) -def setup(hass, config): +def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up AquaLogic platform.""" host = config[DOMAIN][CONF_HOST] port = config[DOMAIN][CONF_PORT] diff --git a/homeassistant/components/arcam_fmj/__init__.py b/homeassistant/components/arcam_fmj/__init__.py index 3cb4c83211f..ee86fc8c4b5 100644 --- a/homeassistant/components/arcam_fmj/__init__.py +++ b/homeassistant/components/arcam_fmj/__init__.py @@ -67,7 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True -async def async_unload_entry(hass, entry): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Cleanup before removing config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/arduino/__init__.py b/homeassistant/components/arduino/__init__.py index 2890fd4abda..6de03526ed3 100644 --- a/homeassistant/components/arduino/__init__.py +++ b/homeassistant/components/arduino/__init__.py @@ -10,7 +10,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__) @@ -21,7 +23,7 @@ CONFIG_SCHEMA = vol.Schema( ) -def setup(hass, config): +def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Arduino component.""" _LOGGER.warning( "The %s integration has been deprecated. Please move your " diff --git a/homeassistant/components/arlo/__init__.py b/homeassistant/components/arlo/__init__.py index 7a16a2d7ae6..3a869856504 100644 --- a/homeassistant/components/arlo/__init__.py +++ b/homeassistant/components/arlo/__init__.py @@ -9,10 +9,11 @@ from requests.exceptions import ConnectTimeout, HTTPError import voluptuous as vol from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME -from homeassistant.core import ServiceCall +from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from homeassistant.helpers.dispatcher import dispatcher_send from homeassistant.helpers.event import track_time_interval +from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) @@ -43,7 +44,7 @@ CONFIG_SCHEMA = vol.Schema( ) -def setup(hass, config): +def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up an Arlo component.""" conf = config[DOMAIN] username = conf[CONF_USERNAME] diff --git a/homeassistant/components/asuswrt/__init__.py b/homeassistant/components/asuswrt/__init__.py index fb6c547cc6b..7d3ea839ebd 100644 --- a/homeassistant/components/asuswrt/__init__.py +++ b/homeassistant/components/asuswrt/__init__.py @@ -1,5 +1,4 @@ """Support for ASUSWRT devices.""" - import voluptuous as vol from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry @@ -16,6 +15,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType from .const import ( CONF_DNSMASQ, @@ -72,7 +72,7 @@ CONFIG_SCHEMA = vol.Schema( ) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the AsusWrt integration.""" if (conf := config.get(DOMAIN)) is None: return True diff --git a/homeassistant/components/atag/__init__.py b/homeassistant/components/atag/__init__.py index 82340032a1a..6eb17fded3f 100644 --- a/homeassistant/components/atag/__init__.py +++ b/homeassistant/components/atag/__init__.py @@ -56,7 +56,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True -async def async_unload_entry(hass, entry): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload Atag config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/auth/__init__.py b/homeassistant/components/auth/__init__.py index 374a36683da..1ca74231298 100644 --- a/homeassistant/components/auth/__init__.py +++ b/homeassistant/components/auth/__init__.py @@ -134,6 +134,7 @@ from homeassistant.components.http.ban import log_invalid_auth from homeassistant.components.http.data_validator import RequestDataValidator from homeassistant.components.http.view import HomeAssistantView from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util import dt as dt_util @@ -186,7 +187,7 @@ def create_auth_code(hass, client_id: str, credential: Credentials) -> str: return hass.data[DOMAIN](client_id, credential) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Component to allow users to login.""" store_result, retrieve_result = _create_auth_code_store() diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 64c6b335fbd..1aefeff5d6b 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -66,7 +66,7 @@ from homeassistant.helpers.trace import ( trace_path, ) from homeassistant.helpers.trigger import async_initialize_triggers -from homeassistant.helpers.typing import TemplateVarsType +from homeassistant.helpers.typing import ConfigType, TemplateVarsType from homeassistant.loader import bind_hass from homeassistant.util.dt import parse_datetime @@ -220,7 +220,7 @@ def areas_in_automation(hass: HomeAssistant, entity_id: str) -> list[str]: return list(automation_entity.referenced_areas) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up all automations.""" hass.data[DOMAIN] = component = EntityComponent(LOGGER, DOMAIN, hass) diff --git a/homeassistant/components/awair/__init__.py b/homeassistant/components/awair/__init__.py index 2cfaa88022d..c82c7ed19bd 100644 --- a/homeassistant/components/awair/__init__.py +++ b/homeassistant/components/awair/__init__.py @@ -8,7 +8,9 @@ from async_timeout import timeout from python_awair import Awair from python_awair.exceptions import AuthError +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ACCESS_TOKEN, Platform +from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -18,7 +20,7 @@ from .const import API_TIMEOUT, DOMAIN, LOGGER, UPDATE_INTERVAL, AwairResult PLATFORMS = [Platform.SENSOR] -async def async_setup_entry(hass, config_entry) -> bool: +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up Awair integration from a config entry.""" session = async_get_clientsession(hass) coordinator = AwairDataUpdateCoordinator(hass, config_entry, session) @@ -33,7 +35,7 @@ async def async_setup_entry(hass, config_entry) -> bool: return True -async def async_unload_entry(hass, config_entry) -> bool: +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload Awair configuration.""" unload_ok = await hass.config_entries.async_unload_platforms( config_entry, PLATFORMS diff --git a/homeassistant/components/axis/__init__.py b/homeassistant/components/axis/__init__.py index e3c4d20fc04..68c656980dc 100644 --- a/homeassistant/components/axis/__init__.py +++ b/homeassistant/components/axis/__init__.py @@ -1,9 +1,9 @@ """Support for Axis devices.""" - import logging +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_DEVICE, CONF_MAC, EVENT_HOMEASSISTANT_STOP -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.entity_registry import async_migrate_entries @@ -13,7 +13,7 @@ from .device import AxisNetworkDevice _LOGGER = logging.getLogger(__name__) -async def async_setup_entry(hass, config_entry): +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up the Axis component.""" hass.data.setdefault(AXIS_DOMAIN, {}) @@ -33,7 +33,7 @@ async def async_setup_entry(hass, config_entry): return True -async def async_unload_entry(hass, config_entry): +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload Axis device config entry.""" device = hass.data[AXIS_DOMAIN].pop(config_entry.unique_id) return await device.async_reset()