mirror of
https://github.com/home-assistant/core.git
synced 2026-10-11 17:01:06 -04:00
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""Services for the input_boolean integration."""
|
|
|
|
import probatio
|
|
|
|
from homeassistant.const import (
|
|
CONF_ID,
|
|
SERVICE_RELOAD,
|
|
SERVICE_TOGGLE,
|
|
SERVICE_TURN_OFF,
|
|
SERVICE_TURN_ON,
|
|
)
|
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
|
from homeassistant.helpers.service import async_register_admin_service
|
|
|
|
from .const import DATA_INPUT_BOOLEAN, DOMAIN
|
|
|
|
RELOAD_SERVICE_SCHEMA = probatio.Schema({})
|
|
|
|
|
|
async def _async_reload_service(service_call: ServiceCall) -> None:
|
|
"""Remove all input booleans and load new ones from config."""
|
|
hass = service_call.hass
|
|
data = hass.data[DATA_INPUT_BOOLEAN]
|
|
conf = await data.component.async_prepare_reload(skip_reset=True)
|
|
await data.yaml_collection.async_load(
|
|
[{CONF_ID: id_, **(conf or {})} for id_, conf in conf.get(DOMAIN, {}).items()]
|
|
)
|
|
|
|
|
|
@callback
|
|
def async_setup_services(hass: HomeAssistant) -> None:
|
|
"""Register the input_boolean services."""
|
|
async_register_admin_service(
|
|
hass,
|
|
DOMAIN,
|
|
SERVICE_RELOAD,
|
|
_async_reload_service,
|
|
schema=RELOAD_SERVICE_SCHEMA,
|
|
)
|
|
|
|
component = hass.data[DATA_INPUT_BOOLEAN].component
|
|
component.async_register_entity_service(SERVICE_TURN_ON, None, "async_turn_on")
|
|
component.async_register_entity_service(SERVICE_TURN_OFF, None, "async_turn_off")
|
|
component.async_register_entity_service(SERVICE_TOGGLE, None, "async_toggle")
|