From 05ac2d4c3ab9675a4ff4ee7c84be8f82b7724fe9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 28 Dec 2021 13:12:06 +0100 Subject: [PATCH] Ensure service calls are typed [v-z] (#62923) Co-authored-by: epenet --- homeassistant/components/velux/__init__.py | 4 ++-- homeassistant/components/vesync/__init__.py | 3 ++- homeassistant/components/wake_on_lan/__init__.py | 4 ++-- homeassistant/components/webostv/__init__.py | 5 +++-- homeassistant/components/zwave/__init__.py | 6 ++++-- homeassistant/components/zwave/lock.py | 8 ++++---- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/velux/__init__.py b/homeassistant/components/velux/__init__.py index 6783c71b3cd..e763a7003d5 100644 --- a/homeassistant/components/velux/__init__.py +++ b/homeassistant/components/velux/__init__.py @@ -5,7 +5,7 @@ from pyvlx import PyVLX, PyVLXException import voluptuous as vol from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP -from homeassistant.core import callback +from homeassistant.core import ServiceCall, callback from homeassistant.helpers import discovery import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -60,7 +60,7 @@ class VeluxModule: _LOGGER.debug("Velux interface terminated") await self.pyvlx.disconnect() - async def async_reboot_gateway(service_call): + async def async_reboot_gateway(service_call: ServiceCall) -> None: await self.pyvlx.reboot_gateway() self._hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop) diff --git a/homeassistant/components/vesync/__init__.py b/homeassistant/components/vesync/__init__.py index e62436fce27..41de93da092 100644 --- a/homeassistant/components/vesync/__init__.py +++ b/homeassistant/components/vesync/__init__.py @@ -4,6 +4,7 @@ import logging from pyvesync import VeSync from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform +from homeassistant.core import ServiceCall from homeassistant.helpers import config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -66,7 +67,7 @@ async def async_setup_entry(hass, config_entry): lights.extend(device_dict[VS_LIGHTS]) hass.async_create_task(forward_setup(config_entry, Platform.LIGHT)) - async def async_new_device_discovery(service): + async def async_new_device_discovery(service: ServiceCall) -> None: """Discover if new devices should be added.""" manager = hass.data[DOMAIN][VS_MANAGER] switches = hass.data[DOMAIN][VS_SWITCHES] diff --git a/homeassistant/components/wake_on_lan/__init__.py b/homeassistant/components/wake_on_lan/__init__.py index e788f6c0124..aae640381a2 100644 --- a/homeassistant/components/wake_on_lan/__init__.py +++ b/homeassistant/components/wake_on_lan/__init__.py @@ -6,7 +6,7 @@ import voluptuous as vol import wakeonlan from homeassistant.const import CONF_BROADCAST_ADDRESS, CONF_BROADCAST_PORT, CONF_MAC -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, ServiceCall import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import ConfigType @@ -28,7 +28,7 @@ WAKE_ON_LAN_SEND_MAGIC_PACKET_SCHEMA = vol.Schema( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the wake on LAN component.""" - async def send_magic_packet(call): + async def send_magic_packet(call: ServiceCall) -> None: """Send magic packet to wake up a device.""" mac_address = call.data.get(CONF_MAC) broadcast_address = call.data.get(CONF_BROADCAST_ADDRESS) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index db5a618ff5c..3675e33bf39 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -19,6 +19,7 @@ from homeassistant.const import ( CONF_NAME, EVENT_HOMEASSISTANT_STOP, ) +from homeassistant.core import ServiceCall import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -86,8 +87,8 @@ async def async_setup(hass, config): """Set up the LG WebOS TV platform.""" hass.data[DOMAIN] = {} - async def async_service_handler(service): - method = SERVICE_TO_METHOD.get(service.service) + async def async_service_handler(service: ServiceCall) -> None: + method = SERVICE_TO_METHOD[service.service] data = service.data.copy() data["method"] = method["method"] async_dispatcher_send(hass, DOMAIN, data) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index cd15f632d0b..99548eff53e 100644 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -1,5 +1,7 @@ """Support for Z-Wave.""" # pylint: disable=import-outside-toplevel +from __future__ import annotations + import asyncio import copy from importlib import import_module @@ -17,7 +19,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_STOP, Platform, ) -from homeassistant.core import CoreState, HomeAssistant, callback +from homeassistant.core import CoreState, Event, HomeAssistant, ServiceCall, callback from homeassistant.helpers import discovery import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import ( @@ -876,7 +878,7 @@ async def async_setup_entry( # noqa: C901 _LOGGER.info("Sending %s test-messages to node %s", messages, node_id) node.test(messages) - def start_zwave(_service_or_event): + def start_zwave(_service_or_event: ServiceCall | Event) -> None: """Startup Z-Wave network.""" _LOGGER.info("Starting Z-Wave network") network.start() diff --git a/homeassistant/components/zwave/lock.py b/homeassistant/components/zwave/lock.py index bc49f9c0bd2..81e7c066b5d 100644 --- a/homeassistant/components/zwave/lock.py +++ b/homeassistant/components/zwave/lock.py @@ -4,7 +4,7 @@ import logging import voluptuous as vol from homeassistant.components.lock import DOMAIN, LockEntity -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 @@ -169,7 +169,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): network = hass.data[const.DATA_NETWORK] - def set_usercode(service): + def set_usercode(service: ServiceCall) -> None: """Set the usercode to index X on the lock.""" node_id = service.data.get(const.ATTR_NODE_ID) lock_node = network.nodes[node_id] @@ -193,7 +193,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): value.data = str(usercode) break - def get_usercode(service): + def get_usercode(service: ServiceCall) -> None: """Get a usercode at index X on the lock.""" node_id = service.data.get(const.ATTR_NODE_ID) lock_node = network.nodes[node_id] @@ -207,7 +207,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): _LOGGER.info("Usercode at slot %s is: %s", value.index, value.data) break - def clear_usercode(service): + def clear_usercode(service: ServiceCall) -> None: """Set usercode to slot X on the lock.""" node_id = service.data.get(const.ATTR_NODE_ID) lock_node = network.nodes[node_id]