Home Assistant Unofficial Reference 2024.12.1
logbook.py
Go to the documentation of this file.
1 """Describe logbook events."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable
6 
8  LOGBOOK_ENTRY_ENTITY_ID,
9  LOGBOOK_ENTRY_MESSAGE,
10  LOGBOOK_ENTRY_NAME,
11 )
12 from homeassistant.const import ATTR_ENTITY_ID
13 from homeassistant.core import Event, HomeAssistant, callback
14 
15 from .const import DOMAIN
16 from .util import async_get_entries
17 
18 
19 @callback
21  hass: HomeAssistant,
22  async_describe_event: Callable[
23  [str, str, Callable[[Event], dict[str, str | None]]], None
24  ],
25 ) -> None:
26  """Describe logbook events."""
27 
28  @callback
29  def async_describe_logbook_event(event: Event) -> dict[str, str | None]:
30  """Describe a logbook event."""
31  return {
32  LOGBOOK_ENTRY_NAME: "Doorbird",
33  LOGBOOK_ENTRY_MESSAGE: f"Event {event.event_type} was fired",
34  # Database entries before Jun 25th 2020 will not have an entity ID
35  LOGBOOK_ENTRY_ENTITY_ID: event.data.get(ATTR_ENTITY_ID),
36  }
37 
38  for entry in async_get_entries(hass):
39  data = entry.runtime_data
40  for event in data.door_station.door_station_events:
41  async_describe_event(
42  DOMAIN, f"{DOMAIN}_{event}", async_describe_logbook_event
43  )
None async_describe_events(HomeAssistant hass, Callable[[str, str, Callable[[Event], dict[str, str|None]]], None] async_describe_event)
Definition: logbook.py:25
list[DoorBirdConfigEntry] async_get_entries(HomeAssistant hass)
Definition: util.py:29