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

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-28 14:23:01 +01:00 committed by GitHub
parent fb272f58fb
commit 656d383ba6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 40 additions and 30 deletions

View file

@ -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)

View file

@ -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(

View file

@ -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)

View file

@ -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

View file

@ -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]

View file

@ -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)

View file

@ -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()

View file

@ -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()

View file

@ -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]

View file

@ -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

View file

@ -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}"