From 803eaa8e222be297f9a6a3211c92b6d9a06ab1a4 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 30 Dec 2021 21:12:40 +0100 Subject: [PATCH] Ensure admin service calls are typed (#63093) Co-authored-by: epenet --- .../components/cast/home_assistant_cast.py | 2 +- homeassistant/components/cloud/__init__.py | 4 ++-- .../components/homeassistant/__init__.py | 8 ++++---- homeassistant/components/homekit/__init__.py | 2 +- homeassistant/components/person/__init__.py | 2 +- homeassistant/components/profiler/__init__.py | 10 +++++----- homeassistant/components/template/__init__.py | 4 ++-- homeassistant/components/zha/api.py | 16 ++++++++-------- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/cast/home_assistant_cast.py b/homeassistant/components/cast/home_assistant_cast.py index e4b72f0bf40..417809e4894 100644 --- a/homeassistant/components/cast/home_assistant_cast.py +++ b/homeassistant/components/cast/home_assistant_cast.py @@ -39,7 +39,7 @@ async def async_setup_ha_cast( else: refresh_token = await hass.auth.async_create_refresh_token(user) - async def handle_show_view(call: core.ServiceCall): + async def handle_show_view(call: core.ServiceCall) -> None: """Handle a Show View service call.""" hass_url = get_url(hass, require_ssl=True, prefer_external=True) diff --git a/homeassistant/components/cloud/__init__.py b/homeassistant/components/cloud/__init__.py index f99ac4c7b0a..55c0a86c75c 100644 --- a/homeassistant/components/cloud/__init__.py +++ b/homeassistant/components/cloud/__init__.py @@ -13,7 +13,7 @@ from homeassistant.const import ( CONF_REGION, EVENT_HOMEASSISTANT_STOP, ) -from homeassistant.core import callback +from homeassistant.core import ServiceCall, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, entityfilter from homeassistant.loader import bind_hass @@ -197,7 +197,7 @@ async def async_setup(hass, config): _remote_handle_prefs_updated(cloud) - async def _service_handler(service): + async def _service_handler(service: ServiceCall) -> None: """Handle service for cloud.""" if service.service == SERVICE_REMOTE_CONNECT: await prefs.async_update(remote_enabled=True) diff --git a/homeassistant/components/homeassistant/__init__.py b/homeassistant/components/homeassistant/__init__.py index a1d3880777e..5747fe4463e 100644 --- a/homeassistant/components/homeassistant/__init__.py +++ b/homeassistant/components/homeassistant/__init__.py @@ -136,7 +136,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no ha.DOMAIN, SERVICE_TOGGLE, async_handle_turn_service, schema=service_schema ) - async def async_handle_core_service(call): + async def async_handle_core_service(call: ha.ServiceCall) -> None: """Service handler for handling core services.""" if call.service in SHUTDOWN_SERVICES and recorder.async_migration_in_progress( hass @@ -220,7 +220,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no schema=SCHEMA_UPDATE_ENTITY, ) - async def async_handle_reload_config(call): + async def async_handle_reload_config(call: ha.ServiceCall) -> None: """Service handler for reloading core config.""" try: conf = await conf_util.async_hass_config_yaml(hass) @@ -235,7 +235,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no ha.DOMAIN, SERVICE_RELOAD_CORE_CONFIG, async_handle_reload_config ) - async def async_set_location(call): + async def async_set_location(call: ha.ServiceCall) -> None: """Service handler to set location.""" await hass.config.async_update( latitude=call.data[ATTR_LATITUDE], longitude=call.data[ATTR_LONGITUDE] @@ -248,7 +248,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no vol.Schema({ATTR_LATITUDE: cv.latitude, ATTR_LONGITUDE: cv.longitude}), ) - async def async_handle_reload_config_entry(call): + async def async_handle_reload_config_entry(call: ha.ServiceCall) -> None: """Service handler for reloading a config entry.""" reload_entries = set() if ATTR_ENTRY_ID in call.data: diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 55781fdb1c6..00f5e82432d 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -417,7 +417,7 @@ def _async_register_events_and_services(hass: HomeAssistant): schema=UNPAIR_SERVICE_SCHEMA, ) - async def _handle_homekit_reload(service): + async def _handle_homekit_reload(service: ServiceCall) -> None: """Handle start HomeKit service call.""" config = await async_integration_yaml_config(hass, DOMAIN) diff --git a/homeassistant/components/person/__init__.py b/homeassistant/components/person/__init__.py index 3ec08ae518e..98351951505 100644 --- a/homeassistant/components/person/__init__.py +++ b/homeassistant/components/person/__init__.py @@ -336,7 +336,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.bus.async_listen(EVENT_USER_REMOVED, _handle_user_removed) - async def async_reload_yaml(call: ServiceCall): + async def async_reload_yaml(call: ServiceCall) -> None: """Reload YAML.""" conf = await entity_component.async_prepare_reload(skip_reset=True) if conf is None: diff --git a/homeassistant/components/profiler/__init__.py b/homeassistant/components/profiler/__init__.py index e2d44451ec2..a8f5a2d8d1d 100644 --- a/homeassistant/components/profiler/__init__.py +++ b/homeassistant/components/profiler/__init__.py @@ -56,15 +56,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: lock = asyncio.Lock() domain_data = hass.data[DOMAIN] = {} - async def _async_run_profile(call: ServiceCall): + async def _async_run_profile(call: ServiceCall) -> None: async with lock: await _async_generate_profile(hass, call) - async def _async_run_memory_profile(call: ServiceCall): + async def _async_run_memory_profile(call: ServiceCall) -> None: async with lock: await _async_generate_memory_profile(hass, call) - async def _async_start_log_objects(call: ServiceCall): + async def _async_start_log_objects(call: ServiceCall) -> None: if LOG_INTERVAL_SUB in domain_data: domain_data[LOG_INTERVAL_SUB]() @@ -78,14 +78,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass, _log_objects, call.data[CONF_SCAN_INTERVAL] ) - async def _async_stop_log_objects(call: ServiceCall): + async def _async_stop_log_objects(call: ServiceCall) -> None: if LOG_INTERVAL_SUB not in domain_data: return hass.components.persistent_notification.async_dismiss("profile_object_logging") domain_data.pop(LOG_INTERVAL_SUB)() - def _dump_log_objects(call: ServiceCall): + def _dump_log_objects(call: ServiceCall) -> None: obj_type = call.data[CONF_TYPE] _LOGGER.critical( diff --git a/homeassistant/components/template/__init__.py b/homeassistant/components/template/__init__.py index 9a0fa5a7320..329c03063e5 100644 --- a/homeassistant/components/template/__init__.py +++ b/homeassistant/components/template/__init__.py @@ -11,7 +11,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, SERVICE_RELOAD, ) -from homeassistant.core import CoreState, Event, callback +from homeassistant.core import CoreState, Event, ServiceCall, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import ( discovery, @@ -31,7 +31,7 @@ async def async_setup(hass, config): if DOMAIN in config: await _process_config(hass, config) - async def _reload_config(call: Event) -> None: + async def _reload_config(call: Event | ServiceCall) -> None: """Reload top-level + platforms.""" try: unprocessed_conf = await conf_util.async_hass_config_yaml(hass) diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index 48e70c86c1f..86dad9d6bd0 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -14,7 +14,7 @@ import zigpy.zdo.types as zdo_types from homeassistant.components import websocket_api from homeassistant.const import ATTR_COMMAND, ATTR_NAME -from homeassistant.core import callback +from homeassistant.core import ServiceCall, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -945,7 +945,7 @@ def async_load_api(hass): zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] application_controller = zha_gateway.application_controller - async def permit(service): + async def permit(service: ServiceCall) -> None: """Allow devices to join this network.""" duration = service.data[ATTR_DURATION] ieee = service.data.get(ATTR_IEEE) @@ -976,7 +976,7 @@ def async_load_api(hass): DOMAIN, SERVICE_PERMIT, permit, schema=SERVICE_SCHEMAS[SERVICE_PERMIT] ) - async def remove(service): + async def remove(service: ServiceCall) -> None: """Remove a node from the network.""" ieee = service.data[ATTR_IEEE] zha_gateway: ZhaGatewayType = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] @@ -994,7 +994,7 @@ def async_load_api(hass): DOMAIN, SERVICE_REMOVE, remove, schema=SERVICE_SCHEMAS[IEEE_SERVICE] ) - async def set_zigbee_cluster_attributes(service): + async def set_zigbee_cluster_attributes(service: ServiceCall) -> None: """Set zigbee attribute for cluster on zha entity.""" ieee = service.data.get(ATTR_IEEE) endpoint_id = service.data.get(ATTR_ENDPOINT_ID) @@ -1041,7 +1041,7 @@ def async_load_api(hass): schema=SERVICE_SCHEMAS[SERVICE_SET_ZIGBEE_CLUSTER_ATTRIBUTE], ) - async def issue_zigbee_cluster_command(service): + async def issue_zigbee_cluster_command(service: ServiceCall) -> None: """Issue command on zigbee cluster on zha entity.""" ieee = service.data.get(ATTR_IEEE) endpoint_id = service.data.get(ATTR_ENDPOINT_ID) @@ -1092,7 +1092,7 @@ def async_load_api(hass): schema=SERVICE_SCHEMAS[SERVICE_ISSUE_ZIGBEE_CLUSTER_COMMAND], ) - async def issue_zigbee_group_command(service): + async def issue_zigbee_group_command(service: ServiceCall) -> None: """Issue command on zigbee cluster on a zigbee group.""" group_id = service.data.get(ATTR_GROUP) cluster_id = service.data.get(ATTR_CLUSTER_ID) @@ -1138,7 +1138,7 @@ def async_load_api(hass): } return cluster_channels.get(CHANNEL_IAS_WD) - async def warning_device_squawk(service): + async def warning_device_squawk(service: ServiceCall) -> None: """Issue the squawk command for an IAS warning device.""" ieee = service.data[ATTR_IEEE] mode = service.data.get(ATTR_WARNING_DEVICE_MODE) @@ -1177,7 +1177,7 @@ def async_load_api(hass): schema=SERVICE_SCHEMAS[SERVICE_WARNING_DEVICE_SQUAWK], ) - async def warning_device_warn(service): + async def warning_device_warn(service: ServiceCall) -> None: """Issue the warning command for an IAS warning device.""" ieee = service.data[ATTR_IEEE] mode = service.data.get(ATTR_WARNING_DEVICE_MODE)