mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 17:31:15 -04:00
Move scene service registration to services module (#182564)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
Reference in New Issue
Block a user