2021-04-13 16:31:01 +00:00
|
|
|
"""Describe logbook events."""
|
2022-09-08 10:24:45 +00:00
|
|
|
from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME
|
2021-04-13 16:31:01 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
|
2021-04-20 16:21:52 +00:00
|
|
|
from .const import DOMAIN, EVENT_COMMAND_RECEIVED, SOURCE_CLOUD
|
2021-04-13 16:31:01 +00:00
|
|
|
|
|
|
|
COMMON_COMMAND_PREFIX = "action.devices.commands."
|
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def async_describe_events(hass, async_describe_event):
|
|
|
|
"""Describe logbook events."""
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def async_describe_logbook_event(event):
|
|
|
|
"""Describe a logbook event."""
|
2021-04-20 16:21:52 +00:00
|
|
|
commands = []
|
2021-04-13 16:31:01 +00:00
|
|
|
|
2021-04-20 16:21:52 +00:00
|
|
|
for command_payload in event.data["execution"]:
|
2023-01-13 11:19:38 +00:00
|
|
|
command = command_payload["command"].removeprefix(COMMON_COMMAND_PREFIX)
|
2021-04-20 16:21:52 +00:00
|
|
|
commands.append(command)
|
2021-04-13 16:31:01 +00:00
|
|
|
|
2021-04-20 16:21:52 +00:00
|
|
|
message = f"sent command {', '.join(commands)}"
|
|
|
|
if event.data["source"] != SOURCE_CLOUD:
|
|
|
|
message += f" (via {event.data['source']})"
|
2021-04-13 16:31:01 +00:00
|
|
|
|
2022-05-23 18:35:45 +00:00
|
|
|
return {LOGBOOK_ENTRY_NAME: "Google Assistant", LOGBOOK_ENTRY_MESSAGE: message}
|
2021-04-13 16:31:01 +00:00
|
|
|
|
|
|
|
async_describe_event(DOMAIN, EVENT_COMMAND_RECEIVED, async_describe_logbook_event)
|