mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Move webostv service registration (#162091)
This commit is contained in:
@@ -23,6 +23,7 @@ from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DATA_HASS_CONFIG, DOMAIN, PLATFORMS, WEBOSTV_EXCEPTIONS
|
||||
from .helpers import WebOsTvConfigEntry, update_client_key
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
@@ -31,6 +32,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the LG webOS TV platform."""
|
||||
hass.data.setdefault(DOMAIN, {DATA_HASS_CONFIG: config})
|
||||
|
||||
async_setup_services(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -12,17 +12,12 @@ PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||
DATA_HASS_CONFIG = "hass_config"
|
||||
DEFAULT_NAME = "LG webOS TV"
|
||||
|
||||
ATTR_BUTTON = "button"
|
||||
ATTR_PAYLOAD = "payload"
|
||||
ATTR_SOUND_OUTPUT = "sound_output"
|
||||
|
||||
CONF_ON_ACTION = "turn_on_action"
|
||||
CONF_SOURCES = "sources"
|
||||
|
||||
SERVICE_BUTTON = "button"
|
||||
SERVICE_COMMAND = "command"
|
||||
SERVICE_SELECT_SOUND_OUTPUT = "select_sound_output"
|
||||
|
||||
LIVE_TV_APP_ID = "com.webos.app.livetv"
|
||||
|
||||
WEBOSTV_EXCEPTIONS = (
|
||||
|
||||
@@ -12,7 +12,6 @@ import logging
|
||||
from typing import Any, Concatenate, cast
|
||||
|
||||
from aiowebostv import WebOsTvPairError, WebOsTvState
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import util
|
||||
from homeassistant.components.media_player import (
|
||||
@@ -22,27 +21,21 @@ from homeassistant.components.media_player import (
|
||||
MediaPlayerState,
|
||||
MediaType,
|
||||
)
|
||||
from homeassistant.const import ATTR_COMMAND, ATTR_SUPPORTED_FEATURES
|
||||
from homeassistant.core import HomeAssistant, ServiceResponse, SupportsResponse
|
||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES
|
||||
from homeassistant.core import HomeAssistant, ServiceResponse
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.trigger import PluggableAction
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
|
||||
from .const import (
|
||||
ATTR_BUTTON,
|
||||
ATTR_PAYLOAD,
|
||||
ATTR_SOUND_OUTPUT,
|
||||
CONF_SOURCES,
|
||||
DOMAIN,
|
||||
LIVE_TV_APP_ID,
|
||||
SERVICE_BUTTON,
|
||||
SERVICE_COMMAND,
|
||||
SERVICE_SELECT_SOUND_OUTPUT,
|
||||
WEBOSTV_EXCEPTIONS,
|
||||
)
|
||||
from .helpers import WebOsTvConfigEntry, update_client_key
|
||||
@@ -70,34 +63,6 @@ MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
|
||||
PARALLEL_UPDATES = 0
|
||||
SCAN_INTERVAL = timedelta(seconds=10)
|
||||
|
||||
BUTTON_SCHEMA: VolDictType = {vol.Required(ATTR_BUTTON): cv.string}
|
||||
COMMAND_SCHEMA: VolDictType = {
|
||||
vol.Required(ATTR_COMMAND): cv.string,
|
||||
vol.Optional(ATTR_PAYLOAD): dict,
|
||||
}
|
||||
SOUND_OUTPUT_SCHEMA: VolDictType = {vol.Required(ATTR_SOUND_OUTPUT): cv.string}
|
||||
|
||||
SERVICES = (
|
||||
(
|
||||
SERVICE_BUTTON,
|
||||
BUTTON_SCHEMA,
|
||||
"async_button",
|
||||
SupportsResponse.NONE,
|
||||
),
|
||||
(
|
||||
SERVICE_COMMAND,
|
||||
COMMAND_SCHEMA,
|
||||
"async_command",
|
||||
SupportsResponse.OPTIONAL,
|
||||
),
|
||||
(
|
||||
SERVICE_SELECT_SOUND_OUTPUT,
|
||||
SOUND_OUTPUT_SCHEMA,
|
||||
"async_select_sound_output",
|
||||
SupportsResponse.OPTIONAL,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@@ -105,12 +70,6 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the LG webOS TV platform."""
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
for service_name, schema, method, supports_response in SERVICES:
|
||||
platform.async_register_entity_service(
|
||||
service_name, schema, method, supports_response=supports_response
|
||||
)
|
||||
|
||||
async_add_entities([LgWebOSMediaPlayerEntity(entry)])
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
"""LG webOS TV services."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||
from homeassistant.const import ATTR_COMMAND
|
||||
from homeassistant.core import HomeAssistant, SupportsResponse, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
|
||||
from .const import ATTR_PAYLOAD, ATTR_SOUND_OUTPUT, DOMAIN
|
||||
|
||||
ATTR_BUTTON = "button"
|
||||
|
||||
SERVICE_BUTTON = "button"
|
||||
SERVICE_COMMAND = "command"
|
||||
SERVICE_SELECT_SOUND_OUTPUT = "select_sound_output"
|
||||
|
||||
BUTTON_SCHEMA: VolDictType = {vol.Required(ATTR_BUTTON): cv.string}
|
||||
COMMAND_SCHEMA: VolDictType = {
|
||||
vol.Required(ATTR_COMMAND): cv.string,
|
||||
vol.Optional(ATTR_PAYLOAD): dict,
|
||||
}
|
||||
SOUND_OUTPUT_SCHEMA: VolDictType = {vol.Required(ATTR_SOUND_OUTPUT): cv.string}
|
||||
|
||||
SERVICES = (
|
||||
(
|
||||
SERVICE_BUTTON,
|
||||
BUTTON_SCHEMA,
|
||||
"async_button",
|
||||
SupportsResponse.NONE,
|
||||
),
|
||||
(
|
||||
SERVICE_COMMAND,
|
||||
COMMAND_SCHEMA,
|
||||
"async_command",
|
||||
SupportsResponse.OPTIONAL,
|
||||
),
|
||||
(
|
||||
SERVICE_SELECT_SOUND_OUTPUT,
|
||||
SOUND_OUTPUT_SCHEMA,
|
||||
"async_select_sound_output",
|
||||
SupportsResponse.OPTIONAL,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up services."""
|
||||
|
||||
for service_name, schema, method, supports_response in SERVICES:
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
service_name,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema=schema,
|
||||
func=method,
|
||||
supports_response=supports_response,
|
||||
)
|
||||
@@ -26,20 +26,22 @@ from homeassistant.components.media_player import (
|
||||
MediaType,
|
||||
)
|
||||
from homeassistant.components.webostv.const import (
|
||||
ATTR_BUTTON,
|
||||
ATTR_PAYLOAD,
|
||||
ATTR_SOUND_OUTPUT,
|
||||
DOMAIN,
|
||||
LIVE_TV_APP_ID,
|
||||
SERVICE_BUTTON,
|
||||
SERVICE_COMMAND,
|
||||
SERVICE_SELECT_SOUND_OUTPUT,
|
||||
WebOsTvCommandError,
|
||||
)
|
||||
from homeassistant.components.webostv.media_player import (
|
||||
SUPPORT_WEBOSTV,
|
||||
SUPPORT_WEBOSTV_VOLUME,
|
||||
)
|
||||
from homeassistant.components.webostv.services import (
|
||||
ATTR_BUTTON,
|
||||
SERVICE_BUTTON,
|
||||
SERVICE_COMMAND,
|
||||
SERVICE_SELECT_SOUND_OUTPUT,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
ATTR_COMMAND,
|
||||
|
||||
Reference in New Issue
Block a user