From 250379e181594e87aba08e6e919cbe66490584e7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 19 Jan 2022 18:00:34 +0100 Subject: [PATCH] Add setup type hints (init) (#64351) * Add setup type hints to acmeda * Add setup type hints to xiaomi_aqara * Add setup type hints to motion_blinds * Add setup type hints to xiaomi_miio * Add setup type hints to diagnostics * Add setup type hints to zha * Add setup type hints to firmata * Add setup type hints to denonavr * Add setup type hints to rfxtrx * Add setup type hints to hue * Cleanup denonavr * Add return types to xiaomi_miio * Fix return type Co-authored-by: epenet Co-authored-by: Martin Hjelmare --- homeassistant/components/acmeda/__init__.py | 12 +++----- homeassistant/components/denonavr/__init__.py | 15 ++++------ .../components/diagnostics/__init__.py | 3 +- homeassistant/components/firmata/__init__.py | 12 +++----- homeassistant/components/hue/__init__.py | 14 ++++------ .../components/motion_blinds/__init__.py | 15 ++++------ homeassistant/components/rfxtrx/__init__.py | 5 ++-- .../components/xiaomi_aqara/__init__.py | 10 ++----- .../components/xiaomi_miio/__init__.py | 28 ++++++------------- homeassistant/components/zha/__init__.py | 16 ++++------- 10 files changed, 45 insertions(+), 85 deletions(-) diff --git a/homeassistant/components/acmeda/__init__.py b/homeassistant/components/acmeda/__init__.py index 49b4d9b85e8..1021a466337 100644 --- a/homeassistant/components/acmeda/__init__.py +++ b/homeassistant/components/acmeda/__init__.py @@ -1,7 +1,7 @@ """The Rollease Acmeda Automate integration.""" - -from homeassistant import config_entries, core +from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform +from homeassistant.core import HomeAssistant from .const import DOMAIN from .hub import PulseHub @@ -11,9 +11,7 @@ CONF_HUBS = "hubs" PLATFORMS = [Platform.COVER, Platform.SENSOR] -async def async_setup_entry( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up Rollease Acmeda Automate hub from a config entry.""" hub = PulseHub(hass, config_entry) @@ -28,9 +26,7 @@ async def async_setup_entry( return True -async def async_unload_entry( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload a config entry.""" hub = hass.data[DOMAIN][config_entry.entry_id] diff --git a/homeassistant/components/denonavr/__init__.py b/homeassistant/components/denonavr/__init__.py index d58bbe963d7..a6678d8b533 100644 --- a/homeassistant/components/denonavr/__init__.py +++ b/homeassistant/components/denonavr/__init__.py @@ -3,8 +3,9 @@ import logging from denonavr.exceptions import AvrNetworkError, AvrTimoutError -from homeassistant import config_entries, core +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, Platform +from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import entity_registry as er from homeassistant.helpers.httpx_client import get_async_client @@ -28,9 +29,7 @@ PLATFORMS = [Platform.MEDIA_PLAYER] _LOGGER = logging.getLogger(__name__) -async def async_setup_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the denonavr components from a config entry.""" hass.data.setdefault(DOMAIN, {}) @@ -61,9 +60,7 @@ async def async_setup_entry( return True -async def async_unload_entry( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -): +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 @@ -91,8 +88,6 @@ async def async_unload_entry( return unload_ok -async def update_listener( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry): """Handle options update.""" await hass.config_entries.async_reload(config_entry.entry_id) diff --git a/homeassistant/components/diagnostics/__init__.py b/homeassistant/components/diagnostics/__init__.py index b2f899b5a89..6d675606563 100644 --- a/homeassistant/components/diagnostics/__init__.py +++ b/homeassistant/components/diagnostics/__init__.py @@ -13,6 +13,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import integration_platform from homeassistant.helpers.json import ExtendedJSONEncoder +from homeassistant.helpers.typing import ConfigType from homeassistant.util.json import ( find_paths_unserializable_data, format_unserializable_data, @@ -23,7 +24,7 @@ from .const import DOMAIN _LOGGER = logging.getLogger(__name__) -async def async_setup(hass: HomeAssistant, config: dict) -> bool: +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up Diagnostics from a config entry.""" hass.data[DOMAIN] = {} diff --git a/homeassistant/components/firmata/__init__.py b/homeassistant/components/firmata/__init__.py index d147d84b341..cef9db620b8 100644 --- a/homeassistant/components/firmata/__init__.py +++ b/homeassistant/components/firmata/__init__.py @@ -5,7 +5,7 @@ import logging import voluptuous as vol -from homeassistant import config_entries +from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import ( CONF_BINARY_SENSORS, CONF_LIGHTS, @@ -150,7 +150,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.async_create_task( hass.config_entries.flow.async_init( DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, + context={"source": SOURCE_IMPORT}, data=firmata_config, ) ) @@ -158,9 +158,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def async_setup_entry( - hass: HomeAssistant, config_entry: config_entries.ConfigEntry -) -> bool: +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up a Firmata board for a config entry.""" if DOMAIN not in hass.data: hass.data[DOMAIN] = {} @@ -207,9 +205,7 @@ async def async_setup_entry( return True -async def async_unload_entry( - hass: HomeAssistant, config_entry: config_entries.ConfigEntry -) -> None: +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Shutdown and close a Firmata board for a config entry.""" _LOGGER.debug("Closing Firmata board %s", config_entry.data[CONF_NAME]) diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index 794283e09f5..9723d506404 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -1,9 +1,9 @@ """Support for the Philips Hue system.""" - from aiohue.util import normalize_bridge_id -from homeassistant import config_entries, core from homeassistant.components import persistent_notification +from homeassistant.config_entries import SOURCE_IGNORE, ConfigEntry +from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr from .bridge import HueBridge @@ -12,9 +12,7 @@ from .migration import check_migration from .services import async_register_services -async def async_setup_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up a bridge from a config entry.""" # check (and run) migrations if needed await check_migration(hass, entry) @@ -50,7 +48,7 @@ async def async_setup_entry( # If no other entry, update unique ID of this entry ID. hass.config_entries.async_update_entry(entry, unique_id=unique_id) - elif other_entry.source == config_entries.SOURCE_IGNORE: + elif other_entry.source == SOURCE_IGNORE: # There is another entry but it is ignored, delete that one and update this one hass.async_create_task( hass.config_entries.async_remove(other_entry.entry_id) @@ -103,9 +101,7 @@ async def async_setup_entry( return True -async def async_unload_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" unload_success = await hass.data[DOMAIN][entry.entry_id].async_reset() if len(hass.data[DOMAIN]) == 0: diff --git a/homeassistant/components/motion_blinds/__init__.py b/homeassistant/components/motion_blinds/__init__.py index 1cf0371ef92..7f31ecf3f61 100644 --- a/homeassistant/components/motion_blinds/__init__.py +++ b/homeassistant/components/motion_blinds/__init__.py @@ -6,8 +6,9 @@ from typing import TYPE_CHECKING from motionblinds import AsyncMotionMulticast, ParseException -from homeassistant import config_entries, core +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_API_KEY, CONF_HOST, EVENT_HOMEASSISTANT_STOP +from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import device_registry as dr from homeassistant.helpers.update_coordinator import DataUpdateCoordinator @@ -97,9 +98,7 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator): return data -async def async_setup_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the motion_blinds components from a config entry.""" hass.data.setdefault(DOMAIN, {}) host = entry.data[CONF_HOST] @@ -177,9 +176,7 @@ async def async_setup_entry( return True -async def async_unload_entry( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -): +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 @@ -197,8 +194,6 @@ async def async_unload_entry( return unload_ok -async def update_listener( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -) -> None: +async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None: """Handle options update.""" await hass.config_entries.async_reload(config_entry.entry_id) diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index 10be57fd247..6700e66a941 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -14,6 +14,7 @@ import async_timeout import voluptuous as vol from homeassistant import config_entries +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_DEVICE_ID, CONF_DEVICE, @@ -81,7 +82,7 @@ PLATFORMS = [ ] -async def async_setup_entry(hass, entry: config_entries.ConfigEntry): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the RFXtrx component.""" hass.data.setdefault(DOMAIN, {}) @@ -99,7 +100,7 @@ async def async_setup_entry(hass, entry: config_entries.ConfigEntry): return True -async def async_unload_entry(hass, entry: config_entries.ConfigEntry): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload RFXtrx component.""" if not await hass.config_entries.async_unload_platforms(entry, PLATFORMS): return False diff --git a/homeassistant/components/xiaomi_aqara/__init__.py b/homeassistant/components/xiaomi_aqara/__init__.py index 0ce7b6c4d0f..1857b6e83b2 100644 --- a/homeassistant/components/xiaomi_aqara/__init__.py +++ b/homeassistant/components/xiaomi_aqara/__init__.py @@ -5,8 +5,8 @@ import logging import voluptuous as vol from xiaomi_gateway import XiaomiGateway, XiaomiGatewayDiscovery -from homeassistant import config_entries, core from homeassistant.components import persistent_notification +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_DEVICE_ID, @@ -140,9 +140,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def async_setup_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the xiaomi aqara components from a config entry.""" hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN].setdefault(GATEWAYS_KEY, {}) @@ -202,9 +200,7 @@ async def async_setup_entry( return True -async def async_unload_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" if entry.data[CONF_KEY] is not None: platforms = GATEWAY_PLATFORMS diff --git a/homeassistant/components/xiaomi_miio/__init__.py b/homeassistant/components/xiaomi_miio/__init__.py index ea35d3d785f..63fc3172253 100644 --- a/homeassistant/components/xiaomi_miio/__init__.py +++ b/homeassistant/components/xiaomi_miio/__init__.py @@ -32,9 +32,9 @@ from miio import ( ) from miio.gateway.gateway import GatewayException -from homeassistant import config_entries, core +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_TOKEN, Platform -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -115,9 +115,7 @@ MODEL_TO_CLASS_MAP = { } -async def async_setup_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the Xiaomi Miio components from a config entry.""" hass.data.setdefault(DOMAIN, {}) if entry.data[CONF_FLOW_TYPE] == CONF_GATEWAY: @@ -278,8 +276,8 @@ def _async_update_data_vacuum(hass, device: RoborockVacuum): async def async_create_miio_device_and_coordinator( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): + hass: HomeAssistant, entry: ConfigEntry +) -> None: """Set up a data coordinator and one miio device to service multiple entities.""" model: str = entry.data[CONF_MODEL] host = entry.data[CONF_HOST] @@ -370,9 +368,7 @@ async def async_create_miio_device_and_coordinator( await coordinator.async_config_entry_first_refresh() -async def async_setup_gateway_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_setup_gateway_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: """Set up the Xiaomi Gateway component from a config entry.""" host = entry.data[CONF_HOST] token = entry.data[CONF_TOKEN] @@ -445,9 +441,7 @@ async def async_setup_gateway_entry( ) -async def async_setup_device_entry( - hass: core.HomeAssistant, entry: config_entries.ConfigEntry -): +async def async_setup_device_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the Xiaomi Miio device component from a config entry.""" platforms = get_platforms(entry) await async_create_miio_device_and_coordinator(hass, entry) @@ -462,9 +456,7 @@ async def async_setup_device_entry( return True -async def async_unload_entry( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload a config entry.""" platforms = get_platforms(config_entry) @@ -478,8 +470,6 @@ async def async_unload_entry( return unload_ok -async def update_listener( - hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None: """Handle options update.""" await hass.config_entries.async_reload(config_entry.entry_id) diff --git a/homeassistant/components/zha/__init__.py b/homeassistant/components/zha/__init__.py index 0a80f5014d3..1d5656a1b8d 100644 --- a/homeassistant/components/zha/__init__.py +++ b/homeassistant/components/zha/__init__.py @@ -1,5 +1,4 @@ """Support for Zigbee Home Automation devices.""" - import asyncio import logging @@ -7,7 +6,8 @@ import voluptuous as vol from zhaquirks import setup as setup_quirks from zigpy.config import CONF_DEVICE, CONF_DEVICE_PATH -from homeassistant import config_entries, const as ha_const +from homeassistant import const as ha_const +from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE @@ -83,9 +83,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def async_setup_entry( - hass: HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up ZHA. Will automatically load components to support devices found on the network. @@ -132,9 +130,7 @@ async def async_setup_entry( return True -async def async_unload_entry( - hass: HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload ZHA config entry.""" await hass.data[DATA_ZHA][DATA_ZHA_GATEWAY].shutdown() await hass.data[DATA_ZHA][DATA_ZHA_GATEWAY].async_update_device_storage() @@ -166,9 +162,7 @@ async def async_load_entities(hass: HomeAssistant) -> None: async_dispatcher_send(hass, SIGNAL_ADD_ENTITIES) -async def async_migrate_entry( - hass: HomeAssistant, config_entry: config_entries.ConfigEntry -): +async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Migrate old entry.""" _LOGGER.debug("Migrating from version %s", config_entry.version)