mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 05:06:13 +01:00
Move epson service registration (#162124)
This commit is contained in:
@@ -11,11 +11,15 @@ from epson_projector.const import (
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import CONF_CONNECTION_TYPE, HTTP
|
||||
from .const import CONF_CONNECTION_TYPE, DOMAIN, HTTP
|
||||
from .exceptions import CannotConnect, PoweredOff
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -47,6 +51,12 @@ async def validate_projector(
|
||||
return epson_proj
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the component."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: EpsonConfigEntry) -> bool:
|
||||
"""Set up epson from a config entry."""
|
||||
projector = await validate_projector(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Constants for the epson integration."""
|
||||
|
||||
DOMAIN = "epson"
|
||||
SERVICE_SELECT_CMODE = "select_cmode"
|
||||
|
||||
CONF_CONNECTION_TYPE = "connection_type"
|
||||
|
||||
ATTR_CMODE = "cmode"
|
||||
|
||||
@@ -27,7 +27,6 @@ from epson_projector.const import (
|
||||
VOL_UP,
|
||||
VOLUME,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
MediaPlayerEntity,
|
||||
@@ -36,17 +35,12 @@ from homeassistant.components.media_player import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
device_registry as dr,
|
||||
entity_platform,
|
||||
entity_registry as er,
|
||||
)
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import EpsonConfigEntry
|
||||
from .const import ATTR_CMODE, DOMAIN, SERVICE_SELECT_CMODE
|
||||
from .const import ATTR_CMODE, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -63,12 +57,6 @@ async def async_setup_entry(
|
||||
entry=config_entry,
|
||||
)
|
||||
async_add_entities([projector_entity], True)
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SELECT_CMODE,
|
||||
{vol.Required(ATTR_CMODE): vol.All(cv.string, vol.Any(*CMODE_LIST_SET))},
|
||||
SERVICE_SELECT_CMODE,
|
||||
)
|
||||
|
||||
|
||||
class EpsonProjectorMediaPlayer(MediaPlayerEntity):
|
||||
|
||||
27
homeassistant/components/epson/services.py
Normal file
27
homeassistant/components/epson/services.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Support for Epson projector."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from epson_projector.const import CMODE_LIST_SET
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import ATTR_CMODE, DOMAIN
|
||||
|
||||
SERVICE_SELECT_CMODE = "select_cmode"
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up services."""
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SELECT_CMODE,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema={vol.Required(ATTR_CMODE): vol.All(cv.string, vol.Any(*CMODE_LIST_SET))},
|
||||
func=SERVICE_SELECT_CMODE,
|
||||
)
|
||||
Reference in New Issue
Block a user