diff --git a/homeassistant/components/habitica/__init__.py b/homeassistant/components/habitica/__init__.py index af67178185d..3cadd6897d2 100644 --- a/homeassistant/components/habitica/__init__.py +++ b/homeassistant/components/habitica/__init__.py @@ -14,7 +14,7 @@ from homeassistant.const import ( CONF_URL, Platform, ) -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.typing import ConfigType @@ -111,7 +111,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: def __call__(self, **kwargs): return super().__call__(websession, **kwargs) - async def handle_api_call(call): + async def handle_api_call(call: ServiceCall) -> None: name = call.data[ATTR_NAME] path = call.data[ATTR_PATH] entries = hass.config_entries.async_entries(DOMAIN) diff --git a/homeassistant/components/hangouts/hangouts_bot.py b/homeassistant/components/hangouts/hangouts_bot.py index 5c0625411ae..c29fd9b2cdf 100644 --- a/homeassistant/components/hangouts/hangouts_bot.py +++ b/homeassistant/components/hangouts/hangouts_bot.py @@ -1,4 +1,6 @@ """The Hangouts Bot.""" +from __future__ import annotations + import asyncio from contextlib import suppress from http import HTTPStatus @@ -9,7 +11,7 @@ import aiohttp import hangups from hangups import ChatMessageEvent, ChatMessageSegment, Client, get_auth, hangouts_pb2 -from homeassistant.core import callback +from homeassistant.core import ServiceCall, callback from homeassistant.helpers import dispatcher, intent from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -326,7 +328,7 @@ class HangoutsBot: self.hass, EVENT_HANGOUTS_CONVERSATIONS_CHANGED, conversations ) - async def async_handle_send_message(self, service): + async def async_handle_send_message(self, service: ServiceCall) -> None: """Handle the send_message service.""" await self._async_send_message( service.data[ATTR_MESSAGE], @@ -334,11 +336,13 @@ class HangoutsBot: service.data.get(ATTR_DATA, {}), ) - async def async_handle_update_users_and_conversations(self, _=None): + async def async_handle_update_users_and_conversations( + self, service: ServiceCall | None = None + ) -> None: """Handle the update_users_and_conversations service.""" await self._async_list_conversations() - async def async_handle_reconnect(self, _=None): + async def async_handle_reconnect(self, service: ServiceCall | None = None) -> None: """Handle the reconnect service.""" await self.async_disconnect() await self.async_connect() diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index 78927d2f322..15d0a885d60 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -25,7 +25,12 @@ from homeassistant.const import ( SERVICE_HOMEASSISTANT_STOP, Platform, ) -from homeassistant.core import DOMAIN as HASS_DOMAIN, HomeAssistant, callback +from homeassistant.core import ( + DOMAIN as HASS_DOMAIN, + HomeAssistant, + ServiceCall, + callback, +) from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, recorder from homeassistant.helpers.device_registry import ( @@ -488,7 +493,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: await push_config(None) - async def async_service_handler(service): + async def async_service_handler(service: ServiceCall) -> None: """Handle service calls for Hass.io.""" api_endpoint = MAP_SERVICE_API[service.service] @@ -566,7 +571,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: # Fetch data await update_info_data(None) - async def async_handle_core_service(call): + async def async_handle_core_service(call: ServiceCall) -> None: """Service handler for handling core services.""" if call.service in SHUTDOWN_SERVICES and recorder.async_migration_in_progress( hass diff --git a/homeassistant/components/heos/services.py b/homeassistant/components/heos/services.py index 68328f3e1a2..9331f786f9d 100644 --- a/homeassistant/components/heos/services.py +++ b/homeassistant/components/heos/services.py @@ -5,7 +5,7 @@ import logging from pyheos import CommandFailedError, Heos, HeosError, const import voluptuous as vol -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from .const import ( @@ -47,7 +47,7 @@ def remove(hass: HomeAssistant): hass.services.async_remove(DOMAIN, SERVICE_SIGN_OUT) -async def _sign_in_handler(controller, service): +async def _sign_in_handler(controller: Heos, service: ServiceCall) -> None: """Sign in to the HEOS account.""" if controller.connection_state != const.STATE_CONNECTED: _LOGGER.error("Unable to sign in because HEOS is not connected") @@ -62,7 +62,7 @@ async def _sign_in_handler(controller, service): _LOGGER.error("Unable to sign in: %s", err) -async def _sign_out_handler(controller, service): +async def _sign_out_handler(controller: Heos, service: ServiceCall) -> None: """Sign out of the HEOS account.""" if controller.connection_state != const.STATE_CONNECTED: _LOGGER.error("Unable to sign out because HEOS is not connected") diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 02232aee1e8..55781fdb1c6 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -37,7 +37,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_STOP, SERVICE_RELOAD, ) -from homeassistant.core import CoreState, HomeAssistant, callback +from homeassistant.core import CoreState, HomeAssistant, ServiceCall, callback from homeassistant.exceptions import HomeAssistantError, Unauthorized from homeassistant.helpers import device_registry, entity_registry import homeassistant.helpers.config_validation as cv @@ -365,7 +365,7 @@ def _async_register_events_and_services(hass: HomeAssistant): """Register events and services for HomeKit.""" hass.http.register_view(HomeKitPairingQRView) - async def async_handle_homekit_reset_accessory(service): + async def async_handle_homekit_reset_accessory(service: ServiceCall) -> None: """Handle reset accessory HomeKit service call.""" for homekit in _async_all_homekit_instances(hass): if homekit.status != STATUS_RUNNING: @@ -385,7 +385,7 @@ def _async_register_events_and_services(hass: HomeAssistant): schema=RESET_ACCESSORY_SERVICE_SCHEMA, ) - async def async_handle_homekit_unpair(service): + async def async_handle_homekit_unpair(service: ServiceCall) -> None: """Handle unpair HomeKit service call.""" referenced = async_extract_referenced_entity_ids(hass, service) dev_reg = device_registry.async_get(hass) diff --git a/homeassistant/components/homematicip_cloud/services.py b/homeassistant/components/homematicip_cloud/services.py index 88c14c648d8..a8393ff88ac 100644 --- a/homeassistant/components/homematicip_cloud/services.py +++ b/homeassistant/components/homematicip_cloud/services.py @@ -114,7 +114,7 @@ async def async_setup_services(hass: HomeAssistant) -> None: return @verify_domain_control(hass, HMIPC_DOMAIN) - async def async_call_hmipc_service(service: ServiceCall): + async def async_call_hmipc_service(service: ServiceCall) -> None: """Call correct HomematicIP Cloud service.""" service_name = service.service diff --git a/homeassistant/components/html5/notify.py b/homeassistant/components/html5/notify.py index 6c3a10757bb..92663bcdf90 100644 --- a/homeassistant/components/html5/notify.py +++ b/homeassistant/components/html5/notify.py @@ -28,6 +28,7 @@ from homeassistant.components.notify import ( BaseNotificationService, ) from homeassistant.const import ATTR_NAME, URL_ROOT +from homeassistant.core import ServiceCall from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv from homeassistant.util import ensure_unique_string @@ -405,7 +406,7 @@ class HTML5NotificationService(BaseNotificationService): self.registrations = registrations self.registrations_json_path = json_path - async def async_dismiss_message(service): + async def async_dismiss_message(service: ServiceCall) -> None: """Handle dismissing notification message service calls.""" kwargs = {} diff --git a/homeassistant/components/hue/services.py b/homeassistant/components/hue/services.py index 6e68bbffbb8..652ec52ebed 100644 --- a/homeassistant/components/hue/services.py +++ b/homeassistant/components/hue/services.py @@ -27,7 +27,7 @@ LOGGER = logging.getLogger(__name__) def async_register_services(hass: HomeAssistant) -> None: """Register services for Hue integration.""" - async def hue_activate_scene(call: ServiceCall, skip_reload=True): + async def hue_activate_scene(call: ServiceCall, skip_reload=True) -> None: """Handle activation of Hue scene.""" # Get parameters group_name = call.data[ATTR_GROUP_NAME] diff --git a/homeassistant/components/icloud/__init__.py b/homeassistant/components/icloud/__init__.py index 7054a0f0ad1..5340ff8a4fb 100644 --- a/homeassistant/components/icloud/__init__.py +++ b/homeassistant/components/icloud/__init__.py @@ -4,9 +4,9 @@ import voluptuous as vol from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_USERNAME -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, ServiceCall import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.typing import ConfigType, ServiceDataType +from homeassistant.helpers.typing import ConfigType from homeassistant.util import slugify from .account import IcloudAccount @@ -134,7 +134,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.config_entries.async_setup_platforms(entry, PLATFORMS) - def play_sound(service: ServiceDataType) -> None: + def play_sound(service: ServiceCall) -> None: """Play sound on the device.""" account = service.data[ATTR_ACCOUNT] device_name = service.data.get(ATTR_DEVICE_NAME) @@ -143,7 +143,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: for device in _get_account(account).get_devices_with_name(device_name): device.play_sound() - def display_message(service: ServiceDataType) -> None: + def display_message(service: ServiceCall) -> None: """Display a message on the device.""" account = service.data[ATTR_ACCOUNT] device_name = service.data.get(ATTR_DEVICE_NAME) @@ -154,7 +154,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: for device in _get_account(account).get_devices_with_name(device_name): device.display_message(message, sound) - def lost_device(service: ServiceDataType) -> None: + def lost_device(service: ServiceCall) -> None: """Make the device in lost state.""" account = service.data[ATTR_ACCOUNT] device_name = service.data.get(ATTR_DEVICE_NAME) @@ -165,7 +165,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: for device in _get_account(account).get_devices_with_name(device_name): device.lost_device(number, message) - def update_account(service: ServiceDataType) -> None: + def update_account(service: ServiceCall) -> None: """Call the update function of an iCloud account.""" if (account := service.data.get(ATTR_ACCOUNT)) is None: for account in hass.data[DOMAIN].values(): diff --git a/homeassistant/components/ifttt/__init__.py b/homeassistant/components/ifttt/__init__.py index 68d8159b6e4..a9c682d40ad 100644 --- a/homeassistant/components/ifttt/__init__.py +++ b/homeassistant/components/ifttt/__init__.py @@ -8,6 +8,7 @@ import requests import voluptuous as vol from homeassistant.const import CONF_WEBHOOK_ID +from homeassistant.core import ServiceCall from homeassistant.helpers import config_entry_flow import homeassistant.helpers.config_validation as cv @@ -57,7 +58,7 @@ async def async_setup(hass, config): if isinstance(api_keys, str): api_keys = {"default": api_keys} - def trigger_service(call): + def trigger_service(call: ServiceCall) -> None: """Handle IFTTT trigger service calls.""" event = call.data[ATTR_EVENT] targets = call.data.get(ATTR_TARGET, list(api_keys)) diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index 5c09e0b0bc7..b2f9e339757 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -13,7 +13,7 @@ from homeassistant.const import ( CONF_NAME, CONF_SOURCE, ) -from homeassistant.core import callback +from homeassistant.core import ServiceCall, callback from homeassistant.exceptions import HomeAssistantError import homeassistant.helpers.config_validation as cv from homeassistant.helpers.config_validation import make_entity_service_schema @@ -75,7 +75,7 @@ async def async_setup(hass, config): await component.async_setup(config) - async def async_scan_service(service): + async def async_scan_service(service: ServiceCall) -> None: """Service handler for scan.""" image_entities = await component.async_extract_from_service(service) diff --git a/homeassistant/components/insteon/utils.py b/homeassistant/components/insteon/utils.py index ace24644523..1599975f462 100644 --- a/homeassistant/components/insteon/utils.py +++ b/homeassistant/components/insteon/utils.py @@ -27,7 +27,7 @@ from homeassistant.const import ( CONF_PLATFORM, ENTITY_MATCH_ALL, ) -from homeassistant.core import callback +from homeassistant.core import ServiceCall, callback from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, @@ -166,19 +166,19 @@ def async_register_services(hass): save_lock = asyncio.Lock() - async def async_srv_add_all_link(service): + async def async_srv_add_all_link(service: ServiceCall) -> None: """Add an INSTEON All-Link between two devices.""" - group = service.data.get(SRV_ALL_LINK_GROUP) - mode = service.data.get(SRV_ALL_LINK_MODE) + group = service.data[SRV_ALL_LINK_GROUP] + mode = service.data[SRV_ALL_LINK_MODE] link_mode = mode.lower() == SRV_CONTROLLER await async_enter_linking_mode(link_mode, group) - async def async_srv_del_all_link(service): + async def async_srv_del_all_link(service: ServiceCall) -> None: """Delete an INSTEON All-Link between two devices.""" group = service.data.get(SRV_ALL_LINK_GROUP) await async_enter_unlinking_mode(group) - async def async_srv_load_aldb(service): + async def async_srv_load_aldb(service: ServiceCall) -> None: """Load the device All-Link database.""" entity_id = service.data[CONF_ENTITY_ID] reload = service.data[SRV_LOAD_DB_RELOAD] @@ -204,7 +204,7 @@ def async_register_services(hass): _LOGGER.debug("Saving Insteon devices") await devices.async_save(hass.config.config_dir) - def print_aldb(service): + def print_aldb(service: ServiceCall) -> None: """Print the All-Link Database for a device.""" # For now this sends logs to the log file. # Future direction is to create an INSTEON control panel. @@ -212,39 +212,39 @@ def async_register_services(hass): signal = f"{entity_id}_{SIGNAL_PRINT_ALDB}" dispatcher_send(hass, signal) - def print_im_aldb(service): + def print_im_aldb(service: ServiceCall) -> None: """Print the All-Link Database for a device.""" # For now this sends logs to the log file. # Future direction is to create an INSTEON control panel. print_aldb_to_log(devices.modem.aldb) - async def async_srv_x10_all_units_off(service): + async def async_srv_x10_all_units_off(service: ServiceCall) -> None: """Send the X10 All Units Off command.""" housecode = service.data.get(SRV_HOUSECODE) await async_x10_all_units_off(housecode) - async def async_srv_x10_all_lights_off(service): + async def async_srv_x10_all_lights_off(service: ServiceCall) -> None: """Send the X10 All Lights Off command.""" housecode = service.data.get(SRV_HOUSECODE) await async_x10_all_lights_off(housecode) - async def async_srv_x10_all_lights_on(service): + async def async_srv_x10_all_lights_on(service: ServiceCall) -> None: """Send the X10 All Lights On command.""" housecode = service.data.get(SRV_HOUSECODE) await async_x10_all_lights_on(housecode) - async def async_srv_scene_on(service): + async def async_srv_scene_on(service: ServiceCall) -> None: """Trigger an INSTEON scene ON.""" group = service.data.get(SRV_ALL_LINK_GROUP) await async_trigger_scene_on(group) - async def async_srv_scene_off(service): + async def async_srv_scene_off(service: ServiceCall) -> None: """Trigger an INSTEON scene ON.""" group = service.data.get(SRV_ALL_LINK_GROUP) await async_trigger_scene_off(group) @callback - def async_add_default_links(service): + def async_add_default_links(service: ServiceCall) -> None: """Add the default All-Link entries to a device.""" entity_id = service.data[CONF_ENTITY_ID] signal = f"{entity_id}_{SIGNAL_ADD_DEFAULT_LINKS}" diff --git a/homeassistant/components/iperf3/__init__.py b/homeassistant/components/iperf3/__init__.py index 04dabc013e7..14b1b37c005 100644 --- a/homeassistant/components/iperf3/__init__.py +++ b/homeassistant/components/iperf3/__init__.py @@ -20,6 +20,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, DATA_RATE_MEGABITS_PER_SECOND, ) +from homeassistant.core import ServiceCall import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.dispatcher import dispatcher_send @@ -103,7 +104,7 @@ async def async_setup(hass, config): if not conf[CONF_MANUAL]: async_track_time_interval(hass, data.update, conf[CONF_SCAN_INTERVAL]) - def update(call): + def update(call: ServiceCall) -> None: """Service call to manually update the data.""" called_host = call.data[ATTR_HOST] if called_host in hass.data[DOMAIN]: diff --git a/homeassistant/components/isy994/services.py b/homeassistant/components/isy994/services.py index 5b18d6cd33a..a1dff594a1f 100644 --- a/homeassistant/components/isy994/services.py +++ b/homeassistant/components/isy994/services.py @@ -182,7 +182,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 # Integration-level services have already been added. Return. return - async def async_system_query_service_handler(service): + async def async_system_query_service_handler(service: ServiceCall) -> None: """Handle a system query service call.""" address = service.data.get(CONF_ADDRESS) isy_name = service.data.get(CONF_ISY) @@ -206,7 +206,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 ) await isy.query() - async def async_run_network_resource_service_handler(service): + async def async_run_network_resource_service_handler(service: ServiceCall) -> None: """Handle a network resource service call.""" address = service.data.get(CONF_ADDRESS) name = service.data.get(CONF_NAME) @@ -230,7 +230,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 "Could not run network resource command; not found or enabled on the ISY" ) - async def async_send_program_command_service_handler(service): + async def async_send_program_command_service_handler(service: ServiceCall) -> None: """Handle a send program command service call.""" address = service.data.get(CONF_ADDRESS) name = service.data.get(CONF_NAME) @@ -251,7 +251,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 return _LOGGER.error("Could not send program command; not found or enabled on the ISY") - async def async_set_variable_service_handler(service): + async def async_set_variable_service_handler(service: ServiceCall) -> None: """Handle a set variable service call.""" address = service.data.get(CONF_ADDRESS) vtype = service.data.get(CONF_TYPE) @@ -275,7 +275,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 _LOGGER.error("Could not set variable value; not found or enabled on the ISY") @callback - def async_cleanup_registry_entries(service) -> None: + def async_cleanup_registry_entries(service: ServiceCall) -> None: """Remove extra entities that are no longer part of the integration.""" entity_registry = er.async_get(hass) config_ids = [] @@ -327,7 +327,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 len(extra_entities), ) - async def async_reload_config_entries(service) -> None: + async def async_reload_config_entries(service: ServiceCall) -> None: """Trigger a reload of all ISY994 config entries.""" for config_entry_id in hass.data[DOMAIN]: hass.async_create_task(hass.config_entries.async_reload(config_entry_id)) @@ -370,7 +370,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 domain=DOMAIN, service=SERVICE_RELOAD, service_func=async_reload_config_entries ) - async def _async_send_raw_node_command(call: ServiceCall): + async def _async_send_raw_node_command(call: ServiceCall) -> None: await hass.helpers.service.entity_service_call( async_get_platforms(hass, DOMAIN), "async_send_raw_node_command", call ) @@ -382,7 +382,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 service_func=_async_send_raw_node_command, ) - async def _async_send_node_command(call: ServiceCall): + async def _async_send_node_command(call: ServiceCall) -> None: await hass.helpers.service.entity_service_call( async_get_platforms(hass, DOMAIN), "async_send_node_command", call ) @@ -394,7 +394,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 service_func=_async_send_node_command, ) - async def _async_get_zwave_parameter(call: ServiceCall): + async def _async_get_zwave_parameter(call: ServiceCall) -> None: await hass.helpers.service.entity_service_call( async_get_platforms(hass, DOMAIN), "async_get_zwave_parameter", call ) @@ -406,7 +406,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 service_func=_async_get_zwave_parameter, ) - async def _async_set_zwave_parameter(call: ServiceCall): + async def _async_set_zwave_parameter(call: ServiceCall) -> None: await hass.helpers.service.entity_service_call( async_get_platforms(hass, DOMAIN), "async_set_zwave_parameter", call ) @@ -418,7 +418,7 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 service_func=_async_set_zwave_parameter, ) - async def _async_rename_node(call: ServiceCall): + async def _async_rename_node(call: ServiceCall) -> None: await hass.helpers.service.entity_service_call( async_get_platforms(hass, DOMAIN), "async_rename_node", call )