mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 02:24:51 -05:00
Add support for child devices to assist_pipeline logbook augmentation (#179366)
This commit is contained in:
@@ -21,10 +21,9 @@ def async_describe_events(
|
||||
@callback
|
||||
def async_describe_logbook_event(event: Event) -> dict[str, str]:
|
||||
"""Describe logbook event."""
|
||||
device: dr.DeviceEntry | None = None
|
||||
device_name: str = "Unknown device"
|
||||
device_name = "Unknown device"
|
||||
|
||||
device = device_registry.devices[event.data[ATTR_DEVICE_ID]]
|
||||
device = device_registry.async_get(event.data[ATTR_DEVICE_ID])
|
||||
if device:
|
||||
device_name = device.name_by_user or device.name or "Unknown device"
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""The tests for assist_pipeline logbook."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import assist_pipeline, logbook
|
||||
from homeassistant.const import ATTR_DEVICE_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -42,3 +44,67 @@ async def test_recording_event(
|
||||
assert (
|
||||
event[logbook.LOGBOOK_ENTRY_MESSAGE] == "My Satellite captured an audio sample"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_components")
|
||||
async def test_recording_event_child_device(
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||
) -> None:
|
||||
"""Test recording event fired for a child device."""
|
||||
hass.config.components.add("recorder")
|
||||
assert await async_setup_component(hass, "logbook", {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entry = MockConfigEntry()
|
||||
entry.add_to_hass(hass)
|
||||
satellite_device = device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
connections=set(),
|
||||
identifiers={("demo", "satellite-1234")},
|
||||
)
|
||||
child_device = device_registry.async_get_or_create_child(
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={("demo", "satellite-1234-child")},
|
||||
parent_device_id=satellite_device.id,
|
||||
name="My Child Satellite",
|
||||
)
|
||||
|
||||
event = mock_humanify(
|
||||
hass,
|
||||
[
|
||||
MockRow(
|
||||
assist_pipeline.EVENT_RECORDING,
|
||||
{ATTR_DEVICE_ID: child_device.id},
|
||||
),
|
||||
],
|
||||
)[0]
|
||||
|
||||
assert event[logbook.LOGBOOK_ENTRY_NAME] == "My Child Satellite"
|
||||
assert (
|
||||
event[logbook.LOGBOOK_ENTRY_MESSAGE]
|
||||
== "My Child Satellite captured an audio sample"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_components")
|
||||
async def test_recording_event_unknown_device(hass: HomeAssistant) -> None:
|
||||
"""Test recording event for an unknown device does not raise."""
|
||||
hass.config.components.add("recorder")
|
||||
assert await async_setup_component(hass, "logbook", {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
event = mock_humanify(
|
||||
hass,
|
||||
[
|
||||
MockRow(
|
||||
assist_pipeline.EVENT_RECORDING,
|
||||
{ATTR_DEVICE_ID: "non-existing-device"},
|
||||
),
|
||||
],
|
||||
)[0]
|
||||
|
||||
assert event[logbook.LOGBOOK_ENTRY_NAME] == "Unknown device"
|
||||
assert (
|
||||
event[logbook.LOGBOOK_ENTRY_MESSAGE]
|
||||
== "Unknown device captured an audio sample"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user