mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 10:47:51 +00:00

* Add Config Flow to lg_netcast * Add YAML import to Lg Netcast ConfigFlow Deprecates YAML config support * Add LG Netcast Device triggers for turn_on action * Add myself to LG Netcast codeowners * Remove unnecessary user_input validation check. * Move netcast discovery logic to the backend * Use FlowResultType Enum for tests * Mock pylgnetcast.query_device_info instead of _send_to_tv * Refactor lg_netcast client discovery, simplify YAML import * Simplify CONF_NAME to use friendly name Fix: Use Friendly name for Name * Expose model to DeviceInfo * Add test for testing YAML import when not TV not online * Switch to entity_name for LGTVDevice * Add data_description to host field in user step * Wrap try only around _get_session_id * Send regular request for access_token to ensure it display on the TV * Stop displaying access token when flow is aborted * Remove config_flow only consts and minor fixups * Simplify media_player logic & raise new migration issue * Add async_unload_entry * Create issues when import config flow fails, and raise only a single yaml deprecation issue type * Remove single use trigger helpers * Bump issue deprecation breakage version * Lint --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
"""LG Netcast TV trigger dispatcher."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import cast
|
|
|
|
from homeassistant.const import CONF_PLATFORM
|
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
|
from homeassistant.helpers.trigger import (
|
|
TriggerActionType,
|
|
TriggerInfo,
|
|
TriggerProtocol,
|
|
)
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
from .triggers import turn_on
|
|
|
|
TRIGGERS = {
|
|
"turn_on": turn_on,
|
|
}
|
|
|
|
|
|
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 LG Netcast TV trigger platform {config[CONF_PLATFORM]}"
|
|
)
|
|
return cast(TriggerProtocol, TRIGGERS[platform_split[1]])
|
|
|
|
|
|
async def async_validate_trigger_config(
|
|
hass: HomeAssistant, config: ConfigType
|
|
) -> ConfigType:
|
|
"""Validate config."""
|
|
platform = _get_trigger_platform(config)
|
|
return cast(ConfigType, platform.TRIGGER_SCHEMA(config))
|
|
|
|
|
|
async def async_attach_trigger(
|
|
hass: HomeAssistant,
|
|
config: ConfigType,
|
|
action: TriggerActionType,
|
|
trigger_info: TriggerInfo,
|
|
) -> CALLBACK_TYPE:
|
|
"""Attach trigger of specified platform."""
|
|
platform = _get_trigger_platform(config)
|
|
return await platform.async_attach_trigger(hass, config, action, trigger_info)
|