Type homeassistant triggers event (#51979)

This commit is contained in:
Martin Hjelmare 2021-06-18 18:46:20 +02:00 committed by GitHub
parent 054ca1d7ec
commit 2628ce54d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 10 deletions

View File

@ -35,6 +35,7 @@ homeassistant.components.geo_location.*
homeassistant.components.gios.*
homeassistant.components.group.*
homeassistant.components.history.*
homeassistant.components.homeassistant.triggers.event
homeassistant.components.http.*
homeassistant.components.huawei_lte.*
homeassistant.components.hyperion.*

View File

@ -1,11 +1,15 @@
"""Offer event listening automation rules."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.components.automation import AutomationActionType
from homeassistant.const import CONF_EVENT_DATA, CONF_PLATFORM
from homeassistant.core import HassJob, callback
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, template
# mypy: allow-untyped-defs
from homeassistant.helpers.typing import ConfigType
CONF_EVENT_TYPE = "event_type"
CONF_EVENT_CONTEXT = "context"
@ -20,7 +24,7 @@ TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
)
def _schema_value(value):
def _schema_value(value: Any) -> Any:
if isinstance(value, list):
return vol.In(value)
@ -28,8 +32,13 @@ def _schema_value(value):
async def async_attach_trigger(
hass, config, action, automation_info, *, platform_type="event"
):
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: dict[str, Any],
*,
platform_type: str = "event",
) -> CALLBACK_TYPE:
"""Listen for events based on configuration."""
trigger_data = automation_info.get("trigger_data", {}) if automation_info else {}
variables = None
@ -76,7 +85,7 @@ async def async_attach_trigger(
job = HassJob(action)
@callback
def handle_event(event):
def handle_event(event: Event) -> None:
"""Listen for events and calls the action when data matches."""
try:
# Check that the event data and context match the configured
@ -107,7 +116,7 @@ async def async_attach_trigger(
]
@callback
def remove_listen_events():
def remove_listen_events() -> None:
"""Remove event listeners."""
for remove in removes:
remove()

View File

@ -396,6 +396,17 @@ no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.homeassistant.triggers.event]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.http.*]
check_untyped_defs = true
disallow_incomplete_defs = true
@ -1148,7 +1159,22 @@ ignore_errors = true
[mypy-homeassistant.components.home_plus_control.*]
ignore_errors = true
[mypy-homeassistant.components.homeassistant.*]
[mypy-homeassistant.components.homeassistant.triggers.homeassistant]
ignore_errors = true
[mypy-homeassistant.components.homeassistant.triggers.numeric_state]
ignore_errors = true
[mypy-homeassistant.components.homeassistant.triggers.time_pattern]
ignore_errors = true
[mypy-homeassistant.components.homeassistant.triggers.time]
ignore_errors = true
[mypy-homeassistant.components.homeassistant.triggers.state]
ignore_errors = true
[mypy-homeassistant.components.homeassistant.scene]
ignore_errors = true
[mypy-homeassistant.components.homekit.*]

View File

@ -85,7 +85,12 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.hisense_aehw4a1.*",
"homeassistant.components.home_connect.*",
"homeassistant.components.home_plus_control.*",
"homeassistant.components.homeassistant.*",
"homeassistant.components.homeassistant.triggers.homeassistant",
"homeassistant.components.homeassistant.triggers.numeric_state",
"homeassistant.components.homeassistant.triggers.time_pattern",
"homeassistant.components.homeassistant.triggers.time",
"homeassistant.components.homeassistant.triggers.state",
"homeassistant.components.homeassistant.scene",
"homeassistant.components.homekit.*",
"homeassistant.components.homekit_controller.*",
"homeassistant.components.homematicip_cloud.*",