Improve type hint in zwave_js trigger (#88597)
Imrpove type hint in zwave_js trigger
This commit is contained in:
parent
6d9411b8a1
commit
3c1e62aeef
1 changed files with 10 additions and 16 deletions
|
@ -1,12 +1,15 @@
|
||||||
"""Z-Wave JS trigger dispatcher."""
|
"""Z-Wave JS trigger dispatcher."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from types import ModuleType
|
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from homeassistant.const import CONF_PLATFORM
|
from homeassistant.const import CONF_PLATFORM
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
from homeassistant.helpers.trigger import (
|
||||||
|
TriggerActionType,
|
||||||
|
TriggerInfo,
|
||||||
|
TriggerProtocol,
|
||||||
|
)
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .triggers import event, value_updated
|
from .triggers import event, value_updated
|
||||||
|
@ -17,7 +20,7 @@ TRIGGERS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_trigger_platform(config: ConfigType) -> ModuleType:
|
def _get_trigger_platform(config: ConfigType) -> TriggerProtocol:
|
||||||
"""Return trigger platform."""
|
"""Return trigger platform."""
|
||||||
platform_split = config[CONF_PLATFORM].split(".", maxsplit=1)
|
platform_split = config[CONF_PLATFORM].split(".", maxsplit=1)
|
||||||
if len(platform_split) < 2 or platform_split[1] not in TRIGGERS:
|
if len(platform_split) < 2 or platform_split[1] not in TRIGGERS:
|
||||||
|
@ -31,12 +34,9 @@ async def async_validate_trigger_config(
|
||||||
"""Validate config."""
|
"""Validate config."""
|
||||||
platform = _get_trigger_platform(config)
|
platform = _get_trigger_platform(config)
|
||||||
if hasattr(platform, "async_validate_trigger_config"):
|
if hasattr(platform, "async_validate_trigger_config"):
|
||||||
return cast(
|
return await platform.async_validate_trigger_config(hass, config)
|
||||||
ConfigType,
|
|
||||||
await getattr(platform, "async_validate_trigger_config")(hass, config),
|
return cast(ConfigType, platform.TRIGGER_SCHEMA(config))
|
||||||
)
|
|
||||||
assert hasattr(platform, "TRIGGER_SCHEMA")
|
|
||||||
return cast(ConfigType, getattr(platform, "TRIGGER_SCHEMA")(config))
|
|
||||||
|
|
||||||
|
|
||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
|
@ -47,10 +47,4 @@ async def async_attach_trigger(
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Attach trigger of specified platform."""
|
"""Attach trigger of specified platform."""
|
||||||
platform = _get_trigger_platform(config)
|
platform = _get_trigger_platform(config)
|
||||||
assert hasattr(platform, "async_attach_trigger")
|
return await platform.async_attach_trigger(hass, config, action, trigger_info)
|
||||||
return cast(
|
|
||||||
CALLBACK_TYPE,
|
|
||||||
await getattr(platform, "async_attach_trigger")(
|
|
||||||
hass, config, action, trigger_info
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue