Ensure service calls are typed [e-g] (#62912)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
fb272f58fb
commit
656d383ba6
11 changed files with 40 additions and 30 deletions
|
@ -37,6 +37,7 @@ from homeassistant.const import (
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import ServiceCall
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
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()
|
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."""
|
"""Create a vacation on the target thermostat."""
|
||||||
entity_id = service.data[ATTR_ENTITY_ID]
|
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)
|
thermostat.schedule_update_ha_state(True)
|
||||||
break
|
break
|
||||||
|
|
||||||
def delete_vacation_service(service):
|
def delete_vacation_service(service: ServiceCall) -> None:
|
||||||
"""Delete a vacation on the target thermostat."""
|
"""Delete a vacation on the target thermostat."""
|
||||||
entity_id = service.data[ATTR_ENTITY_ID]
|
entity_id = service.data[ATTR_ENTITY_ID]
|
||||||
vacation_name = service.data[ATTR_VACATION_NAME]
|
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)
|
thermostat.schedule_update_ha_state(True)
|
||||||
break
|
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."""
|
"""Set the minimum fan on time on the target thermostats."""
|
||||||
entity_id = service.data.get(ATTR_ENTITY_ID)
|
entity_id = service.data.get(ATTR_ENTITY_ID)
|
||||||
fan_min_on_time = service.data[ATTR_FAN_MIN_ON_TIME]
|
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)
|
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."""
|
"""Resume the program on the target thermostats."""
|
||||||
entity_id = service.data.get(ATTR_ENTITY_ID)
|
entity_id = service.data.get(ATTR_ENTITY_ID)
|
||||||
resume_all = service.data.get(ATTR_RESUME_ALL)
|
resume_all = service.data.get(ATTR_RESUME_ALL)
|
||||||
|
|
|
@ -24,7 +24,7 @@ from homeassistant.const import (
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
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")
|
raise HomeAssistantError(f"No ElkM1 with prefix '{prefix}' found")
|
||||||
return elk
|
return elk
|
||||||
|
|
||||||
def _speak_word_service(service):
|
def _speak_word_service(service: ServiceCall) -> None:
|
||||||
_getelk(service).panel.speak_word(service.data["number"])
|
_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"])
|
_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())
|
_getelk(service).panel.set_time(dt_util.now())
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.const import (
|
||||||
CONF_TIMEOUT,
|
CONF_TIMEOUT,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import ServiceCall, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.discovery import async_load_platform
|
from homeassistant.helpers.discovery import async_load_platform
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
@ -181,7 +181,7 @@ async def async_setup(hass, config):
|
||||||
_LOGGER.info("Shutting down Envisalink")
|
_LOGGER.info("Shutting down Envisalink")
|
||||||
controller.stop()
|
controller.stop()
|
||||||
|
|
||||||
async def handle_custom_function(call):
|
async def handle_custom_function(call: ServiceCall) -> None:
|
||||||
"""Handle custom/PGM service."""
|
"""Handle custom/PGM service."""
|
||||||
custom_function = call.data.get(ATTR_CUSTOM_FUNCTION)
|
custom_function = call.data.get(ATTR_CUSTOM_FUNCTION)
|
||||||
partition = call.data.get(ATTR_PARTITION)
|
partition = call.data.get(ATTR_PARTITION)
|
||||||
|
|
|
@ -24,7 +24,7 @@ from homeassistant.const import (
|
||||||
STATE_ALARM_TRIGGERED,
|
STATE_ALARM_TRIGGERED,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import ServiceCall, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
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)
|
async_add_entities(devices)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def alarm_keypress_handler(service):
|
def alarm_keypress_handler(service: ServiceCall) -> None:
|
||||||
"""Map services to methods on Alarm."""
|
"""Map services to methods on Alarm."""
|
||||||
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
entity_ids = service.data[ATTR_ENTITY_ID]
|
||||||
keypress = service.data.get(ATTR_KEYPRESS)
|
keypress = service.data[ATTR_KEYPRESS]
|
||||||
|
|
||||||
target_devices = [
|
target_devices = [
|
||||||
device for device in devices if device.entity_id in entity_ids
|
device for device in devices if device.entity_id in entity_ids
|
||||||
|
|
|
@ -22,7 +22,7 @@ from homeassistant.const import (
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.discovery import async_load_platform
|
from homeassistant.helpers.discovery import async_load_platform
|
||||||
|
@ -274,12 +274,12 @@ def setup_service_functions(hass: HomeAssistant, broker):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@verify_domain_control(hass, DOMAIN)
|
@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."""
|
"""Obtain the latest state data via the vendor's RESTful API."""
|
||||||
await broker.async_update()
|
await broker.async_update()
|
||||||
|
|
||||||
@verify_domain_control(hass, DOMAIN)
|
@verify_domain_control(hass, DOMAIN)
|
||||||
async def set_system_mode(call) -> None:
|
async def set_system_mode(call: ServiceCall) -> None:
|
||||||
"""Set the system mode."""
|
"""Set the system mode."""
|
||||||
payload = {
|
payload = {
|
||||||
"unique_id": broker.tcs.systemId,
|
"unique_id": broker.tcs.systemId,
|
||||||
|
@ -289,7 +289,7 @@ def setup_service_functions(hass: HomeAssistant, broker):
|
||||||
async_dispatcher_send(hass, DOMAIN, payload)
|
async_dispatcher_send(hass, DOMAIN, payload)
|
||||||
|
|
||||||
@verify_domain_control(hass, DOMAIN)
|
@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)."""
|
"""Set the zone override (setpoint)."""
|
||||||
entity_id = call.data[ATTR_ENTITY_ID]
|
entity_id = call.data[ATTR_ENTITY_ID]
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect,
|
async_dispatcher_connect,
|
||||||
|
@ -64,7 +64,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
await manager.async_get_version()
|
await manager.async_get_version()
|
||||||
|
|
||||||
# Register service
|
# Register service
|
||||||
async def async_service_handle(service):
|
async def async_service_handle(service: ServiceCall) -> None:
|
||||||
"""Handle service ffmpeg process."""
|
"""Handle service ffmpeg process."""
|
||||||
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ Flux for Home-Assistant.
|
||||||
|
|
||||||
The idea was taken from https://github.com/KpaBap/hue-flux/
|
The idea was taken from https://github.com/KpaBap/hue-flux/
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -32,6 +34,7 @@ from homeassistant.const import (
|
||||||
SUN_EVENT_SUNRISE,
|
SUN_EVENT_SUNRISE,
|
||||||
SUN_EVENT_SUNSET,
|
SUN_EVENT_SUNSET,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import ServiceCall
|
||||||
from homeassistant.helpers import config_validation as cv, event
|
from homeassistant.helpers import config_validation as cv, event
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.sun import get_astral_event_date
|
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_add_entities([flux])
|
||||||
|
|
||||||
async def async_update(call=None):
|
async def async_update(call: ServiceCall | None = None) -> None:
|
||||||
"""Update lights."""
|
"""Update lights."""
|
||||||
await flux.async_flux_update()
|
await flux.async_flux_update()
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP
|
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 homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORMS, SERVICE_REBOOT
|
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)
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
# Services
|
# Services
|
||||||
async def async_reboot(call):
|
async def async_reboot(call: ServiceCall) -> None:
|
||||||
"""Handle reboot service call."""
|
"""Handle reboot service call."""
|
||||||
await router.reboot()
|
await router.reboot()
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.const import (
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
TEMP_CELSIUS,
|
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 import config_validation as cv
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.discovery import async_load_platform
|
from homeassistant.helpers.discovery import async_load_platform
|
||||||
|
@ -133,7 +133,7 @@ def setup_service_functions(hass: HomeAssistant, broker):
|
||||||
"""Set up the service functions."""
|
"""Set up the service functions."""
|
||||||
|
|
||||||
@verify_domain_control(hass, DOMAIN)
|
@verify_domain_control(hass, DOMAIN)
|
||||||
async def set_zone_mode(call) -> None:
|
async def set_zone_mode(call: ServiceCall) -> None:
|
||||||
"""Set the system mode."""
|
"""Set the system mode."""
|
||||||
entity_id = call.data[ATTR_ENTITY_ID]
|
entity_id = call.data[ATTR_ENTITY_ID]
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
|
||||||
if google_config.should_report_state:
|
if google_config.should_report_state:
|
||||||
google_config.async_enable_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."""
|
"""Handle request sync service calls."""
|
||||||
agent_user_id = call.data.get("agent_user_id") or call.context.user_id
|
agent_user_id = call.data.get("agent_user_id") or call.context.user_id
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,13 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
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
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
@ -220,7 +226,7 @@ async def async_setup(hass, config):
|
||||||
|
|
||||||
await _async_process_config(hass, config, component)
|
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."""
|
"""Remove all user-defined groups and load new ones from config."""
|
||||||
auto = list(filter(lambda e: not e.user_defined, component.entities))
|
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()
|
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."""
|
"""Handle a service with an async lock."""
|
||||||
async with service_lock:
|
async with service_lock:
|
||||||
await groups_service_handler(service)
|
await groups_service_handler(service)
|
||||||
|
|
||||||
async def groups_service_handler(service):
|
async def groups_service_handler(service: ServiceCall) -> None:
|
||||||
"""Handle dynamic group service functions."""
|
"""Handle dynamic group service functions."""
|
||||||
object_id = service.data[ATTR_OBJECT_ID]
|
object_id = service.data[ATTR_OBJECT_ID]
|
||||||
entity_id = f"{DOMAIN}.{object_id}"
|
entity_id = f"{DOMAIN}.{object_id}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue