1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-14 10:03:52 +01:00
Files

38 lines
1.2 KiB
Python

"""Support for Google Assistant services."""
import logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import service
from .const import DOMAIN, SERVICE_REQUEST_SYNC
from .http import GoogleConfig
_LOGGER = logging.getLogger(__name__)
@callback
def async_register_services(hass: HomeAssistant) -> None:
"""Register Google Assistant services."""
async def request_sync_service_handler(call: ServiceCall) -> None:
"""Handle request sync service calls."""
agent_user_id = call.data.get("agent_user_id") or call.context.user_id
if agent_user_id is None:
_LOGGER.warning(
"No agent_user_id supplied for request_sync. Call as a user or pass in"
" user id as agent_user_id"
)
return
entry: ConfigEntry[GoogleConfig] = service.async_get_config_entry(
hass, DOMAIN, None
)
await entry.runtime_data.async_sync_entities(agent_user_id)
hass.services.async_register(
DOMAIN, SERVICE_REQUEST_SYNC, request_sync_service_handler
)