mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 01:11:51 -04:00
Move select service registration to services module (#182830)
This commit is contained in:
@@ -4,7 +4,6 @@ from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any, final, override
|
||||
|
||||
import probatio
|
||||
from propcache.api import cached_property
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@@ -15,11 +14,11 @@ from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import (
|
||||
ATTR_CYCLE,
|
||||
ATTR_OPTIONS,
|
||||
DATA_COMPONENT,
|
||||
DOMAIN,
|
||||
SERVICE_SELECT_FIRST,
|
||||
SERVICE_SELECT_LAST,
|
||||
@@ -27,10 +26,10 @@ from .const import (
|
||||
SERVICE_SELECT_PREVIOUS,
|
||||
SelectEntityCapabilityAttribute,
|
||||
)
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DATA_COMPONENT: HassKey[EntityComponent[SelectEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
@@ -65,35 +64,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_FIRST,
|
||||
None,
|
||||
SelectEntity.async_first.__name__,
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_LAST,
|
||||
None,
|
||||
SelectEntity.async_last.__name__,
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_NEXT,
|
||||
{probatio.Optional(ATTR_CYCLE, default=True): bool},
|
||||
SelectEntity.async_next.__name__,
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_OPTION,
|
||||
{probatio.Required(ATTR_OPTION): cv.string},
|
||||
SelectEntity.async_handle_select_option.__name__,
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_PREVIOUS,
|
||||
{probatio.Optional(ATTR_CYCLE, default=True): bool},
|
||||
SelectEntity.async_previous.__name__,
|
||||
)
|
||||
async_setup_services(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
"""Provides the constants needed for the component."""
|
||||
|
||||
from enum import StrEnum
|
||||
from typing import Final
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
||||
from . import SelectEntity
|
||||
|
||||
DOMAIN: Final = "select"
|
||||
DATA_COMPONENT: HassKey[EntityComponent[SelectEntity]] = HassKey(DOMAIN)
|
||||
|
||||
|
||||
class SelectEntityCapabilityAttribute(StrEnum):
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
"""Services for the Select integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.const import ATTR_OPTION, SERVICE_SELECT_OPTION
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
from .const import (
|
||||
ATTR_CYCLE,
|
||||
DATA_COMPONENT,
|
||||
SERVICE_SELECT_FIRST,
|
||||
SERVICE_SELECT_LAST,
|
||||
SERVICE_SELECT_NEXT,
|
||||
SERVICE_SELECT_PREVIOUS,
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register the select services."""
|
||||
component = hass.data[DATA_COMPONENT]
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_FIRST,
|
||||
None,
|
||||
"async_first",
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_LAST,
|
||||
None,
|
||||
"async_last",
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_NEXT,
|
||||
{probatio.Optional(ATTR_CYCLE, default=True): bool},
|
||||
"async_next",
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_OPTION,
|
||||
{probatio.Required(ATTR_OPTION): cv.string},
|
||||
"async_handle_select_option",
|
||||
)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_PREVIOUS,
|
||||
{probatio.Optional(ATTR_CYCLE, default=True): bool},
|
||||
"async_previous",
|
||||
)
|
||||
Reference in New Issue
Block a user