diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index be8b4e0f1528..9f28a650ff54 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -7,20 +7,23 @@ from typing import Any, Final, final, override import probatio -from homeassistant.components.light import ATTR_TRANSITION +from homeassistant.components.light import ATTR_TRANSITION # noqa: F401 from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_PLATFORM, SERVICE_TURN_ON, STATE_UNAVAILABLE +from homeassistant.const import ( # noqa: F401 + CONF_PLATFORM, + SERVICE_TURN_ON, + STATE_UNAVAILABLE, +) from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback 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.async_ import run_callback_threadsafe -from homeassistant.util.hass_dict import HassKey -from .const import DOMAIN +from .const import DATA_COMPONENT, DOMAIN +from .services import async_setup_services -DATA_COMPONENT: HassKey[EntityComponent[BaseScene]] = HassKey(DOMAIN) STATES: Final = "states" @@ -76,15 +79,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: ), eager_start=True, ) - component.async_register_entity_service( - SERVICE_TURN_ON, - { - ATTR_TRANSITION: probatio.All( - probatio.Coerce(float), probatio.Clamp(min=0, max=6553) - ) - }, - "_async_activate", - ) + async_setup_services(hass) return True diff --git a/homeassistant/components/scene/const.py b/homeassistant/components/scene/const.py index f2c09d553923..7de13d6e6267 100644 --- a/homeassistant/components/scene/const.py +++ b/homeassistant/components/scene/const.py @@ -1,5 +1,13 @@ """Constants for the scene integration.""" -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 BaseScene DOMAIN: Final = "scene" +DATA_COMPONENT: HassKey[EntityComponent[BaseScene]] = HassKey(DOMAIN) diff --git a/homeassistant/components/scene/services.py b/homeassistant/components/scene/services.py new file mode 100644 index 000000000000..adeb9fd0c477 --- /dev/null +++ b/homeassistant/components/scene/services.py @@ -0,0 +1,23 @@ +"""Services for the Scene integration.""" + +import probatio + +from homeassistant.components.light import ATTR_TRANSITION +from homeassistant.const import SERVICE_TURN_ON +from homeassistant.core import HomeAssistant, callback + +from .const import DATA_COMPONENT + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Register the scene services.""" + hass.data[DATA_COMPONENT].async_register_entity_service( + SERVICE_TURN_ON, + { + ATTR_TRANSITION: probatio.All( + probatio.Coerce(float), probatio.Clamp(min=0, max=6553) + ) + }, + "_async_activate", + )