parent
ba929dfc79
commit
fdc06c2fc2
|
@ -5,24 +5,28 @@ from typing import cast
|
|||
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
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 .triggers import TriggersPlatformModule, turn_on
|
||||
from .triggers import turn_on
|
||||
|
||||
TRIGGERS = {
|
||||
"turn_on": turn_on,
|
||||
}
|
||||
|
||||
|
||||
def _get_trigger_platform(config: ConfigType) -> TriggersPlatformModule:
|
||||
def _get_trigger_platform(config: ConfigType) -> TriggerProtocol:
|
||||
"""Return trigger platform."""
|
||||
platform_split = config[CONF_PLATFORM].split(".", maxsplit=1)
|
||||
if len(platform_split) < 2 or platform_split[1] not in TRIGGERS:
|
||||
raise ValueError(
|
||||
f"Unknown webOS Smart TV trigger platform {config[CONF_PLATFORM]}"
|
||||
)
|
||||
return cast(TriggersPlatformModule, TRIGGERS[platform_split[1]])
|
||||
return cast(TriggerProtocol, TRIGGERS[platform_split[1]])
|
||||
|
||||
|
||||
async def async_validate_trigger_config(
|
||||
|
@ -41,10 +45,4 @@ async def async_attach_trigger(
|
|||
) -> CALLBACK_TYPE:
|
||||
"""Attach trigger of specified platform."""
|
||||
platform = _get_trigger_platform(config)
|
||||
assert hasattr(platform, "async_attach_trigger")
|
||||
return cast(
|
||||
CALLBACK_TYPE,
|
||||
await getattr(platform, "async_attach_trigger")(
|
||||
hass, config, action, trigger_info
|
||||
),
|
||||
)
|
||||
return await platform.async_attach_trigger(hass, config, action, trigger_info)
|
||||
|
|
|
@ -1,12 +1 @@
|
|||
"""webOS Smart TV triggers."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Protocol
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
||||
class TriggersPlatformModule(Protocol):
|
||||
"""Protocol type for the triggers platform."""
|
||||
|
||||
TRIGGER_SCHEMA: vol.Schema
|
||||
|
|
Loading…
Reference in New Issue