mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
Move button service registration to services module (#182563)
This commit is contained in:
@@ -15,18 +15,18 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import ( # noqa: F401
|
||||
DATA_COMPONENT,
|
||||
DEVICE_CLASSES_SCHEMA,
|
||||
DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
ButtonDeviceClass,
|
||||
)
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DATA_COMPONENT: HassKey[EntityComponent[ButtonEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
@@ -45,11 +45,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_PRESS,
|
||||
None,
|
||||
"_async_press_action",
|
||||
)
|
||||
async_setup_services(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
"""Provides the constants needed for the component."""
|
||||
|
||||
from enum import StrEnum
|
||||
from typing import Final
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
||||
from . import ButtonEntity
|
||||
|
||||
DOMAIN: Final = "button"
|
||||
DATA_COMPONENT: HassKey[EntityComponent[ButtonEntity]] = HassKey(DOMAIN)
|
||||
|
||||
SERVICE_PRESS = "press"
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
"""Services for the Button integration."""
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from .const import DATA_COMPONENT, SERVICE_PRESS
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register the button services."""
|
||||
hass.data[DATA_COMPONENT].async_register_entity_service(
|
||||
SERVICE_PRESS,
|
||||
None,
|
||||
"_async_press_action",
|
||||
)
|
||||
Reference in New Issue
Block a user