From 656d383ba6a59e76b4605fa4fc2a444ee10d995f Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 28 Dec 2021 14:23:01 +0100 Subject: [PATCH] Ensure service calls are typed [e-g] (#62912) Co-authored-by: epenet --- homeassistant/components/ecobee/climate.py | 9 +++++---- homeassistant/components/elkm1/__init__.py | 8 ++++---- homeassistant/components/envisalink/__init__.py | 4 ++-- .../components/envisalink/alarm_control_panel.py | 8 ++++---- homeassistant/components/evohome/__init__.py | 8 ++++---- homeassistant/components/ffmpeg/__init__.py | 4 ++-- homeassistant/components/flux/switch.py | 5 ++++- homeassistant/components/freebox/__init__.py | 4 ++-- homeassistant/components/geniushub/__init__.py | 4 ++-- .../components/google_assistant/__init__.py | 2 +- homeassistant/components/group/__init__.py | 14 ++++++++++---- 11 files changed, 40 insertions(+), 30 deletions(-) diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index 473ba0cdd58..fa3a00e1175 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -37,6 +37,7 @@ from homeassistant.const import ( STATE_ON, TEMP_FAHRENHEIT, ) +from homeassistant.core import ServiceCall from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import DeviceInfo @@ -198,7 +199,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): platform = entity_platform.async_get_current_platform() - def create_vacation_service(service): + def create_vacation_service(service: ServiceCall) -> None: """Create a vacation on the target thermostat.""" entity_id = service.data[ATTR_ENTITY_ID] @@ -208,7 +209,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): thermostat.schedule_update_ha_state(True) break - def delete_vacation_service(service): + def delete_vacation_service(service: ServiceCall) -> None: """Delete a vacation on the target thermostat.""" entity_id = service.data[ATTR_ENTITY_ID] vacation_name = service.data[ATTR_VACATION_NAME] @@ -219,7 +220,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): thermostat.schedule_update_ha_state(True) break - def fan_min_on_time_set_service(service): + def fan_min_on_time_set_service(service: ServiceCall) -> None: """Set the minimum fan on time on the target thermostats.""" entity_id = service.data.get(ATTR_ENTITY_ID) fan_min_on_time = service.data[ATTR_FAN_MIN_ON_TIME] @@ -236,7 +237,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): thermostat.schedule_update_ha_state(True) - def resume_program_set_service(service): + def resume_program_set_service(service: ServiceCall) -> None: """Resume the program on the target thermostats.""" entity_id = service.data.get(ATTR_ENTITY_ID) resume_all = service.data.get(ATTR_RESUME_ALL) diff --git a/homeassistant/components/elkm1/__init__.py b/homeassistant/components/elkm1/__init__.py index 8714a41a9a7..6f586423552 100644 --- a/homeassistant/components/elkm1/__init__.py +++ b/homeassistant/components/elkm1/__init__.py @@ -24,7 +24,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, Platform, ) -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import DeviceInfo, Entity @@ -342,13 +342,13 @@ def _create_elk_services(hass): raise HomeAssistantError(f"No ElkM1 with prefix '{prefix}' found") return elk - def _speak_word_service(service): + def _speak_word_service(service: ServiceCall) -> None: _getelk(service).panel.speak_word(service.data["number"]) - def _speak_phrase_service(service): + def _speak_phrase_service(service: ServiceCall) -> None: _getelk(service).panel.speak_phrase(service.data["number"]) - def _set_time_service(service): + def _set_time_service(service: ServiceCall) -> None: _getelk(service).panel.set_time(dt_util.now()) hass.services.async_register( diff --git a/homeassistant/components/envisalink/__init__.py b/homeassistant/components/envisalink/__init__.py index d5a8b39e8f9..433f515469f 100644 --- a/homeassistant/components/envisalink/__init__.py +++ b/homeassistant/components/envisalink/__init__.py @@ -11,7 +11,7 @@ from homeassistant.const import ( CONF_TIMEOUT, EVENT_HOMEASSISTANT_STOP, ) -from homeassistant.core import callback +from homeassistant.core import ServiceCall, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -181,7 +181,7 @@ async def async_setup(hass, config): _LOGGER.info("Shutting down Envisalink") controller.stop() - async def handle_custom_function(call): + async def handle_custom_function(call: ServiceCall) -> None: """Handle custom/PGM service.""" custom_function = call.data.get(ATTR_CUSTOM_FUNCTION) partition = call.data.get(ATTR_PARTITION) diff --git a/homeassistant/components/envisalink/alarm_control_panel.py b/homeassistant/components/envisalink/alarm_control_panel.py index dff434a68ee..d93e980064d 100644 --- a/homeassistant/components/envisalink/alarm_control_panel.py +++ b/homeassistant/components/envisalink/alarm_control_panel.py @@ -24,7 +24,7 @@ from homeassistant.const import ( STATE_ALARM_TRIGGERED, STATE_UNKNOWN, ) -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 @@ -74,10 +74,10 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities(devices) @callback - def alarm_keypress_handler(service): + def alarm_keypress_handler(service: ServiceCall) -> None: """Map services to methods on Alarm.""" - entity_ids = service.data.get(ATTR_ENTITY_ID) - keypress = service.data.get(ATTR_KEYPRESS) + entity_ids = service.data[ATTR_ENTITY_ID] + keypress = service.data[ATTR_KEYPRESS] target_devices = [ device for device in devices if device.entity_id in entity_ids diff --git a/homeassistant/components/evohome/__init__.py b/homeassistant/components/evohome/__init__.py index d7b1407642d..fa394079e2f 100644 --- a/homeassistant/components/evohome/__init__.py +++ b/homeassistant/components/evohome/__init__.py @@ -22,7 +22,7 @@ from homeassistant.const import ( CONF_USERNAME, TEMP_CELSIUS, ) -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import async_load_platform @@ -274,12 +274,12 @@ def setup_service_functions(hass: HomeAssistant, broker): """ @verify_domain_control(hass, DOMAIN) - async def force_refresh(call) -> None: + async def force_refresh(call: ServiceCall) -> None: """Obtain the latest state data via the vendor's RESTful API.""" await broker.async_update() @verify_domain_control(hass, DOMAIN) - async def set_system_mode(call) -> None: + async def set_system_mode(call: ServiceCall) -> None: """Set the system mode.""" payload = { "unique_id": broker.tcs.systemId, @@ -289,7 +289,7 @@ def setup_service_functions(hass: HomeAssistant, broker): async_dispatcher_send(hass, DOMAIN, payload) @verify_domain_control(hass, DOMAIN) - async def set_zone_override(call) -> None: + async def set_zone_override(call: ServiceCall) -> None: """Set the zone override (setpoint).""" entity_id = call.data[ATTR_ENTITY_ID] diff --git a/homeassistant/components/ffmpeg/__init__.py b/homeassistant/components/ffmpeg/__init__.py index 7da1bc572f5..31650598371 100644 --- a/homeassistant/components/ffmpeg/__init__.py +++ b/homeassistant/components/ffmpeg/__init__.py @@ -13,7 +13,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, ) -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import HomeAssistant, ServiceCall, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, @@ -64,7 +64,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await manager.async_get_version() # Register service - async def async_service_handle(service): + async def async_service_handle(service: ServiceCall) -> None: """Handle service ffmpeg process.""" entity_ids = service.data.get(ATTR_ENTITY_ID) diff --git a/homeassistant/components/flux/switch.py b/homeassistant/components/flux/switch.py index ab0d296928f..2a6801d8966 100644 --- a/homeassistant/components/flux/switch.py +++ b/homeassistant/components/flux/switch.py @@ -3,6 +3,8 @@ Flux for Home-Assistant. The idea was taken from https://github.com/KpaBap/hue-flux/ """ +from __future__ import annotations + import datetime import logging @@ -32,6 +34,7 @@ from homeassistant.const import ( SUN_EVENT_SUNRISE, SUN_EVENT_SUNSET, ) +from homeassistant.core import ServiceCall from homeassistant.helpers import config_validation as cv, event from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.sun import get_astral_event_date @@ -159,7 +162,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) async_add_entities([flux]) - async def async_update(call=None): + async def async_update(call: ServiceCall | None = None) -> None: """Update lights.""" await flux.async_flux_update() diff --git a/homeassistant/components/freebox/__init__.py b/homeassistant/components/freebox/__init__.py index c343e8d629c..565d43b2a41 100644 --- a/homeassistant/components/freebox/__init__.py +++ b/homeassistant/components/freebox/__init__.py @@ -5,7 +5,7 @@ import voluptuous as vol from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from .const import DOMAIN, PLATFORMS, SERVICE_REBOOT @@ -50,7 +50,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.config_entries.async_setup_platforms(entry, PLATFORMS) # Services - async def async_reboot(call): + async def async_reboot(call: ServiceCall) -> None: """Handle reboot service call.""" await router.reboot() diff --git a/homeassistant/components/geniushub/__init__.py b/homeassistant/components/geniushub/__init__.py index cad80e8d707..72a759427f5 100644 --- a/homeassistant/components/geniushub/__init__.py +++ b/homeassistant/components/geniushub/__init__.py @@ -19,7 +19,7 @@ from homeassistant.const import ( CONF_USERNAME, TEMP_CELSIUS, ) -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.discovery import async_load_platform @@ -133,7 +133,7 @@ def setup_service_functions(hass: HomeAssistant, broker): """Set up the service functions.""" @verify_domain_control(hass, DOMAIN) - async def set_zone_mode(call) -> None: + async def set_zone_mode(call: ServiceCall) -> None: """Set the system mode.""" entity_id = call.data[ATTR_ENTITY_ID] diff --git a/homeassistant/components/google_assistant/__init__.py b/homeassistant/components/google_assistant/__init__.py index 1e0c0a06114..dca436d8e2a 100644 --- a/homeassistant/components/google_assistant/__init__.py +++ b/homeassistant/components/google_assistant/__init__.py @@ -105,7 +105,7 @@ async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool: if google_config.should_report_state: google_config.async_enable_report_state() - async def request_sync_service_handler(call: ServiceCall): + async def request_sync_service_handler(call: ServiceCall) -> None: """Handle request sync service calls.""" agent_user_id = call.data.get("agent_user_id") or call.context.user_id diff --git a/homeassistant/components/group/__init__.py b/homeassistant/components/group/__init__.py index e3816d52d60..a609009fe80 100644 --- a/homeassistant/components/group/__init__.py +++ b/homeassistant/components/group/__init__.py @@ -26,7 +26,13 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, ) -from homeassistant.core import CoreState, HomeAssistant, callback, split_entity_id +from homeassistant.core import ( + CoreState, + HomeAssistant, + ServiceCall, + callback, + split_entity_id, +) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity, async_generate_entity_id from homeassistant.helpers.entity_component import EntityComponent @@ -220,7 +226,7 @@ async def async_setup(hass, config): await _async_process_config(hass, config, component) - async def reload_service_handler(service): + async def reload_service_handler(service: ServiceCall) -> None: """Remove all user-defined groups and load new ones from config.""" auto = list(filter(lambda e: not e.user_defined, component.entities)) @@ -238,12 +244,12 @@ async def async_setup(hass, config): service_lock = asyncio.Lock() - async def locked_service_handler(service): + async def locked_service_handler(service: ServiceCall) -> None: """Handle a service with an async lock.""" async with service_lock: await groups_service_handler(service) - async def groups_service_handler(service): + async def groups_service_handler(service: ServiceCall) -> None: """Handle dynamic group service functions.""" object_id = service.data[ATTR_OBJECT_ID] entity_id = f"{DOMAIN}.{object_id}"