Add Event entity states to diagnostics for Bang & Olufsen (#135859)
Add diagnostics for event buttonspull/138605/head
parent
c89d8edb3c
commit
05696b5528
|
@ -4,12 +4,13 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.components.event import DOMAIN as EVENT_DOMAIN
|
||||
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import BangOlufsenConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .const import DEVICE_BUTTONS, DOMAIN
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
|
@ -25,8 +26,9 @@ async def async_get_config_entry_diagnostics(
|
|||
if TYPE_CHECKING:
|
||||
assert config_entry.unique_id
|
||||
|
||||
# Add media_player entity's state
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
# Add media_player entity's state
|
||||
if entity_id := entity_registry.async_get_entity_id(
|
||||
MEDIA_PLAYER_DOMAIN, DOMAIN, config_entry.unique_id
|
||||
):
|
||||
|
@ -37,4 +39,16 @@ async def async_get_config_entry_diagnostics(
|
|||
state_dict.pop("context")
|
||||
data["media_player"] = state_dict
|
||||
|
||||
# Add button Event entity states (if enabled)
|
||||
for device_button in DEVICE_BUTTONS:
|
||||
if entity_id := entity_registry.async_get_entity_id(
|
||||
EVENT_DOMAIN, DOMAIN, f"{config_entry.unique_id}_{device_button}"
|
||||
):
|
||||
if state := hass.states.get(entity_id):
|
||||
state_dict = dict(state.as_dict())
|
||||
|
||||
# Remove context as it is not relevant
|
||||
state_dict.pop("context")
|
||||
data[f"{device_button}_event"] = state_dict
|
||||
|
||||
return data
|
||||
|
|
|
@ -1,6 +1,22 @@
|
|||
# serializer version: 1
|
||||
# name: test_async_get_config_entry_diagnostics
|
||||
dict({
|
||||
'PlayPause_event': dict({
|
||||
'attributes': dict({
|
||||
'device_class': 'button',
|
||||
'event_type': None,
|
||||
'event_types': list([
|
||||
'short_press_release',
|
||||
'long_press_timeout',
|
||||
'long_press_release',
|
||||
'very_long_press_timeout',
|
||||
'very_long_press_release',
|
||||
]),
|
||||
'friendly_name': 'Living room Balance Play / Pause',
|
||||
}),
|
||||
'entity_id': 'event.beosound_balance_11111111_play_pause',
|
||||
'state': 'unknown',
|
||||
}),
|
||||
'config_entry': dict({
|
||||
'data': dict({
|
||||
'host': '192.168.0.1',
|
||||
|
|
|
@ -6,6 +6,9 @@ from syrupy import SnapshotAssertion
|
|||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from .const import TEST_BUTTON_EVENT_ENTITY_ID
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
@ -14,6 +17,7 @@ from tests.typing import ClientSessionGenerator
|
|||
|
||||
async def test_async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: EntityRegistry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_mozart_client: AsyncMock,
|
||||
|
@ -23,6 +27,10 @@ async def test_async_get_config_entry_diagnostics(
|
|||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
|
||||
# Enable an Event entity
|
||||
entity_registry.async_update_entity(TEST_BUTTON_EVENT_ENTITY_ID, disabled_by=None)
|
||||
hass.config_entries.async_schedule_reload(mock_config_entry.entry_id)
|
||||
|
||||
result = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue