Ensure service calls are typed [k-n] (#62917)

* Ensure service calls are typed [k-n]

* Ensure service calls are typed in mazda

* Adjust mazda

* Add mazda comment

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-28 14:33:08 +01:00 committed by GitHub
parent 1c7efe7047
commit 8cc0df7b72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 47 additions and 32 deletions

View file

@ -6,6 +6,7 @@ from keba_kecontact.connection import KebaKeContact
import voluptuous as vol
from homeassistant.const import CONF_HOST
from homeassistant.core import ServiceCall
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
@ -77,7 +78,7 @@ async def async_setup(hass, config):
_LOGGER.warning("Could not set failsafe mode %s", ex)
# Register services to hass
async def execute_service(call):
async def execute_service(call: ServiceCall) -> None:
"""Execute a service to KEBA charging station.
This must be a member function as we need access to the keba

View file

@ -42,7 +42,7 @@ from homeassistant.const import (
ATTR_SW_VERSION,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import callback
from homeassistant.core import ServiceCall, callback
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
import homeassistant.helpers.device_registry as dr
@ -298,7 +298,7 @@ class LIFXManager:
def register_effects(self):
"""Register the LIFX effects as hass service calls."""
async def service_handler(service):
async def service_handler(service: ServiceCall) -> None:
"""Apply a service, i.e. start an effect."""
entities = await self.platform.async_extract_from_service(service)
if entities:

View file

@ -34,7 +34,12 @@ from homeassistant.const import (
EVENT_LOGBOOK_ENTRY,
EVENT_STATE_CHANGED,
)
from homeassistant.core import DOMAIN as HA_DOMAIN, callback, split_entity_id
from homeassistant.core import (
DOMAIN as HA_DOMAIN,
ServiceCall,
callback,
split_entity_id,
)
from homeassistant.exceptions import InvalidEntityFormatError
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entityfilter import (
@ -130,7 +135,7 @@ async def async_setup(hass, config):
hass.data[DOMAIN] = {}
@callback
def log_message(service):
def log_message(service: ServiceCall) -> None:
"""Handle sending notification message service calls."""
message = service.data[ATTR_MESSAGE]
name = service.data[ATTR_NAME]

View file

@ -3,7 +3,7 @@ import logging
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.core import ServiceCall, callback
import homeassistant.helpers.config_validation as cv
DOMAIN = "logger"
@ -78,7 +78,7 @@ async def async_setup(hass, config):
_add_log_filter(logger, value)
@callback
def async_service_handler(service):
def async_service_handler(service: ServiceCall) -> None:
"""Handle logger services."""
if service.service == SERVICE_SET_DEFAULT_LEVEL:
set_default_log_level(service.data.get(ATTR_LEVEL))

View file

@ -20,6 +20,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import ServiceCall
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -184,7 +185,7 @@ async def async_setup_entry(hass, entry):
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
async def service_handler(service):
async def service_handler(service: ServiceCall) -> None:
"""Dispatch service calls to target entities."""
params = dict(service.data)

View file

@ -1,6 +1,9 @@
"""The Mazda Connected Services integration."""
from __future__ import annotations
from datetime import timedelta
import logging
from typing import TYPE_CHECKING
import async_timeout
from pymazda import (
@ -15,7 +18,7 @@ import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_REGION, Platform
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import (
ConfigEntryAuthFailed,
ConfigEntryNotReady,
@ -67,12 +70,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
_LOGGER.error("Error occurred during Mazda login request: %s", ex)
raise ConfigEntryNotReady from ex
async def async_handle_service_call(service_call=None):
async def async_handle_service_call(service_call: ServiceCall) -> None:
"""Handle a service call."""
# Get device entry from device registry
dev_reg = device_registry.async_get(hass)
device_id = service_call.data["device_id"]
device_entry = dev_reg.async_get(device_id)
if TYPE_CHECKING:
# For mypy: it has already been checked in validate_mazda_device_id
assert device_entry
# Get vehicle VIN from device identifiers
mazda_identifiers = (

View file

@ -9,6 +9,7 @@ import async_timeout
import voluptuous as vol
from homeassistant.const import ATTR_NAME, CONF_API_KEY, CONF_TIMEOUT, CONTENT_TYPE_JSON
from homeassistant.core import ServiceCall
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
@ -86,7 +87,7 @@ async def async_setup(hass, config):
hass.data[DATA_MICROSOFT_FACE] = face
async def async_create_group(service):
async def async_create_group(service: ServiceCall) -> None:
"""Create a new person group."""
name = service.data[ATTR_NAME]
g_id = slugify(name)
@ -104,7 +105,7 @@ async def async_setup(hass, config):
DOMAIN, SERVICE_CREATE_GROUP, async_create_group, schema=SCHEMA_GROUP_SERVICE
)
async def async_delete_group(service):
async def async_delete_group(service: ServiceCall) -> None:
"""Delete a person group."""
g_id = slugify(service.data[ATTR_NAME])
@ -121,7 +122,7 @@ async def async_setup(hass, config):
DOMAIN, SERVICE_DELETE_GROUP, async_delete_group, schema=SCHEMA_GROUP_SERVICE
)
async def async_train_group(service):
async def async_train_group(service: ServiceCall) -> None:
"""Train a person group."""
g_id = service.data[ATTR_GROUP]
@ -134,7 +135,7 @@ async def async_setup(hass, config):
DOMAIN, SERVICE_TRAIN_GROUP, async_train_group, schema=SCHEMA_TRAIN_SERVICE
)
async def async_create_person(service):
async def async_create_person(service: ServiceCall) -> None:
"""Create a person in a group."""
name = service.data[ATTR_NAME]
g_id = service.data[ATTR_GROUP]
@ -153,7 +154,7 @@ async def async_setup(hass, config):
DOMAIN, SERVICE_CREATE_PERSON, async_create_person, schema=SCHEMA_PERSON_SERVICE
)
async def async_delete_person(service):
async def async_delete_person(service: ServiceCall) -> None:
"""Delete a person in a group."""
name = service.data[ATTR_NAME]
g_id = service.data[ATTR_GROUP]
@ -171,7 +172,7 @@ async def async_setup(hass, config):
DOMAIN, SERVICE_DELETE_PERSON, async_delete_person, schema=SCHEMA_PERSON_SERVICE
)
async def async_face_person(service):
async def async_face_person(service: ServiceCall) -> None:
"""Add a new face picture to a person."""
g_id = service.data[ATTR_GROUP]
p_id = face.store[g_id].get(service.data[ATTR_PERSON])

View file

@ -19,7 +19,7 @@ from homeassistant.const import (
PRECISION_WHOLE,
TEMP_CELSIUS,
)
from homeassistant.core import callback
from homeassistant.core import ServiceCall, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -65,7 +65,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
]
async_add_entities(entities)
async def set_room_temp(service):
async def set_room_temp(service: ServiceCall) -> None:
"""Set room temp."""
room_name = service.data.get(ATTR_ROOM_NAME)
sleep_temp = service.data.get(ATTR_SLEEP_TEMP)

View file

@ -93,7 +93,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entity.restore()
@service.verify_domain_control(hass, DOMAIN)
async def async_service_handle(service_call):
async def async_service_handle(service_call: core.ServiceCall) -> None:
"""Handle for services."""
entities = await platform.async_extract_from_service(service_call)

View file

@ -541,7 +541,7 @@ async def async_setup_entry(hass, entry):
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_stop_mqtt)
async def async_publish_service(call: ServiceCall):
async def async_publish_service(call: ServiceCall) -> None:
"""Handle MQTT publish service calls."""
msg_topic = call.data.get(ATTR_TOPIC)
msg_topic_template = call.data.get(ATTR_TOPIC_TEMPLATE)
@ -594,7 +594,7 @@ async def async_setup_entry(hass, entry):
DOMAIN, SERVICE_PUBLISH, async_publish_service, schema=MQTT_PUBLISH_SCHEMA
)
async def async_dump_service(call: ServiceCall):
async def async_dump_service(call: ServiceCall) -> None:
"""Handle MQTT dump service calls."""
messages = []

View file

@ -16,6 +16,7 @@ from homeassistant.const import (
CONF_SCAN_INTERVAL,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import ServiceCall
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -132,10 +133,10 @@ async def async_setup(hass, config):
hass.loop.create_task(client.keepalive())
hass.loop.create_task(client.update())
async def handle_panic(call):
async def handle_panic(call: ServiceCall) -> None:
await client.panic(call.data[ATTR_CODE])
async def handle_aux(call):
async def handle_aux(call: ServiceCall) -> None:
await client.aux(call.data[ATTR_OUTPUT_ID], call.data[ATTR_STATE])
hass.services.async_register(

View file

@ -22,7 +22,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import CoreState, HomeAssistant
from homeassistant.core import CoreState, HomeAssistant, ServiceCall
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import (
aiohttp_client,
@ -146,7 +146,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
async def unregister_webhook(_: None) -> None:
async def unregister_webhook(call: ServiceCall | None) -> None:
if CONF_WEBHOOK_ID not in entry.data:
return
_LOGGER.debug("Unregister Netatmo webhook (%s)", entry.data[CONF_WEBHOOK_ID])
@ -163,7 +163,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"No webhook to be dropped for %s", entry.data[CONF_WEBHOOK_ID]
)
async def register_webhook(_: None) -> None:
async def register_webhook(call: ServiceCall | None) -> None:
if CONF_WEBHOOK_ID not in entry.data:
data = {**entry.data, CONF_WEBHOOK_ID: secrets.token_hex()}
hass.config_entries.async_update_entry(entry, data=data)

View file

@ -19,7 +19,7 @@ from homeassistant.const import (
CONF_RECIPIENT,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import callback
from homeassistant.core import ServiceCall, callback
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.helpers.dispatcher import (
@ -179,7 +179,7 @@ async def async_setup(hass, config):
)
hass.data[DATA_KEY] = LTEData(websession)
async def service_handler(service):
async def service_handler(service: ServiceCall) -> None:
"""Apply a service."""
host = service.data.get(ATTR_HOST)
conf = {CONF_HOST: host}

View file

@ -12,7 +12,7 @@ from homeassistant.const import (
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -130,15 +130,15 @@ def _async_register_services(
) -> None:
"""Register integration-level services."""
def pause(call) -> None:
def pause(call: ServiceCall) -> None:
"""Service call to pause downloads in NZBGet."""
coordinator.nzbget.pausedownload()
def resume(call) -> None:
def resume(call: ServiceCall) -> None:
"""Service call to resume downloads in NZBGet."""
coordinator.nzbget.resumedownload()
def set_speed(call) -> None:
def set_speed(call: ServiceCall) -> None:
"""Service call to rate limit speeds in NZBGet."""
coordinator.nzbget.rate(call.data[ATTR_SPEED])