2020-06-25 20:17:05 +00:00
|
|
|
"""Describe logbook events."""
|
2022-07-07 17:46:19 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Any
|
2020-06-25 20:17:05 +00:00
|
|
|
|
2022-09-08 10:24:45 +00:00
|
|
|
from homeassistant.components.logbook import (
|
2022-05-23 18:35:45 +00:00
|
|
|
LOGBOOK_ENTRY_ENTITY_ID,
|
|
|
|
LOGBOOK_ENTRY_MESSAGE,
|
|
|
|
LOGBOOK_ENTRY_NAME,
|
|
|
|
)
|
2020-06-26 06:29:22 +00:00
|
|
|
from homeassistant.const import ATTR_ENTITY_ID
|
2020-06-25 20:17:05 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
|
|
|
|
from .const import DOMAIN, DOOR_STATION, DOOR_STATION_EVENT_ENTITY_IDS
|
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def async_describe_events(hass, async_describe_event):
|
|
|
|
"""Describe logbook events."""
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def async_describe_logbook_event(event):
|
|
|
|
"""Describe a logbook event."""
|
2020-11-28 23:44:25 +00:00
|
|
|
doorbird_event = event.event_type.split("_", 1)[1]
|
2020-06-25 20:17:05 +00:00
|
|
|
|
|
|
|
return {
|
2022-05-23 18:35:45 +00:00
|
|
|
LOGBOOK_ENTRY_NAME: "Doorbird",
|
|
|
|
LOGBOOK_ENTRY_MESSAGE: f"Event {event.event_type} was fired",
|
|
|
|
LOGBOOK_ENTRY_ENTITY_ID: hass.data[DOMAIN][
|
|
|
|
DOOR_STATION_EVENT_ENTITY_IDS
|
|
|
|
].get(doorbird_event, event.data.get(ATTR_ENTITY_ID)),
|
2020-06-25 20:17:05 +00:00
|
|
|
}
|
|
|
|
|
2022-07-07 17:46:19 +00:00
|
|
|
domain_data: dict[str, Any] = hass.data[DOMAIN]
|
2020-06-25 20:17:05 +00:00
|
|
|
|
2022-07-07 17:46:19 +00:00
|
|
|
for data in domain_data.values():
|
|
|
|
if DOOR_STATION not in data:
|
|
|
|
# We need to skip door_station_event_entity_ids
|
|
|
|
continue
|
|
|
|
for event in data[DOOR_STATION].doorstation_events:
|
2020-06-25 20:17:05 +00:00
|
|
|
async_describe_event(
|
|
|
|
DOMAIN, f"{DOMAIN}_{event}", async_describe_logbook_event
|
|
|
|
)
|