Move button service registration to services module (#182563)

This commit is contained in:
epenet
2026-09-18 20:48:26 +02:00
committed by GitHub
parent d3e91e2c10
commit 3bf54699b2
3 changed files with 27 additions and 8 deletions
+3 -7
View File
@@ -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
+9 -1
View File
@@ -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",
)