Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion homeassistant/components/alexa/logbook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""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
Expand All @@ -22,6 +27,10 @@ def async_describe_logbook_event(event):
f"sent command {data['request']['namespace']}/{data['request']['name']}"
)

return {"name": "Amazon Alexa", "message": message, "entity_id": entity_id}
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)
17 changes: 12 additions & 5 deletions homeassistant/components/automation/logbook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""Describe logbook events."""
from homeassistant.components.logbook import LazyEventPartialState
from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_CONTEXT_ID,
LOGBOOK_ENTRY_ENTITY_ID,
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
LOGBOOK_ENTRY_SOURCE,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_NAME
from homeassistant.core import HomeAssistant, callback

Expand All @@ -20,11 +27,11 @@ def async_describe_logbook_event(event: LazyEventPartialState): # type: ignore[
message = f"{message} by {data[ATTR_SOURCE]}"

return {
"name": data.get(ATTR_NAME),
"message": message,
"source": data.get(ATTR_SOURCE),
"entity_id": data.get(ATTR_ENTITY_ID),
"context_id": event.context_id,
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,
}

async_describe_event(
Expand Down
24 changes: 14 additions & 10 deletions homeassistant/components/deconz/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

from collections.abc import Callable

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.const import ATTR_DEVICE_ID, CONF_EVENT
from homeassistant.core import Event, HomeAssistant, callback
import homeassistant.helpers.device_registry as dr
Expand Down Expand Up @@ -135,8 +139,8 @@ def async_describe_deconz_alarm_event(event: Event) -> dict[str, str]:
data = event.data[CONF_EVENT]

return {
"name": f"{deconz_alarm_event.device.name}",
"message": f"fired event '{data}'",
LOGBOOK_ENTRY_NAME: f"{deconz_alarm_event.device.name}",
LOGBOOK_ENTRY_MESSAGE: f"fired event '{data}'",
}

@callback
Expand All @@ -157,27 +161,27 @@ def async_describe_deconz_event(event: Event) -> dict[str, str]:
# Unknown event
if not data:
return {
"name": f"{deconz_event.device.name}",
"message": "fired an unknown event",
LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
LOGBOOK_ENTRY_MESSAGE: "fired an unknown event",
}

# No device event match
if not action:
return {
"name": f"{deconz_event.device.name}",
"message": f"fired event '{data}'",
LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
LOGBOOK_ENTRY_MESSAGE: f"fired event '{data}'",
}

# Gesture event
if not interface:
return {
"name": f"{deconz_event.device.name}",
"message": f"fired event '{ACTIONS[action]}'",
LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
LOGBOOK_ENTRY_MESSAGE: f"fired event '{ACTIONS[action]}'",
}

return {
"name": f"{deconz_event.device.name}",
"message": f"'{ACTIONS[action]}' event for '{INTERFACES[interface]}' was fired",
LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
LOGBOOK_ENTRY_MESSAGE: f"'{ACTIONS[action]}' event for '{INTERFACES[interface]}' was fired",
}

async_describe_event(
Expand Down
15 changes: 10 additions & 5 deletions homeassistant/components/doorbird/logbook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Describe logbook events."""

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_ENTITY_ID,
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import callback

Expand All @@ -16,11 +21,11 @@ def async_describe_logbook_event(event):
doorbird_event = event.event_type.split("_", 1)[1]

return {
"name": "Doorbird",
"message": f"Event {event.event_type} was fired",
"entity_id": hass.data[DOMAIN][DOOR_STATION_EVENT_ENTITY_IDS].get(
doorbird_event, event.data.get(ATTR_ENTITY_ID)
),
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)),
}

domain_data = hass.data[DOMAIN]
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/elkm1/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

from collections.abc import Callable

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.core import Event, HomeAssistant, callback

from .const import (
Expand Down Expand Up @@ -30,8 +34,8 @@ def async_describe_button_event(event: Event) -> dict[str, str]:
ATTR_KEYPAD_NAME, data[ATTR_KEYPAD_ID]
) # added in 2022.6
return {
"name": f"Elk Keypad {keypad_name}",
"message": f"pressed {data[ATTR_KEY_NAME]} ({data[ATTR_KEY]})",
LOGBOOK_ENTRY_NAME: f"Elk Keypad {keypad_name}",
LOGBOOK_ENTRY_MESSAGE: f"pressed {data[ATTR_KEY_NAME]} ({data[ATTR_KEY]})",
}

