mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""Describe logbook events."""
|
|
from homeassistant.components.logbook.const import (
|
|
LOGBOOK_ENTRY_ENTITY_ID,
|
|
LOGBOOK_ENTRY_MESSAGE,
|
|
LOGBOOK_ENTRY_NAME,
|
|
)
|
|
from homeassistant.core import callback
|
|
|
|
from .const import DOMAIN, EVENT_ALEXA_SMART_HOME
|
|
|
|
|
|
@callback
|
|
def async_describe_events(hass, async_describe_event):
|
|
"""Describe logbook events."""
|
|
|
|
@callback
|
|
def async_describe_logbook_event(event):
|
|
"""Describe a logbook event."""
|
|
data = event.data
|
|
|
|
if entity_id := data["request"].get("entity_id"):
|
|
state = hass.states.get(entity_id)
|
|
name = state.name if state else entity_id
|
|
message = f"sent command {data['request']['namespace']}/{data['request']['name']} for {name}"
|
|
else:
|
|
message = (
|
|
f"sent command {data['request']['namespace']}/{data['request']['name']}"
|
|
)
|
|
|
|
return {
|
|
LOGBOOK_ENTRY_NAME: "Amazon Alexa",
|
|
LOGBOOK_ENTRY_MESSAGE: message,
|
|
LOGBOOK_ENTRY_ENTITY_ID: entity_id,
|
|
}
|
|
|
|
async_describe_event(DOMAIN, EVENT_ALEXA_SMART_HOME, async_describe_logbook_event)
|