Always pass the source of the trigger for logbook context messages (#72333)

This commit is contained in:
J. Nick Koston 2022-05-23 13:35:45 -05:00 committed by GitHub
parent f6370d0522
commit 0248a8710f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 145 additions and 59 deletions

View file

@ -1,4 +1,9 @@
"""Describe logbook events.""" """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 homeassistant.core import callback
from .const import DOMAIN, EVENT_ALEXA_SMART_HOME from .const import DOMAIN, EVENT_ALEXA_SMART_HOME
@ -22,6 +27,10 @@ def async_describe_events(hass, async_describe_event):
f"sent command {data['request']['namespace']}/{data['request']['name']}" 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) async_describe_event(DOMAIN, EVENT_ALEXA_SMART_HOME, async_describe_logbook_event)

View file

@ -1,5 +1,12 @@
"""Describe logbook events.""" """Describe logbook events."""
from homeassistant.components.logbook import LazyEventPartialState 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.const import ATTR_ENTITY_ID, ATTR_NAME
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
@ -20,11 +27,11 @@ def async_describe_events(hass: HomeAssistant, async_describe_event): # type: i
message = f"{message} by {data[ATTR_SOURCE]}" message = f"{message} by {data[ATTR_SOURCE]}"
return { return {
"name": data.get(ATTR_NAME), LOGBOOK_ENTRY_NAME: data.get(ATTR_NAME),
"message": message, LOGBOOK_ENTRY_MESSAGE: message,
"source": data.get(ATTR_SOURCE), LOGBOOK_ENTRY_SOURCE: data.get(ATTR_SOURCE),
"entity_id": data.get(ATTR_ENTITY_ID), LOGBOOK_ENTRY_ENTITY_ID: data.get(ATTR_ENTITY_ID),
"context_id": event.context_id, LOGBOOK_ENTRY_CONTEXT_ID: event.context_id,
} }
async_describe_event( async_describe_event(

View file

@ -3,6 +3,10 @@ from __future__ import annotations
from collections.abc import Callable 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.const import ATTR_DEVICE_ID, CONF_EVENT
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
@ -135,8 +139,8 @@ def async_describe_events(
data = event.data[CONF_EVENT] data = event.data[CONF_EVENT]
return { return {
"name": f"{deconz_alarm_event.device.name}", LOGBOOK_ENTRY_NAME: f"{deconz_alarm_event.device.name}",
"message": f"fired event '{data}'", LOGBOOK_ENTRY_MESSAGE: f"fired event '{data}'",
} }
@callback @callback
@ -157,27 +161,27 @@ def async_describe_events(
# Unknown event # Unknown event
if not data: if not data:
return { return {
"name": f"{deconz_event.device.name}", LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
"message": "fired an unknown event", LOGBOOK_ENTRY_MESSAGE: "fired an unknown event",
} }
# No device event match # No device event match
if not action: if not action:
return { return {
"name": f"{deconz_event.device.name}", LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
"message": f"fired event '{data}'", LOGBOOK_ENTRY_MESSAGE: f"fired event '{data}'",
} }
# Gesture event # Gesture event
if not interface: if not interface:
return { return {
"name": f"{deconz_event.device.name}", LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
"message": f"fired event '{ACTIONS[action]}'", LOGBOOK_ENTRY_MESSAGE: f"fired event '{ACTIONS[action]}'",
} }
return { return {
"name": f"{deconz_event.device.name}", LOGBOOK_ENTRY_NAME: f"{deconz_event.device.name}",
"message": f"'{ACTIONS[action]}' event for '{INTERFACES[interface]}' was fired", LOGBOOK_ENTRY_MESSAGE: f"'{ACTIONS[action]}' event for '{INTERFACES[interface]}' was fired",
} }
async_describe_event( async_describe_event(

View file

@ -1,5 +1,10 @@
"""Describe logbook events.""" """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.const import ATTR_ENTITY_ID
from homeassistant.core import callback from homeassistant.core import callback
@ -16,11 +21,11 @@ def async_describe_events(hass, async_describe_event):
doorbird_event = event.event_type.split("_", 1)[1] doorbird_event = event.event_type.split("_", 1)[1]
return { return {
"name": "Doorbird", LOGBOOK_ENTRY_NAME: "Doorbird",
"message": f"Event {event.event_type} was fired", LOGBOOK_ENTRY_MESSAGE: f"Event {event.event_type} was fired",
"entity_id": hass.data[DOMAIN][DOOR_STATION_EVENT_ENTITY_IDS].get( LOGBOOK_ENTRY_ENTITY_ID: hass.data[DOMAIN][
doorbird_event, event.data.get(ATTR_ENTITY_ID) DOOR_STATION_EVENT_ENTITY_IDS
), ].get(doorbird_event, event.data.get(ATTR_ENTITY_ID)),
} }
domain_data = hass.data[DOMAIN] domain_data = hass.data[DOMAIN]

View file

@ -3,6 +3,10 @@ from __future__ import annotations
from collections.abc import Callable 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 homeassistant.core import Event, HomeAssistant, callback
from .const import ( from .const import (
@ -30,8 +34,8 @@ def async_describe_events(
ATTR_KEYPAD_NAME, data[ATTR_KEYPAD_ID] ATTR_KEYPAD_NAME, data[ATTR_KEYPAD_ID]
) # added in 2022.6 ) # added in 2022.6
return { return {
"name": f"Elk Keypad {keypad_name}", LOGBOOK_ENTRY_NAME: f"Elk Keypad {keypad_name}",
"message": f"pressed {data[ATTR_KEY_NAME]} ({data[ATTR_KEY]})", LOGBOOK_ENTRY_MESSAGE: f"pressed {data[ATTR_KEY_NAME]} ({data[ATTR_KEY]})",
} }
async_describe_event( async_describe_event(

View file

@ -1,4 +1,8 @@
"""Describe logbook events.""" """Describe logbook events."""
from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME,
)
from homeassistant.core import callback from homeassistant.core import callback
from .const import DOMAIN, EVENT_COMMAND_RECEIVED, SOURCE_CLOUD from .const import DOMAIN, EVENT_COMMAND_RECEIVED, SOURCE_CLOUD
@ -25,6 +29,6 @@ def async_describe_events(hass, async_describe_event):
if event.data["source"] != SOURCE_CLOUD: if event.data["source"] != SOURCE_CLOUD:
message += f" (via {event.data['source']})" 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) async_describe_event(DOMAIN, EVENT_COMMAND_RECEIVED, async_describe_logbook_event)

View file

@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from homeassistant.components.logbook import ( from homeassistant.components.logbook.const import (
LOGBOOK_ENTRY_ICON, LOGBOOK_ENTRY_ICON,
LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME, LOGBOOK_ENTRY_NAME,

View file

@ -2,6 +2,11 @@
from collections.abc import Callable from collections.abc import Callable
from typing import Any 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.const import ATTR_ENTITY_ID, ATTR_SERVICE
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
@ -26,9 +31,9 @@ def async_describe_events(
message = f"send command {data[ATTR_SERVICE]}{value_msg} for {data[ATTR_DISPLAY_NAME]}" message = f"send command {data[ATTR_SERVICE]}{value_msg} for {data[ATTR_DISPLAY_NAME]}"
return { return {
"name": "HomeKit", LOGBOOK_ENTRY_NAME: "HomeKit",
"message": message, LOGBOOK_ENTRY_MESSAGE: message,
"entity_id": entity_id, LOGBOOK_ENTRY_ENTITY_ID: entity_id,
} }
async_describe_event(DOMAIN, EVENT_HOMEKIT_CHANGED, async_describe_logbook_event) async_describe_event(DOMAIN, EVENT_HOMEKIT_CHANGED, async_describe_logbook_event)

View file

@ -3,6 +3,10 @@ from __future__ import annotations
from collections.abc import Callable 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.const import CONF_DEVICE_ID, CONF_EVENT, CONF_ID, CONF_TYPE
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
@ -66,8 +70,8 @@ def async_describe_events(
else: else:
message = f"Event {data[CONF_EVENT]}" # v1 message = f"Event {data[CONF_EVENT]}" # v1
return { return {
"name": name, LOGBOOK_ENTRY_NAME: name,
"message": str(message), LOGBOOK_ENTRY_MESSAGE: message,
} }
async_describe_event(DOMAIN, ATTR_HUE_EVENT, async_describe_hue_event) async_describe_event(DOMAIN, ATTR_HUE_EVENT, async_describe_hue_event)

View file

@ -39,7 +39,6 @@ from .const import (
LOGBOOK_ENTRY_NAME, LOGBOOK_ENTRY_NAME,
LOGBOOK_FILTERS, LOGBOOK_FILTERS,
) )
from .const import LOGBOOK_ENTRY_ICON # noqa: F401
from .models import LazyEventPartialState # noqa: F401 from .models import LazyEventPartialState # noqa: F401
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = vol.Schema(

View file

@ -15,13 +15,16 @@ CONTEXT_ENTITY_ID_NAME = "context_entity_id_name"
CONTEXT_EVENT_TYPE = "context_event_type" CONTEXT_EVENT_TYPE = "context_event_type"
CONTEXT_DOMAIN = "context_domain" CONTEXT_DOMAIN = "context_domain"
CONTEXT_STATE = "context_state" CONTEXT_STATE = "context_state"
CONTEXT_SOURCE = "context_source"
CONTEXT_SERVICE = "context_service" CONTEXT_SERVICE = "context_service"
CONTEXT_NAME = "context_name" CONTEXT_NAME = "context_name"
CONTEXT_MESSAGE = "context_message" CONTEXT_MESSAGE = "context_message"
LOGBOOK_ENTRY_CONTEXT_ID = "context_id"
LOGBOOK_ENTRY_DOMAIN = "domain" LOGBOOK_ENTRY_DOMAIN = "domain"
LOGBOOK_ENTRY_ENTITY_ID = "entity_id" LOGBOOK_ENTRY_ENTITY_ID = "entity_id"
LOGBOOK_ENTRY_ICON = "icon" LOGBOOK_ENTRY_ICON = "icon"
LOGBOOK_ENTRY_SOURCE = "source"
LOGBOOK_ENTRY_MESSAGE = "message" LOGBOOK_ENTRY_MESSAGE = "message"
LOGBOOK_ENTRY_NAME = "name" LOGBOOK_ENTRY_NAME = "name"
LOGBOOK_ENTRY_STATE = "state" LOGBOOK_ENTRY_STATE = "state"

View file

@ -42,6 +42,7 @@ from .const import (
CONTEXT_MESSAGE, CONTEXT_MESSAGE,
CONTEXT_NAME, CONTEXT_NAME,
CONTEXT_SERVICE, CONTEXT_SERVICE,
CONTEXT_SOURCE,
CONTEXT_STATE, CONTEXT_STATE,
CONTEXT_USER_ID, CONTEXT_USER_ID,
DOMAIN, DOMAIN,
@ -51,6 +52,7 @@ from .const import (
LOGBOOK_ENTRY_ICON, LOGBOOK_ENTRY_ICON,
LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_MESSAGE,
LOGBOOK_ENTRY_NAME, LOGBOOK_ENTRY_NAME,
LOGBOOK_ENTRY_SOURCE,
LOGBOOK_ENTRY_STATE, LOGBOOK_ENTRY_STATE,
LOGBOOK_ENTRY_WHEN, LOGBOOK_ENTRY_WHEN,
LOGBOOK_FILTERS, LOGBOOK_FILTERS,
@ -398,11 +400,14 @@ class ContextAugmenter:
data[CONTEXT_DOMAIN] = domain data[CONTEXT_DOMAIN] = domain
event = self.event_cache.get(context_row) event = self.event_cache.get(context_row)
described = describe_event(event) described = describe_event(event)
if name := described.get(ATTR_NAME): if name := described.get(LOGBOOK_ENTRY_NAME):
data[CONTEXT_NAME] = name data[CONTEXT_NAME] = name
if message := described.get(ATTR_MESSAGE): if message := described.get(LOGBOOK_ENTRY_MESSAGE):
data[CONTEXT_MESSAGE] = 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 return
data[CONTEXT_ENTITY_ID] = attr_entity_id data[CONTEXT_ENTITY_ID] = attr_entity_id
if self.include_entity_name: if self.include_entity_name:

View file

@ -3,6 +3,10 @@ from __future__ import annotations
from collections.abc import Callable 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 homeassistant.core import Event, HomeAssistant, callback
from .const import ( from .const import (
@ -33,8 +37,8 @@ def async_describe_events(
button_map = LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP[device_type] button_map = LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP[device_type]
button_description = button_map[leap_button_number] button_description = button_map[leap_button_number]
return { return {
"name": f"{data[ATTR_AREA_NAME]} {data[ATTR_DEVICE_NAME]}", LOGBOOK_ENTRY_NAME: f"{data[ATTR_AREA_NAME]} {data[ATTR_DEVICE_NAME]}",
"message": f"{data[ATTR_ACTION]} {button_description}", LOGBOOK_ENTRY_MESSAGE: f"{data[ATTR_ACTION]} {button_description}",
} }
async_describe_event( async_describe_event(

View file

@ -3,6 +3,12 @@ from __future__ import annotations
from collections.abc import Callable 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.const import ATTR_FRIENDLY_NAME, ATTR_ICON
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
@ -42,12 +48,12 @@ def async_describe_events(
zone_name = zone_state.attributes.get(ATTR_FRIENDLY_NAME) zone_name = zone_state.attributes.get(ATTR_FRIENDLY_NAME)
zone_icon = zone_state.attributes.get(ATTR_ICON) zone_icon = zone_state.attributes.get(ATTR_ICON)
description = { description = {
"name": source_device_name, LOGBOOK_ENTRY_NAME: source_device_name,
"message": f"{event_description} {zone_name or zone_entity_id}", LOGBOOK_ENTRY_MESSAGE: f"{event_description} {zone_name or zone_entity_id}",
"icon": zone_icon or "mdi:crosshairs-gps", LOGBOOK_ENTRY_ICON: zone_icon or "mdi:crosshairs-gps",
} }
if zone_entity_id: if zone_entity_id:
description["entity_id"] = zone_entity_id description[LOGBOOK_ENTRY_ENTITY_ID] = zone_entity_id
return description return description
async_describe_event(DOMAIN, IOS_EVENT_ZONE_ENTERED, async_describe_zone_event) async_describe_event(DOMAIN, IOS_EVENT_ZONE_ENTERED, async_describe_zone_event)

View file

@ -1,4 +1,10 @@
"""Describe logbook events.""" """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.const import ATTR_ENTITY_ID, ATTR_NAME
from homeassistant.core import callback from homeassistant.core import callback
@ -14,10 +20,10 @@ def async_describe_events(hass, async_describe_event):
"""Describe the logbook event.""" """Describe the logbook event."""
data = event.data data = event.data
return { return {
"name": data.get(ATTR_NAME), LOGBOOK_ENTRY_NAME: data.get(ATTR_NAME),
"message": "started", LOGBOOK_ENTRY_MESSAGE: "started",
"entity_id": data.get(ATTR_ENTITY_ID), LOGBOOK_ENTRY_ENTITY_ID: data.get(ATTR_ENTITY_ID),
"context_id": event.context_id, LOGBOOK_ENTRY_CONTEXT_ID: event.context_id,
} }
async_describe_event(DOMAIN, EVENT_SCRIPT_STARTED, async_describe_logbook_event) async_describe_event(DOMAIN, EVENT_SCRIPT_STARTED, async_describe_logbook_event)

View file

@ -3,6 +3,10 @@ from __future__ import annotations
from collections.abc import Callable 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.const import ATTR_DEVICE_ID
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import EventType from homeassistant.helpers.typing import EventType
@ -48,8 +52,8 @@ def async_describe_events(
input_name = f"{device_name} channel {channel}" input_name = f"{device_name} channel {channel}"
return { return {
"name": "Shelly", LOGBOOK_ENTRY_NAME: "Shelly",
"message": f"'{click_type}' click event for {input_name} Input was fired", 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) async_describe_event(DOMAIN, EVENT_SHELLY_CLICK, async_describe_shelly_click_event)

View file

@ -8,7 +8,7 @@ import pytest
from homeassistant import core from homeassistant import core
from homeassistant.components import logbook, recorder from homeassistant.components import logbook, recorder
from homeassistant.components.automation import EVENT_AUTOMATION_TRIGGERED from homeassistant.components.automation import ATTR_SOURCE, EVENT_AUTOMATION_TRIGGERED
from homeassistant.components.logbook import websocket_api from homeassistant.components.logbook import websocket_api
from homeassistant.components.script import EVENT_SCRIPT_STARTED from homeassistant.components.script import EVENT_SCRIPT_STARTED
from homeassistant.components.websocket_api.const import TYPE_RESULT from homeassistant.components.websocket_api.const import TYPE_RESULT
@ -535,11 +535,19 @@ async def test_subscribe_unsubscribe_logbook_stream(
hass.bus.async_fire( hass.bus.async_fire(
EVENT_AUTOMATION_TRIGGERED, EVENT_AUTOMATION_TRIGGERED,
{ATTR_NAME: "Mock automation", ATTR_ENTITY_ID: "automation.mock_automation"}, {
ATTR_NAME: "Mock automation",
ATTR_ENTITY_ID: "automation.mock_automation",
ATTR_SOURCE: "numeric state of sensor.hungry_dogs",
},
) )
hass.bus.async_fire( hass.bus.async_fire(
EVENT_SCRIPT_STARTED, EVENT_SCRIPT_STARTED,
{ATTR_NAME: "Mock script", ATTR_ENTITY_ID: "script.mock_script"}, {
ATTR_NAME: "Mock script",
ATTR_ENTITY_ID: "script.mock_script",
ATTR_SOURCE: "numeric state of sensor.hungry_dogs",
},
) )
hass.bus.async_fire(EVENT_HOMEASSISTANT_START) hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -552,9 +560,9 @@ async def test_subscribe_unsubscribe_logbook_stream(
"context_id": ANY, "context_id": ANY,
"domain": "automation", "domain": "automation",
"entity_id": "automation.mock_automation", "entity_id": "automation.mock_automation",
"message": "triggered", "message": "triggered by numeric state of sensor.hungry_dogs",
"name": "Mock automation", "name": "Mock automation",
"source": None, "source": "numeric state of sensor.hungry_dogs",
"when": ANY, "when": ANY,
}, },
{ {
@ -581,7 +589,11 @@ async def test_subscribe_unsubscribe_logbook_stream(
automation_entity_id_test = "automation.alarm" automation_entity_id_test = "automation.alarm"
hass.bus.async_fire( hass.bus.async_fire(
EVENT_AUTOMATION_TRIGGERED, EVENT_AUTOMATION_TRIGGERED,
{ATTR_NAME: "Mock automation", ATTR_ENTITY_ID: automation_entity_id_test}, {
ATTR_NAME: "Mock automation",
ATTR_ENTITY_ID: automation_entity_id_test,
ATTR_SOURCE: "state of binary_sensor.dog_food_ready",
},
context=context, context=context,
) )
hass.bus.async_fire( hass.bus.async_fire(
@ -613,9 +625,9 @@ async def test_subscribe_unsubscribe_logbook_stream(
"context_user_id": "b400facee45711eaa9308bfd3d19e474", "context_user_id": "b400facee45711eaa9308bfd3d19e474",
"domain": "automation", "domain": "automation",
"entity_id": "automation.alarm", "entity_id": "automation.alarm",
"message": "triggered", "message": "triggered by state of binary_sensor.dog_food_ready",
"name": "Mock automation", "name": "Mock automation",
"source": None, "source": "state of binary_sensor.dog_food_ready",
"when": ANY, "when": ANY,
}, },
{ {
@ -623,8 +635,9 @@ async def test_subscribe_unsubscribe_logbook_stream(
"context_entity_id": "automation.alarm", "context_entity_id": "automation.alarm",
"context_event_type": "automation_triggered", "context_event_type": "automation_triggered",
"context_id": "ac5bd62de45711eaaeb351041eec8dd9", "context_id": "ac5bd62de45711eaaeb351041eec8dd9",
"context_message": "triggered", "context_message": "triggered by state of " "binary_sensor.dog_food_ready",
"context_name": "Mock automation", "context_name": "Mock automation",
"context_source": "state of binary_sensor.dog_food_ready",
"context_user_id": "b400facee45711eaa9308bfd3d19e474", "context_user_id": "b400facee45711eaa9308bfd3d19e474",
"domain": "script", "domain": "script",
"entity_id": "script.mock_script", "entity_id": "script.mock_script",
@ -636,8 +649,9 @@ async def test_subscribe_unsubscribe_logbook_stream(
"context_domain": "automation", "context_domain": "automation",
"context_entity_id": "automation.alarm", "context_entity_id": "automation.alarm",
"context_event_type": "automation_triggered", "context_event_type": "automation_triggered",
"context_message": "triggered", "context_message": "triggered by state of " "binary_sensor.dog_food_ready",
"context_name": "Mock automation", "context_name": "Mock automation",
"context_source": "state of binary_sensor.dog_food_ready",
"context_user_id": "b400facee45711eaa9308bfd3d19e474", "context_user_id": "b400facee45711eaa9308bfd3d19e474",
"entity_id": "alarm_control_panel.area_001", "entity_id": "alarm_control_panel.area_001",
"state": "on", "state": "on",
@ -647,8 +661,9 @@ async def test_subscribe_unsubscribe_logbook_stream(
"context_domain": "automation", "context_domain": "automation",
"context_entity_id": "automation.alarm", "context_entity_id": "automation.alarm",
"context_event_type": "automation_triggered", "context_event_type": "automation_triggered",
"context_message": "triggered", "context_message": "triggered by state of " "binary_sensor.dog_food_ready",
"context_name": "Mock automation", "context_name": "Mock automation",
"context_source": "state of binary_sensor.dog_food_ready",
"context_user_id": "b400facee45711eaa9308bfd3d19e474", "context_user_id": "b400facee45711eaa9308bfd3d19e474",
"entity_id": "alarm_control_panel.area_002", "entity_id": "alarm_control_panel.area_002",
"state": "on", "state": "on",
@ -672,8 +687,9 @@ async def test_subscribe_unsubscribe_logbook_stream(
"context_entity_id": "automation.alarm", "context_entity_id": "automation.alarm",
"context_event_type": "automation_triggered", "context_event_type": "automation_triggered",
"context_id": "ac5bd62de45711eaaeb351041eec8dd9", "context_id": "ac5bd62de45711eaaeb351041eec8dd9",
"context_message": "triggered", "context_message": "triggered by state of binary_sensor.dog_food_ready",
"context_name": "Mock automation", "context_name": "Mock automation",
"context_source": "state of binary_sensor.dog_food_ready",
"context_user_id": "b400facee45711eaa9308bfd3d19e474", "context_user_id": "b400facee45711eaa9308bfd3d19e474",
"domain": "automation", "domain": "automation",
"entity_id": "automation.alarm", "entity_id": "automation.alarm",
@ -701,8 +717,9 @@ async def test_subscribe_unsubscribe_logbook_stream(
"context_entity_id": "automation.alarm", "context_entity_id": "automation.alarm",
"context_event_type": "automation_triggered", "context_event_type": "automation_triggered",
"context_id": "ac5bd62de45711eaaeb351041eec8dd9", "context_id": "ac5bd62de45711eaaeb351041eec8dd9",
"context_message": "triggered", "context_message": "triggered by state of binary_sensor.dog_food_ready",
"context_name": "Mock automation", "context_name": "Mock automation",
"context_source": "state of binary_sensor.dog_food_ready",
"context_user_id": "b400facee45711eaa9308bfd3d19e474", "context_user_id": "b400facee45711eaa9308bfd3d19e474",
"domain": "automation", "domain": "automation",
"entity_id": "automation.alarm", "entity_id": "automation.alarm",