async_describe_event(
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/google_assistant/logbook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Describe logbook events."""
from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.core import callback

from .const import DOMAIN, EVENT_COMMAND_RECEIVED, SOURCE_CLOUD
Expand All @@ -25,6 +29,6 @@ def async_describe_logbook_event(event):
if event.data["source"] != SOURCE_CLOUD:
message += f" (via {event.data['source']})"

return {"name": "Google Assistant", "message": message}
return {LOGBOOK_ENTRY_NAME: "Google Assistant", LOGBOOK_ENTRY_MESSAGE: message}

async_describe_event(DOMAIN, EVENT_COMMAND_RECEIVED, async_describe_logbook_event)
2 changes: 1 addition & 1 deletion homeassistant/components/homeassistant/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from collections.abc import Callable

from homeassistant.components.logbook import (
from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_ICON,
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
Expand Down
11 changes: 8 additions & 3 deletions homeassistant/components/homekit/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from collections.abc import Callable
from typing import Any

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_ENTITY_ID,
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_SERVICE
from homeassistant.core import Event, HomeAssistant, callback

Expand All @@ -26,9 +31,9 @@ def async_describe_logbook_event(event: Event) -> dict[str, Any]:
message = f"send command {data[ATTR_SERVICE]}{value_msg} for {data[ATTR_DISPLAY_NAME]}"

return {
"name": "HomeKit",
"message": message,
"entity_id": entity_id,
LOGBOOK_ENTRY_NAME: "HomeKit",
LOGBOOK_ENTRY_MESSAGE: message,
LOGBOOK_ENTRY_ENTITY_ID: entity_id,
}

async_describe_event(DOMAIN, EVENT_HOMEKIT_CHANGED, async_describe_logbook_event)
8 changes: 6 additions & 2 deletions homeassistant/components/hue/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

from collections.abc import Callable

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.const import CONF_DEVICE_ID, CONF_EVENT, CONF_ID, CONF_TYPE
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
Expand Down Expand Up @@ -66,8 +70,8 @@ def async_describe_hue_event(event: Event) -> dict[str, str]:
else:
message = f"Event {data[CONF_EVENT]}" # v1
return {
"name": name,
"message": str(message),
LOGBOOK_ENTRY_NAME: name,
LOGBOOK_ENTRY_MESSAGE: message,
}

async_describe_event(DOMAIN, ATTR_HUE_EVENT, async_describe_hue_event)
1 change: 0 additions & 1 deletion homeassistant/components/logbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
LOGBOOK_ENTRY_NAME,
LOGBOOK_FILTERS,
)
from .const import LOGBOOK_ENTRY_ICON # noqa: F401
from .models import LazyEventPartialState # noqa: F401

CONFIG_SCHEMA = vol.Schema(
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/logbook/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
CONTEXT_EVENT_TYPE = "context_event_type"
CONTEXT_DOMAIN = "context_domain"
CONTEXT_STATE = "context_state"
CONTEXT_SOURCE = "context_source"
CONTEXT_SERVICE = "context_service"
CONTEXT_NAME = "context_name"
CONTEXT_MESSAGE = "context_message"

LOGBOOK_ENTRY_CONTEXT_ID = "context_id"
LOGBOOK_ENTRY_DOMAIN = "domain"
LOGBOOK_ENTRY_ENTITY_ID = "entity_id"
LOGBOOK_ENTRY_ICON = "icon"
LOGBOOK_ENTRY_SOURCE = "source"
LOGBOOK_ENTRY_MESSAGE = "message"
LOGBOOK_ENTRY_NAME = "name"
LOGBOOK_ENTRY_STATE = "state"
Expand Down
11 changes: 8 additions & 3 deletions homeassistant/components/logbook/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CONTEXT_MESSAGE,
CONTEXT_NAME,
CONTEXT_SERVICE,
CONTEXT_SOURCE,
CONTEXT_STATE,
CONTEXT_USER_ID,
DOMAIN,
Expand All @@ -51,6 +52,7 @@
LOGBOOK_ENTRY_ICON,
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
LOGBOOK_ENTRY_SOURCE,
LOGBOOK_ENTRY_STATE,
LOGBOOK_ENTRY_WHEN,
LOGBOOK_FILTERS,
Expand Down Expand Up @@ -398,11 +400,14 @@ def augment(
data[CONTEXT_DOMAIN] = domain
event = self.event_cache.get(context_row)
described = describe_event(event)
if name := described.get(ATTR_NAME):
if name := described.get(LOGBOOK_ENTRY_NAME):
data[CONTEXT_NAME] = name
if message := described.get(ATTR_MESSAGE):
if message := described.get(LOGBOOK_ENTRY_MESSAGE):
data[CONTEXT_MESSAGE] = message
if not (attr_entity_id := described.get(ATTR_ENTITY_ID)):
# In 2022.12 and later drop `CONTEXT_MESSAGE` if `CONTEXT_SOURCE` is available
if source := described.get(LOGBOOK_ENTRY_SOURCE):
data[CONTEXT_SOURCE] = source
if not (attr_entity_id := described.get(LOGBOOK_ENTRY_ENTITY_ID)):
return
data[CONTEXT_ENTITY_ID] = attr_entity_id
if self.include_entity_name:
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/lutron_caseta/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

from collections.abc import Callable

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.core import Event, HomeAssistant, callback

from .const import (
Expand Down Expand Up @@ -33,8 +37,8 @@ def async_describe_button_event(event: Event) -> dict[str, str]:
button_map = LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP[device_type]
button_description = button_map[leap_button_number]
return {
"name": f"{data[ATTR_AREA_NAME]} {data[ATTR_DEVICE_NAME]}",
"message": f"{data[ATTR_ACTION]} {button_description}",
LOGBOOK_ENTRY_NAME: f"{data[ATTR_AREA_NAME]} {data[ATTR_DEVICE_NAME]}",
LOGBOOK_ENTRY_MESSAGE: f"{data[ATTR_ACTION]} {button_description}",
}

async_describe_event(
Expand Down
14 changes: 10 additions & 4 deletions homeassistant/components/mobile_app/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

from collections.abc import Callable

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_ENTITY_ID,
LOGBOOK_ENTRY_ICON,
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_ICON
from homeassistant.core import Event, HomeAssistant, callback

Expand Down Expand Up @@ -42,12 +48,12 @@ def async_describe_zone_event(event: Event) -> dict[str, str]:
zone_name = zone_state.attributes.get(ATTR_FRIENDLY_NAME)
zone_icon = zone_state.attributes.get(ATTR_ICON)
description = {
"name": source_device_name,
"message": f"{event_description} {zone_name or zone_entity_id}",
"icon": zone_icon or "mdi:crosshairs-gps",
LOGBOOK_ENTRY_NAME: source_device_name,
LOGBOOK_ENTRY_MESSAGE: f"{event_description} {zone_name or zone_entity_id}",
LOGBOOK_ENTRY_ICON: zone_icon or "mdi:crosshairs-gps",
}
if zone_entity_id:
description["entity_id"] = zone_entity_id
description[LOGBOOK_ENTRY_ENTITY_ID] = zone_entity_id
return description

async_describe_event(DOMAIN, IOS_EVENT_ZONE_ENTERED, async_describe_zone_event)
Expand Down
14 changes: 10 additions & 4 deletions homeassistant/components/script/logbook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
"""Describe logbook events."""
from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_CONTEXT_ID,
LOGBOOK_ENTRY_ENTITY_ID,
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_NAME
from homeassistant.core import callback

Expand All @@ -14,10 +20,10 @@ def async_describe_logbook_event(event):
"""Describe the logbook event."""
data = event.data
return {
"name": data.get(ATTR_NAME),
"message": "started",
"entity_id": data.get(ATTR_ENTITY_ID),
"context_id": event.context_id,
LOGBOOK_ENTRY_NAME: data.get(ATTR_NAME),
LOGBOOK_ENTRY_MESSAGE: "started",
LOGBOOK_ENTRY_ENTITY_ID: data.get(ATTR_ENTITY_ID),
LOGBOOK_ENTRY_CONTEXT_ID: event.context_id,
}

async_describe_event(DOMAIN, EVENT_SCRIPT_STARTED, async_describe_logbook_event)
8 changes: 6 additions & 2 deletions homeassistant/components/shelly/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

from collections.abc import Callable

from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.const import ATTR_DEVICE_ID
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import EventType
Expand Down Expand Up @@ -48,8 +52,8 @@ def async_describe_shelly_click_event(event: EventType) -> dict[str, str]:
input_name = f"{device_name} channel {channel}"

return {
"name": "Shelly",
"message": f"'{click_type}' click event for {input_name} Input was fired",
LOGBOOK_ENTRY_NAME: "Shelly",
LOGBOOK_ENTRY_MESSAGE: f"'{click_type}' click event for {input_name} Input was fired",
}

async_describe_event(DOMAIN, EVENT_SHELLY_CLICK, async_describe_shelly_click_event)
Loading