2020-06-25 01:14:50 +00:00
|
|
|
"""Describe logbook events."""
|
2021-03-16 21:37:26 +00:00
|
|
|
from homeassistant.components.logbook import LazyEventPartialState
|
2022-05-23 18:35:45 +00:00
|
|
|
from homeassistant.components.logbook.const import (
|
|
|
|
LOGBOOK_ENTRY_CONTEXT_ID,
|
|
|
|
LOGBOOK_ENTRY_ENTITY_ID,
|
|
|
|
LOGBOOK_ENTRY_MESSAGE,
|
|
|
|
LOGBOOK_ENTRY_NAME,
|
|
|
|
LOGBOOK_ENTRY_SOURCE,
|
|
|
|
)
|
2020-06-25 01:14:50 +00:00
|
|
|
from homeassistant.const import ATTR_ENTITY_ID, ATTR_NAME
|
2021-03-16 21:37:26 +00:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-06-25 01:14:50 +00:00
|
|
|
|
2022-01-05 16:28:12 +00:00
|
|
|
from . import ATTR_SOURCE, EVENT_AUTOMATION_TRIGGERED
|
|
|
|
from .const import DOMAIN
|
2020-06-25 01:14:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@callback
|
2022-02-18 17:15:57 +00:00
|
|
|
def async_describe_events(hass: HomeAssistant, async_describe_event): # type: ignore[no-untyped-def]
|
2020-06-25 01:14:50 +00:00
|
|
|
"""Describe logbook events."""
|
|
|
|
|
|
|
|
@callback
|
2022-02-18 17:15:57 +00:00
|
|
|
def async_describe_logbook_event(event: LazyEventPartialState): # type: ignore[no-untyped-def]
|
2020-06-25 01:14:50 +00:00
|
|
|
"""Describe a logbook event."""
|
2020-08-30 07:20:31 +00:00
|
|
|
data = event.data
|
2022-05-13 00:21:14 +00:00
|
|
|
message = "triggered"
|
2020-08-30 07:20:31 +00:00
|
|
|
if ATTR_SOURCE in data:
|
|
|
|
message = f"{message} by {data[ATTR_SOURCE]}"
|
2021-03-16 21:37:26 +00:00
|
|
|
|
2020-06-25 01:14:50 +00:00
|
|
|
return {
|
2022-05-23 18:35:45 +00:00
|
|
|
LOGBOOK_ENTRY_NAME: data.get(ATTR_NAME),
|
|
|
|
LOGBOOK_ENTRY_MESSAGE: message,
|
|
|
|
LOGBOOK_ENTRY_SOURCE: data.get(ATTR_SOURCE),
|
|
|
|
LOGBOOK_ENTRY_ENTITY_ID: data.get(ATTR_ENTITY_ID),
|
|
|
|
LOGBOOK_ENTRY_CONTEXT_ID: event.context_id,
|
2020-06-25 01:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async_describe_event(
|
|
|
|
DOMAIN, EVENT_AUTOMATION_TRIGGERED, async_describe_logbook_event
|
|
|
|
)
|