example-custom-config/custom_components/expose_service_sync/__init__.py

25 lines
802 B
Python

"""Example of a custom component exposing a service."""
from __future__ import annotations
import logging
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers.typing import ConfigType
# The domain of your component. Should be equal to the name of your component.
DOMAIN = "expose_service_sync"
_LOGGER = logging.getLogger(__name__)
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the sync service example component."""
def my_service(call: ServiceCall) -> None:
"""My first service."""
_LOGGER.info('Received data', call.data)
# Register our service with Home Assistant.
hass.services.register(DOMAIN, 'demo', my_service)
# Return boolean to indicate that initialization was successfully.
return True