Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure service calls are typed [e-g] #62912

Merged
merged 1 commit into from Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions homeassistant/components/ecobee/climate.py
Expand Up @@ -37,6 +37,7 @@
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
Expand Down Expand Up @@ -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]

Expand All @@ -208,7 +209,7 @@ def create_vacation_service(service):
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]
Expand All @@ -219,7 +220,7 @@ def delete_vacation_service(service):
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]
Expand All @@ -236,7 +237,7 @@ def fan_min_on_time_set_service(service):

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)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/elkm1/__init__.py
Expand Up @@ -24,7 +24,7 @@
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
Expand Down Expand Up @@ -342,13 +342,13 @@ def _getelk(service):
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(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/envisalink/__init__.py
Expand Up @@ -11,7 +11,7 @@
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
Expand Down Expand Up @@ -181,7 +181,7 @@ def stop_envisalink(event):
_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)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/envisalink/alarm_control_panel.py
Expand Up @@ -24,7 +24,7 @@
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

Expand Down Expand Up @@ -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]
Comment on lines +79 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two arguments are marked as required in the schema, so dropped get


target_devices = [
device for device in devices if device.entity_id in entity_ids
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/evohome/__init__.py
Expand Up @@ -22,7 +22,7 @@
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
Expand Down Expand Up @@ -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,
Expand All @@ -289,7 +289,7 @@ async def set_system_mode(call) -> None:
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]

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ffmpeg/__init__.py
Expand Up @@ -13,7 +13,7 @@
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,
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/flux/switch.py
Expand Up @@ -3,6 +3,8 @@

The idea was taken from https://github.com/KpaBap/hue-flux/
"""
from __future__ import annotations

import datetime
import logging

Expand Down Expand Up @@ -32,6 +34,7 @@
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
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/freebox/__init__.py
Expand Up @@ -5,7 +5,7 @@

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
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/geniushub/__init__.py
Expand Up @@ -19,7 +19,7 @@
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
Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_assistant/__init__.py
Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions homeassistant/components/group/__init__.py
Expand Up @@ -26,7 +26,13 @@
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
Expand Down Expand Up @@ -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))

Expand All @@ -238,12 +244,12 @@ async def reload_service_handler(service):

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}"
Expand Down