mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Fix Bang & Olufsen event testing (#135707)
Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
This commit is contained in:
parent
d908d2ab55
commit
e188d9a00c
@ -42,18 +42,18 @@ TEST_MODEL_CORE = "Beoconnect Core"
|
||||
TEST_MODEL_THEATRE = "Beosound Theatre"
|
||||
TEST_MODEL_LEVEL = "Beosound Level"
|
||||
TEST_SERIAL_NUMBER = "11111111"
|
||||
TEST_SERIAL_NUMBER_2 = "22222222"
|
||||
TEST_NAME = f"{TEST_MODEL_BALANCE}-{TEST_SERIAL_NUMBER}"
|
||||
TEST_NAME_2 = f"{TEST_MODEL_BALANCE}-{TEST_SERIAL_NUMBER_2}"
|
||||
TEST_FRIENDLY_NAME = "Living room Balance"
|
||||
TEST_TYPE_NUMBER = "1111"
|
||||
TEST_ITEM_NUMBER = "1111111"
|
||||
TEST_JID_1 = f"{TEST_TYPE_NUMBER}.{TEST_ITEM_NUMBER}.{TEST_SERIAL_NUMBER}@products.bang-olufsen.com"
|
||||
TEST_MEDIA_PLAYER_ENTITY_ID = "media_player.beosound_balance_11111111"
|
||||
|
||||
TEST_FRIENDLY_NAME_2 = "Laundry room Balance"
|
||||
TEST_JID_2 = f"{TEST_TYPE_NUMBER}.{TEST_ITEM_NUMBER}.22222222@products.bang-olufsen.com"
|
||||
TEST_MEDIA_PLAYER_ENTITY_ID_2 = "media_player.beosound_balance_22222222"
|
||||
TEST_FRIENDLY_NAME_2 = "Laundry room Core"
|
||||
TEST_SERIAL_NUMBER_2 = "22222222"
|
||||
TEST_NAME_2 = f"{TEST_MODEL_CORE}-{TEST_SERIAL_NUMBER_2}"
|
||||
TEST_JID_2 = f"{TEST_TYPE_NUMBER}.{TEST_ITEM_NUMBER}.{TEST_SERIAL_NUMBER_2}@products.bang-olufsen.com"
|
||||
TEST_MEDIA_PLAYER_ENTITY_ID_2 = "media_player.beoconnect_core_22222222"
|
||||
TEST_HOST_2 = "192.168.0.2"
|
||||
|
||||
TEST_FRIENDLY_NAME_3 = "Lego room Balance"
|
||||
@ -84,7 +84,7 @@ TEST_DATA_CREATE_ENTRY = {
|
||||
CONF_NAME: TEST_NAME,
|
||||
}
|
||||
TEST_DATA_CREATE_ENTRY_2 = {
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_HOST: TEST_HOST_2,
|
||||
CONF_MODEL: TEST_MODEL_CORE,
|
||||
CONF_BEOLINK_JID: TEST_JID_2,
|
||||
CONF_NAME: TEST_NAME_2,
|
||||
|
21
tests/components/bang_olufsen/snapshots/test_event.ambr
Normal file
21
tests/components/bang_olufsen/snapshots/test_event.ambr
Normal file
@ -0,0 +1,21 @@
|
||||
# serializer version: 1
|
||||
# name: test_button_event_creation
|
||||
list([
|
||||
'event.beosound_balance_11111111_bluetooth',
|
||||
'event.beosound_balance_11111111_microphone',
|
||||
'event.beosound_balance_11111111_next',
|
||||
'event.beosound_balance_11111111_play_pause',
|
||||
'event.beosound_balance_11111111_favourite_1',
|
||||
'event.beosound_balance_11111111_favourite_2',
|
||||
'event.beosound_balance_11111111_favourite_3',
|
||||
'event.beosound_balance_11111111_favourite_4',
|
||||
'event.beosound_balance_11111111_previous',
|
||||
'event.beosound_balance_11111111_volume',
|
||||
'media_player.beosound_balance_11111111',
|
||||
])
|
||||
# ---
|
||||
# name: test_button_event_creation_beoconnect_core
|
||||
list([
|
||||
'media_player.beoconnect_core_22222222',
|
||||
])
|
||||
# ---
|
@ -642,7 +642,7 @@
|
||||
'entity_picture_local': None,
|
||||
'friendly_name': 'Living room Balance',
|
||||
'group_members': list([
|
||||
'media_player.beosound_balance_22222222',
|
||||
'media_player.beoconnect_core_22222222',
|
||||
'listener_not_in_hass-1111.1111111.33333333@products.bang-olufsen.com',
|
||||
'listener_not_in_hass-1111.1111111.44444444@products.bang-olufsen.com',
|
||||
]),
|
||||
@ -661,7 +661,7 @@
|
||||
'supported_features': <MediaPlayerEntityFeature: 2095933>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'media_player.beosound_balance_22222222',
|
||||
'entity_id': 'media_player.beoconnect_core_22222222',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
@ -737,7 +737,7 @@
|
||||
'entity_picture_local': None,
|
||||
'friendly_name': 'Living room Balance',
|
||||
'group_members': list([
|
||||
'media_player.beosound_balance_22222222',
|
||||
'media_player.beoconnect_core_22222222',
|
||||
'listener_not_in_hass-1111.1111111.33333333@products.bang-olufsen.com',
|
||||
'listener_not_in_hass-1111.1111111.44444444@products.bang-olufsen.com',
|
||||
]),
|
||||
@ -756,7 +756,7 @@
|
||||
'supported_features': <MediaPlayerEntityFeature: 2095933>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'media_player.beosound_balance_22222222',
|
||||
'entity_id': 'media_player.beoconnect_core_22222222',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
@ -831,7 +831,7 @@
|
||||
'entity_picture_local': None,
|
||||
'friendly_name': 'Living room Balance',
|
||||
'group_members': list([
|
||||
'media_player.beosound_balance_22222222',
|
||||
'media_player.beoconnect_core_22222222',
|
||||
'listener_not_in_hass-1111.1111111.33333333@products.bang-olufsen.com',
|
||||
'listener_not_in_hass-1111.1111111.44444444@products.bang-olufsen.com',
|
||||
]),
|
||||
@ -850,7 +850,7 @@
|
||||
'supported_features': <MediaPlayerEntityFeature: 2095933>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'media_player.beosound_balance_22222222',
|
||||
'entity_id': 'media_player.beoconnect_core_22222222',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
@ -924,7 +924,7 @@
|
||||
'entity_picture_local': None,
|
||||
'friendly_name': 'Living room Balance',
|
||||
'group_members': list([
|
||||
'media_player.beosound_balance_22222222',
|
||||
'media_player.beoconnect_core_22222222',
|
||||
'listener_not_in_hass-1111.1111111.33333333@products.bang-olufsen.com',
|
||||
'listener_not_in_hass-1111.1111111.44444444@products.bang-olufsen.com',
|
||||
]),
|
||||
@ -943,7 +943,7 @@
|
||||
'supported_features': <MediaPlayerEntityFeature: 2095933>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'media_player.beosound_balance_22222222',
|
||||
'entity_id': 'media_player.beoconnect_core_22222222',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
@ -1003,7 +1003,7 @@
|
||||
'attributes': ReadOnlyDict({
|
||||
'beolink': dict({
|
||||
'leader': dict({
|
||||
'Laundry room Balance': '1111.1111111.22222222@products.bang-olufsen.com',
|
||||
'Laundry room Core': '1111.1111111.22222222@products.bang-olufsen.com',
|
||||
}),
|
||||
'peers': dict({
|
||||
'Lego room Balance': '1111.1111111.33333333@products.bang-olufsen.com',
|
||||
@ -1017,7 +1017,7 @@
|
||||
'entity_picture_local': None,
|
||||
'friendly_name': 'Living room Balance',
|
||||
'group_members': list([
|
||||
'media_player.beosound_balance_22222222',
|
||||
'media_player.beoconnect_core_22222222',
|
||||
'media_player.beosound_balance_11111111',
|
||||
]),
|
||||
'media_content_type': <MediaType.MUSIC: 'music'>,
|
||||
@ -1062,7 +1062,7 @@
|
||||
'entity_picture_local': None,
|
||||
'friendly_name': 'Living room Balance',
|
||||
'group_members': list([
|
||||
'media_player.beosound_balance_22222222',
|
||||
'media_player.beoconnect_core_22222222',
|
||||
'listener_not_in_hass-1111.1111111.33333333@products.bang-olufsen.com',
|
||||
'listener_not_in_hass-1111.1111111.44444444@products.bang-olufsen.com',
|
||||
]),
|
||||
@ -1081,7 +1081,7 @@
|
||||
'supported_features': <MediaPlayerEntityFeature: 2095933>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'media_player.beosound_balance_22222222',
|
||||
'entity_id': 'media_player.beoconnect_core_22222222',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
|
@ -4,6 +4,7 @@ from unittest.mock import AsyncMock
|
||||
|
||||
from inflection import underscore
|
||||
from mozart_api.models import ButtonEvent
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.bang_olufsen.const import (
|
||||
DEVICE_BUTTON_EVENTS,
|
||||
@ -25,6 +26,7 @@ async def test_button_event_creation(
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_mozart_client: AsyncMock,
|
||||
entity_registry: EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test button event entities are created."""
|
||||
|
||||
@ -35,14 +37,21 @@ async def test_button_event_creation(
|
||||
# Add Button Event entity ids
|
||||
entity_ids = [
|
||||
f"event.beosound_balance_11111111_{underscore(button_type)}".replace(
|
||||
"preset", "preset_"
|
||||
"preset", "favourite_"
|
||||
)
|
||||
for button_type in DEVICE_BUTTONS
|
||||
]
|
||||
|
||||
# Check that the entities are available
|
||||
for entity_id in entity_ids:
|
||||
entity_registry.async_get(entity_id)
|
||||
assert entity_registry.async_get(entity_id)
|
||||
|
||||
# Check number of entities
|
||||
# The media_player entity and all of the button event entities should be the only available
|
||||
entity_ids_available = list(entity_registry.entities.keys())
|
||||
assert len(entity_ids_available) == 1 + len(entity_ids)
|
||||
|
||||
assert entity_ids_available == snapshot
|
||||
|
||||
|
||||
async def test_button_event_creation_beoconnect_core(
|
||||
@ -50,6 +59,7 @@ async def test_button_event_creation_beoconnect_core(
|
||||
mock_config_entry_core: MockConfigEntry,
|
||||
mock_mozart_client: AsyncMock,
|
||||
entity_registry: EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test button event entities are not created when using a Beoconnect Core."""
|
||||
|
||||
@ -57,17 +67,12 @@ async def test_button_event_creation_beoconnect_core(
|
||||
mock_config_entry_core.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry_core.entry_id)
|
||||
|
||||
# Add Button Event entity ids
|
||||
entity_ids = [
|
||||
f"event.beosound_balance_11111111_{underscore(button_type)}".replace(
|
||||
"preset", "preset_"
|
||||
)
|
||||
for button_type in DEVICE_BUTTONS
|
||||
]
|
||||
# Check number of entities
|
||||
# The media_player entity should be the only available
|
||||
entity_ids_available = list(entity_registry.entities.keys())
|
||||
assert len(entity_ids_available) == 1
|
||||
|
||||
# Check that the entities are unavailable
|
||||
for entity_id in entity_ids:
|
||||
assert not entity_registry.async_get(entity_id)
|
||||
assert entity_ids_available == snapshot
|
||||
|
||||
|
||||
async def test_button(
|
||||
|
Loading…
x
Reference in New Issue
Block a user