Adjust device_automation type hints in core platforms 1/3 (#72209)

pull/72369/head
epenet 2022-05-23 16:03:21 +02:00 committed by GitHub
parent 3a0e816f1b
commit fb53e39f05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 52 additions and 25 deletions

View File

@ -24,7 +24,7 @@ from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers import entity_registry
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import get_supported_features
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
from . import ATTR_CODE_ARM_REQUIRED, DOMAIN
from .const import (
@ -90,7 +90,10 @@ async def async_get_actions(
async def async_call_action_from_config(
hass: HomeAssistant, config: ConfigType, variables: dict, context: Context | None
hass: HomeAssistant,
config: ConfigType,
variables: TemplateVarsType,
context: Context | None,
) -> None:
"""Execute a device action."""
service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]}

View File

@ -1,7 +1,7 @@
"""Provides device automations for Alarm control panel."""
from __future__ import annotations
from typing import Any, Final
from typing import Final
import voluptuous as vol
@ -58,7 +58,7 @@ TRIGGER_SCHEMA: Final = DEVICE_TRIGGER_BASE_SCHEMA.extend(
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]]:
) -> list[dict[str, str]]:
"""List device triggers for Alarm control panel devices."""
registry = entity_registry.async_get(hass)
triggers: list[dict[str, str]] = []

View File

@ -1,6 +1,10 @@
"""Provides device triggers for binary sensors."""
import voluptuous as vol
from homeassistant.components.automation import (
AutomationActionType,
AutomationTriggerInfo,
)
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
from homeassistant.components.device_automation.const import (
CONF_TURNED_OFF,
@ -8,8 +12,10 @@ from homeassistant.components.device_automation.const import (
)
from homeassistant.components.homeassistant.triggers import state as state_trigger
from homeassistant.const import CONF_ENTITY_ID, CONF_FOR, CONF_TYPE
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.entity import get_device_class
from homeassistant.helpers.typing import ConfigType
from . import DOMAIN, BinarySensorDeviceClass
@ -254,7 +260,12 @@ TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
)
async def async_attach_trigger(hass, config, action, automation_info):
async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: AutomationTriggerInfo,
) -> CALLBACK_TYPE:
"""Listen for state changes based on configuration."""
trigger_type = config[CONF_TYPE]
if trigger_type in TURNED_ON:
@ -276,9 +287,11 @@ async def async_attach_trigger(hass, config, action, automation_info):
)
async def async_get_triggers(hass, device_id):
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, str]]:
"""List device triggers."""
triggers = []
triggers: list[dict[str, str]] = []
entity_registry = er.async_get(hass)
entries = [
@ -308,7 +321,9 @@ async def async_get_triggers(hass, device_id):
return triggers
async def async_get_trigger_capabilities(hass, config):
async def async_get_trigger_capabilities(
hass: HomeAssistant, config: ConfigType
) -> dict[str, vol.Schema]:
"""List trigger capabilities."""
return {
"extra_fields": vol.Schema(

View File

@ -13,6 +13,7 @@ from homeassistant.const import (
from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers import entity_registry
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
from .const import DOMAIN, SERVICE_PRESS
@ -44,7 +45,10 @@ async def async_get_actions(
async def async_call_action_from_config(
hass: HomeAssistant, config: dict, variables: dict, context: Context | None
hass: HomeAssistant,
config: ConfigType,
variables: TemplateVarsType,
context: Context | None,
) -> None:
"""Execute a device action."""
await hass.services.async_call(

View File

@ -1,8 +1,6 @@
"""Provides device triggers for Button."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.components.automation import (
@ -39,7 +37,7 @@ TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]]:
) -> list[dict[str, str]]:
"""List device triggers for button devices."""
registry = entity_registry.async_get(hass)
return [

View File

@ -15,6 +15,7 @@ from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import get_capability, get_supported_features
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
from . import DOMAIN, const
@ -67,7 +68,10 @@ async def async_get_actions(
async def async_call_action_from_config(
hass: HomeAssistant, config: dict, variables: dict, context: Context | None
hass: HomeAssistant,
config: ConfigType,
variables: TemplateVarsType,
context: Context | None,
) -> None:
"""Execute a device action."""
service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]}
@ -84,7 +88,9 @@ async def async_call_action_from_config(
)
async def async_get_action_capabilities(hass, config):
async def async_get_action_capabilities(
hass: HomeAssistant, config: ConfigType
) -> dict[str, vol.Schema]:
"""List action capabilities."""
action_type = config[CONF_TYPE]

View File

@ -92,7 +92,9 @@ def async_condition_from_config(
return test_is_state
async def async_get_condition_capabilities(hass, config):
async def async_get_condition_capabilities(
hass: HomeAssistant, config: ConfigType
) -> dict[str, vol.Schema]:
"""List condition capabilities."""
condition_type = config[CONF_TYPE]

View File

@ -1,8 +1,6 @@
"""Provides device automations for Climate."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.components.automation import (
@ -65,7 +63,7 @@ TRIGGER_SCHEMA = vol.Any(HVAC_MODE_TRIGGER_SCHEMA, CURRENT_TRIGGER_SCHEMA)
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]]:
) -> list[dict[str, str]]:
"""List device triggers for Climate devices."""
registry = entity_registry.async_get(hass)
triggers = []

View File

@ -21,7 +21,7 @@ from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers import entity_registry
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import get_supported_features
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
from . import (
ATTR_POSITION,
@ -120,7 +120,10 @@ async def async_get_action_capabilities(
async def async_call_action_from_config(
hass: HomeAssistant, config: dict, variables: dict, context: Context | None
hass: HomeAssistant,
config: ConfigType,
variables: TemplateVarsType,
context: Context | None,
) -> None:
"""Execute a device action."""
service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]}

View File

@ -1,8 +1,6 @@
"""Provides device automations for Cover."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.components.automation import (
@ -74,7 +72,7 @@ TRIGGER_SCHEMA = vol.Any(POSITION_TRIGGER_SCHEMA, STATE_TRIGGER_SCHEMA)
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]]:
) -> list[dict[str, str]]:
"""List device triggers for Cover devices."""
registry = entity_registry.async_get(hass)
triggers = []

View File

@ -1,7 +1,7 @@
"""Provides device automations for Device Tracker."""
from __future__ import annotations
from typing import Any, Final
from typing import Final
import voluptuous as vol
@ -39,7 +39,7 @@ TRIGGER_SCHEMA: Final = DEVICE_TRIGGER_BASE_SCHEMA.extend(
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]]:
) -> list[dict[str, str]]:
"""List device triggers for Device Tracker devices."""
registry = entity_registry.async_get(hass)
triggers = []