From 3bf54699b21e1bd3919cf155e262bd41d3a20bbe Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 18 Sep 2026 20:48:26 +0200 Subject: [PATCH] Move button service registration to services module (#182563) --- homeassistant/components/button/__init__.py | 10 +++------- homeassistant/components/button/const.py | 10 +++++++++- homeassistant/components/button/services.py | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 homeassistant/components/button/services.py diff --git a/homeassistant/components/button/__init__.py b/homeassistant/components/button/__init__.py index 946f6e15d2d4..fb9bdc44be99 100644 --- a/homeassistant/components/button/__init__.py +++ b/homeassistant/components/button/__init__.py @@ -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 diff --git a/homeassistant/components/button/const.py b/homeassistant/components/button/const.py index 25d40bacb523..05fee14e7728 100644 --- a/homeassistant/components/button/const.py +++ b/homeassistant/components/button/const.py @@ -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" diff --git a/homeassistant/components/button/services.py b/homeassistant/components/button/services.py new file mode 100644 index 000000000000..4ef5de7745b6 --- /dev/null +++ b/homeassistant/components/button/services.py @@ -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", + )