Skip to content
Snippets Groups Projects
Unverified Commit 939fde0a authored by Ville Skyttä's avatar Ville Skyttä Committed by GitHub
Browse files

ConfigType and async_setup/setup type hint improvements (#54739)

parent dcb2a211
Branches
Tags
No related merge requests found
Showing
with 37 additions and 23 deletions
...@@ -5,12 +5,13 @@ from homeassistant.components import websocket_api ...@@ -5,12 +5,13 @@ from homeassistant.components import websocket_api
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.event import async_call_later, async_track_time_interval from homeassistant.helpers.event import async_call_later, async_track_time_interval
from homeassistant.helpers.typing import ConfigType
from .analytics import Analytics from .analytics import Analytics
from .const import ATTR_ONBOARDED, ATTR_PREFERENCES, DOMAIN, INTERVAL, PREFERENCE_SCHEMA from .const import ATTR_ONBOARDED, ATTR_PREFERENCES, DOMAIN, INTERVAL, PREFERENCE_SCHEMA
async def async_setup(hass: HomeAssistant, _): async def async_setup(hass: HomeAssistant, _: ConfigType) -> bool:
"""Set up the analytics integration.""" """Set up the analytics integration."""
analytics = Analytics(hass) analytics = Analytics(hass)
......
...@@ -36,7 +36,7 @@ async def _await_cancel(task): ...@@ -36,7 +36,7 @@ async def _await_cancel(task):
await task await task
async def async_setup(hass: HomeAssistant, config: ConfigType): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the component.""" """Set up the component."""
hass.data[DOMAIN_DATA_ENTRIES] = {} hass.data[DOMAIN_DATA_ENTRIES] = {}
hass.data[DOMAIN_DATA_TASKS] = {} hass.data[DOMAIN_DATA_TASKS] = {}
......
...@@ -23,6 +23,7 @@ from homeassistant.helpers import device_registry, discovery ...@@ -23,6 +23,7 @@ from homeassistant.helpers import device_registry, discovery
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.event import track_utc_time_change from homeassistant.helpers.event import track_utc_time_change
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import slugify from homeassistant.util import slugify
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
...@@ -79,7 +80,7 @@ _SERVICE_MAP = { ...@@ -79,7 +80,7 @@ _SERVICE_MAP = {
UNDO_UPDATE_LISTENER = "undo_update_listener" UNDO_UPDATE_LISTENER = "undo_update_listener"
async def async_setup(hass: HomeAssistant, config: dict): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the BMW Connected Drive component from configuration.yaml.""" """Set up the BMW Connected Drive component from configuration.yaml."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][DATA_HASS_CONFIG] = config hass.data[DOMAIN][DATA_HASS_CONFIG] = config
......
...@@ -8,13 +8,14 @@ import coronavirus ...@@ -8,13 +8,14 @@ import coronavirus
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import aiohttp_client, entity_registry, update_coordinator from homeassistant.helpers import aiohttp_client, entity_registry, update_coordinator
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN from .const import DOMAIN
PLATFORMS = ["sensor"] PLATFORMS = ["sensor"]
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Coronavirus component.""" """Set up the Coronavirus component."""
# Make sure coordinator is initialized. # Make sure coordinator is initialized.
await get_coordinator(hass) await get_coordinator(hass)
......
...@@ -41,6 +41,7 @@ from homeassistant.helpers.event import ( ...@@ -41,6 +41,7 @@ from homeassistant.helpers.event import (
async_track_state_added_domain, async_track_state_added_domain,
async_track_time_interval, async_track_time_interval,
) )
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_dhcp from homeassistant.loader import async_get_dhcp
from homeassistant.util.network import is_invalid, is_link_local, is_loopback from homeassistant.util.network import is_invalid, is_link_local, is_loopback
...@@ -58,7 +59,7 @@ SCAN_INTERVAL = timedelta(minutes=60) ...@@ -58,7 +59,7 @@ SCAN_INTERVAL = timedelta(minutes=60)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the dhcp component.""" """Set up the dhcp component."""
async def _initialize(_): async def _initialize(_):
......
...@@ -22,6 +22,7 @@ from homeassistant.core import HomeAssistant, callback ...@@ -22,6 +22,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.network import get_url from homeassistant.helpers.network import get_url
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import dt as dt_util, slugify from homeassistant.util import dt as dt_util, slugify
from .const import ( from .const import (
...@@ -58,7 +59,7 @@ DEVICE_SCHEMA = vol.Schema( ...@@ -58,7 +59,7 @@ DEVICE_SCHEMA = vol.Schema(
CONFIG_SCHEMA = cv.deprecated(DOMAIN) CONFIG_SCHEMA = cv.deprecated(DOMAIN)
async def async_setup(hass: HomeAssistant, config: dict): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the DoorBird component.""" """Set up the DoorBird component."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
......
...@@ -12,6 +12,7 @@ from homeassistant.const import CONF_DEFAULT, CONF_HOST, CONF_NAME, CONF_PORT, C ...@@ -12,6 +12,7 @@ from homeassistant.const import CONF_DEFAULT, CONF_HOST, CONF_NAME, CONF_PORT, C
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
# Loading the config flow file will register the flow # Loading the config flow file will register the flow
from .bridge import DynaliteBridge from .bridge import DynaliteBridge
...@@ -179,7 +180,7 @@ CONFIG_SCHEMA = vol.Schema( ...@@ -179,7 +180,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Dynalite platform.""" """Set up the Dynalite platform."""
conf = config.get(DOMAIN) conf = config.get(DOMAIN)
LOGGER.debug("Setting up dynalite component config = %s", conf) LOGGER.debug("Setting up dynalite component config = %s", conf)
......
...@@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant ...@@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_registry import RegistryEntry from homeassistant.helpers.entity_registry import RegistryEntry
from homeassistant.helpers.template import Template, is_template_string from homeassistant.helpers.template import Template, is_template_string
from homeassistant.helpers.typing import ConfigType
from .const import CONF_POWER, CONF_POWER_ENTITY, DOMAIN from .const import CONF_POWER, CONF_POWER_ENTITY, DOMAIN
...@@ -48,7 +49,7 @@ CONFIG_SCHEMA = vol.Schema( ...@@ -48,7 +49,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass: HomeAssistant, config: dict): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the emulated_kasa component.""" """Set up the emulated_kasa component."""
conf = config.get(DOMAIN) conf = config.get(DOMAIN)
if not conf: if not conf:
......
...@@ -25,6 +25,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401 ...@@ -25,6 +25,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
) )
from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from homeassistant.util.percentage import ( from homeassistant.util.percentage import (
ordered_list_item_to_percentage, ordered_list_item_to_percentage,
...@@ -124,7 +125,7 @@ def is_on(hass, entity_id: str) -> bool: ...@@ -124,7 +125,7 @@ def is_on(hass, entity_id: str) -> bool:
return state.state == STATE_ON return state.state == STATE_ON
async def async_setup(hass, config: dict): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Expose fan control via statemachine and services.""" """Expose fan control via statemachine and services."""
component = hass.data[DOMAIN] = EntityComponent( component = hass.data[DOMAIN] = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL _LOGGER, DOMAIN, hass, SCAN_INTERVAL
......
...@@ -19,6 +19,7 @@ from homeassistant.const import ( ...@@ -19,6 +19,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, device_registry as dr from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.typing import ConfigType
from .board import FirmataBoard from .board import FirmataBoard
from .const import ( from .const import (
...@@ -122,7 +123,7 @@ CONFIG_SCHEMA = vol.Schema( ...@@ -122,7 +123,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Firmata domain.""" """Set up the Firmata domain."""
# Delete specific entries that no longer exist in the config # Delete specific entries that no longer exist in the config
if hass.config_entries.async_entries(DOMAIN): if hass.config_entries.async_entries(DOMAIN):
......
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
import voluptuous as vol import voluptuous as vol
# Typing imports
from homeassistant.const import CONF_API_KEY, CONF_NAME from homeassistant.const import CONF_API_KEY, CONF_NAME
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import ( from .const import (
CONF_ALIASES, CONF_ALIASES,
...@@ -91,7 +90,7 @@ CONFIG_SCHEMA = vol.Schema( ...@@ -91,7 +90,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass: HomeAssistant, yaml_config: dict[str, Any]): async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
"""Activate Google Actions component.""" """Activate Google Actions component."""
if DOMAIN not in yaml_config: if DOMAIN not in yaml_config:
return True return True
......
...@@ -5,7 +5,6 @@ import datetime ...@@ -5,7 +5,6 @@ import datetime
import json import json
import logging import logging
import os import os
from typing import Any
from google.cloud import pubsub_v1 from google.cloud import pubsub_v1
import voluptuous as vol import voluptuous as vol
...@@ -14,6 +13,7 @@ from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE, STATE_UN ...@@ -14,6 +13,7 @@ from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE, STATE_UN
from homeassistant.core import Event, HomeAssistant from homeassistant.core import Event, HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entityfilter import FILTER_SCHEMA from homeassistant.helpers.entityfilter import FILTER_SCHEMA
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
...@@ -39,7 +39,7 @@ CONFIG_SCHEMA = vol.Schema( ...@@ -39,7 +39,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
def setup(hass: HomeAssistant, yaml_config: dict[str, Any]): def setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
"""Activate Google Pub/Sub component.""" """Activate Google Pub/Sub component."""
config = yaml_config[DOMAIN] config = yaml_config[DOMAIN]
project_id = config[CONF_PROJECT_ID] project_id = config[CONF_PROJECT_ID]
......
...@@ -16,6 +16,7 @@ from homeassistant.const import ( ...@@ -16,6 +16,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import ConfigType
from .const import ( from .const import (
ATTR_ARGS, ATTR_ARGS,
...@@ -83,7 +84,7 @@ SERVICE_API_CALL_SCHEMA = vol.Schema( ...@@ -83,7 +84,7 @@ SERVICE_API_CALL_SCHEMA = vol.Schema(
) )
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Habitica service.""" """Set up the Habitica service."""
configs = config.get(DOMAIN, []) configs = config.get(DOMAIN, [])
......
...@@ -45,6 +45,7 @@ from homeassistant.core import HomeAssistant ...@@ -45,6 +45,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery, event from homeassistant.helpers import discovery, event
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
DOMAIN = "hdmi_cec" DOMAIN = "hdmi_cec"
...@@ -186,7 +187,7 @@ def parse_mapping(mapping, parents=None): ...@@ -186,7 +187,7 @@ def parse_mapping(mapping, parents=None):
yield (val, pad_physical_address(cur)) yield (val, pad_physical_address(cur))
def setup(hass: HomeAssistant, base_config): # noqa: C901 def setup(hass: HomeAssistant, base_config: ConfigType) -> bool: # noqa: C901
"""Set up the CEC capability.""" """Set up the CEC capability."""
# Parse configuration into a dict of device name to physical address # Parse configuration into a dict of device name to physical address
......
...@@ -43,7 +43,7 @@ MIN_UPDATE_SOURCES = timedelta(seconds=1) ...@@ -43,7 +43,7 @@ MIN_UPDATE_SOURCES = timedelta(seconds=1)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: ConfigType): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the HEOS component.""" """Set up the HEOS component."""
if DOMAIN not in config: if DOMAIN not in config:
return True return True
......
...@@ -10,6 +10,7 @@ from homeassistant.config_entries import ConfigEntry ...@@ -10,6 +10,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import Throttle from homeassistant.util import Throttle
from . import api, config_flow from . import api, config_flow
...@@ -34,7 +35,7 @@ CONFIG_SCHEMA = vol.Schema( ...@@ -34,7 +35,7 @@ CONFIG_SCHEMA = vol.Schema(
PLATFORMS = ["binary_sensor", "light", "sensor", "switch"] PLATFORMS = ["binary_sensor", "light", "sensor", "switch"]
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Home Connect component.""" """Set up Home Connect component."""
hass.data[DOMAIN] = {} hass.data[DOMAIN] = {}
......
...@@ -16,6 +16,7 @@ from homeassistant.helpers import ( ...@@ -16,6 +16,7 @@ from homeassistant.helpers import (
dispatcher, dispatcher,
) )
from homeassistant.helpers.device_registry import async_get as async_get_device_registry from homeassistant.helpers.device_registry import async_get as async_get_device_registry
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from . import config_flow, helpers from . import config_flow, helpers
...@@ -50,7 +51,7 @@ PLATFORMS = ["switch"] ...@@ -50,7 +51,7 @@ PLATFORMS = ["switch"]
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Legrand Home+ Control component from configuration.yaml.""" """Set up the Legrand Home+ Control component from configuration.yaml."""
hass.data[DOMAIN] = {} hass.data[DOMAIN] = {}
......
...@@ -26,6 +26,7 @@ from homeassistant.helpers.service import ( ...@@ -26,6 +26,7 @@ from homeassistant.helpers.service import (
async_extract_config_entry_ids, async_extract_config_entry_ids,
async_extract_referenced_entity_ids, async_extract_referenced_entity_ids,
) )
from homeassistant.helpers.typing import ConfigType
ATTR_ENTRY_ID = "entry_id" ATTR_ENTRY_ID = "entry_id"
...@@ -51,7 +52,7 @@ SCHEMA_RELOAD_CONFIG_ENTRY = vol.All( ...@@ -51,7 +52,7 @@ SCHEMA_RELOAD_CONFIG_ENTRY = vol.All(
SHUTDOWN_SERVICES = (SERVICE_HOMEASSISTANT_STOP, SERVICE_HOMEASSISTANT_RESTART) SHUTDOWN_SERVICES = (SERVICE_HOMEASSISTANT_STOP, SERVICE_HOMEASSISTANT_RESTART)
async def async_setup(hass: ha.HomeAssistant, config: dict) -> bool: # noqa: C901 async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # noqa: C901
"""Set up general services related to Home Assistant.""" """Set up general services related to Home Assistant."""
async def async_save_persistent_states(service): async def async_save_persistent_states(service):
......
...@@ -44,6 +44,7 @@ import homeassistant.helpers.config_validation as cv ...@@ -44,6 +44,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entityfilter import BASE_FILTER_SCHEMA, FILTER_SCHEMA from homeassistant.helpers.entityfilter import BASE_FILTER_SCHEMA, FILTER_SCHEMA
from homeassistant.helpers.reload import async_integration_yaml_config from homeassistant.helpers.reload import async_integration_yaml_config
from homeassistant.helpers.service import async_extract_referenced_entity_ids from homeassistant.helpers.service import async_extract_referenced_entity_ids
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import IntegrationNotFound, async_get_integration from homeassistant.loader import IntegrationNotFound, async_get_integration
from . import ( # noqa: F401 from . import ( # noqa: F401
...@@ -187,7 +188,7 @@ def _async_get_entries_by_name(current_entries): ...@@ -187,7 +188,7 @@ def _async_get_entries_by_name(current_entries):
return {entry.data.get(CONF_NAME, BRIDGE_NAME): entry for entry in current_entries} return {entry.data.get(CONF_NAME, BRIDGE_NAME): entry for entry in current_entries}
async def async_setup(hass: HomeAssistant, config: dict): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the HomeKit from yaml.""" """Set up the HomeKit from yaml."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
......
...@@ -298,7 +298,7 @@ class Router: ...@@ -298,7 +298,7 @@ class Router:
class HuaweiLteData: class HuaweiLteData:
"""Shared state.""" """Shared state."""
hass_config: dict = attr.ib() hass_config: ConfigType = attr.ib()
# Our YAML config, keyed by router URL # Our YAML config, keyed by router URL
config: dict[str, dict[str, Any]] = attr.ib() config: dict[str, dict[str, Any]] = attr.ib()
routers: dict[str, Router] = attr.ib(init=False, factory=dict) routers: dict[str, Router] = attr.ib(init=False, factory=dict)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment