mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 01:46:11 -04:00
Move switch service registration to services module (#182565)
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import override
|
||||
from propcache.api import cached_property
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
from homeassistant.const import ( # noqa: F401
|
||||
SERVICE_TOGGLE,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
@@ -18,13 +18,17 @@ from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DEVICE_CLASSES_SCHEMA, DOMAIN, SwitchDeviceClass # noqa: F401
|
||||
from .const import ( # noqa: F401
|
||||
DATA_COMPONENT,
|
||||
DEVICE_CLASSES_SCHEMA,
|
||||
DOMAIN,
|
||||
SwitchDeviceClass,
|
||||
)
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DATA_COMPONENT: HassKey[EntityComponent[SwitchEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
@@ -53,9 +57,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
||||
component.async_register_entity_service(SERVICE_TURN_OFF, None, "async_turn_off")
|
||||
component.async_register_entity_service(SERVICE_TURN_ON, None, "async_turn_on")
|
||||
component.async_register_entity_service(SERVICE_TOGGLE, None, "async_toggle")
|
||||
async_setup_services(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
"""Constants for the Switch integration."""
|
||||
|
||||
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 SwitchEntity
|
||||
|
||||
DOMAIN: Final = "switch"
|
||||
DATA_COMPONENT: HassKey[EntityComponent[SwitchEntity]] = HassKey(DOMAIN)
|
||||
|
||||
|
||||
class SwitchDeviceClass(StrEnum):
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
"""Services for the Switch integration."""
|
||||
|
||||
from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from .const import DATA_COMPONENT
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register the switch services."""
|
||||
component = hass.data[DATA_COMPONENT]
|
||||
|
||||
component.async_register_entity_service(SERVICE_TURN_OFF, None, "async_turn_off")
|
||||
component.async_register_entity_service(SERVICE_TURN_ON, None, "async_turn_on")
|
||||
component.async_register_entity_service(SERVICE_TOGGLE, None, "async_toggle")
|
||||
Reference in New Issue
Block a user