Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions homeassistant/components/webostv/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@

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(
Expand All @@ -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)
11 changes: 0 additions & 11 deletions homeassistant/components/webostv/triggers/__init__.py
Original file line number Diff line number Diff line change
@@ -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