Skip to content

Commit ce48c89

Browse files
mj23000abmantis
andauthored
Fix button event entity creation in Bang & Olufsen (home-assistant#157982)
Co-authored-by: Abílio Costa <[email protected]>
1 parent f67a926 commit ce48c89

File tree

9 files changed

+344
-132
lines changed

9 files changed

+344
-132
lines changed

homeassistant/components/bang_olufsen/util.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,25 @@ async def get_remotes(client: MozartClient) -> list[PairedRemote]:
4242

4343
def get_device_buttons(model: BeoModel) -> list[str]:
4444
"""Get supported buttons for a given model."""
45+
# Beoconnect Core does not have any buttons
46+
if model == BeoModel.BEOCONNECT_CORE:
47+
return []
48+
4549
buttons = DEVICE_BUTTONS.copy()
4650

47-
# Beosound Premiere does not have a bluetooth button
48-
if model == BeoModel.BEOSOUND_PREMIERE:
51+
# Models that don't have a microphone button
52+
if model in (
53+
BeoModel.BEOSOUND_A5,
54+
BeoModel.BEOSOUND_A9,
55+
BeoModel.BEOSOUND_PREMIERE,
56+
):
57+
buttons.remove(BeoButtons.MICROPHONE)
58+
59+
# Models that don't have a Bluetooth button
60+
if model in (
61+
BeoModel.BEOSOUND_A9,
62+
BeoModel.BEOSOUND_PREMIERE,
63+
):
4964
buttons.remove(BeoButtons.BLUETOOTH)
5065

51-
# Beoconnect Core does not have any buttons
52-
elif model == BeoModel.BEOCONNECT_CORE:
53-
buttons = []
54-
5566
return buttons

tests/components/bang_olufsen/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
TEST_DATA_CREATE_ENTRY,
3838
TEST_DATA_CREATE_ENTRY_2,
3939
TEST_DATA_CREATE_ENTRY_3,
40+
TEST_DATA_CREATE_ENTRY_4,
4041
TEST_FRIENDLY_NAME,
4142
TEST_FRIENDLY_NAME_3,
4243
TEST_FRIENDLY_NAME_4,
@@ -48,10 +49,12 @@
4849
TEST_NAME,
4950
TEST_NAME_2,
5051
TEST_NAME_3,
52+
TEST_NAME_4,
5153
TEST_REMOTE_SERIAL,
5254
TEST_SERIAL_NUMBER,
5355
TEST_SERIAL_NUMBER_2,
5456
TEST_SERIAL_NUMBER_3,
57+
TEST_SERIAL_NUMBER_4,
5558
TEST_SOUND_MODE,
5659
TEST_SOUND_MODE_2,
5760
TEST_SOUND_MODE_NAME,
@@ -93,6 +96,17 @@ def mock_config_entry_premiere() -> MockConfigEntry:
9396
)
9497

9598

99+
@pytest.fixture
100+
def mock_config_entry_a5() -> MockConfigEntry:
101+
"""Mock config entry for Beosound A5."""
102+
return MockConfigEntry(
103+
domain=DOMAIN,
104+
unique_id=TEST_SERIAL_NUMBER_4,
105+
data=TEST_DATA_CREATE_ENTRY_4,
106+
title=TEST_NAME_4,
107+
)
108+
109+
96110
async def mock_websocket_connection(
97111
hass: HomeAssistant, mock_mozart_client: AsyncMock
98112
) -> None:

tests/components/bang_olufsen/const.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
TEST_MODEL_PREMIERE = "Beosound Premiere"
4343
TEST_MODEL_THEATRE = "Beosound Theatre"
4444
TEST_MODEL_LEVEL = "Beosound Level"
45+
TEST_MODEL_A5 = "Beosound A5"
4546
TEST_SERIAL_NUMBER = "11111111"
4647
TEST_NAME = f"{TEST_MODEL_BALANCE}-{TEST_SERIAL_NUMBER}"
4748
TEST_FRIENDLY_NAME = "Living room Balance"
@@ -64,9 +65,11 @@
6465
TEST_MEDIA_PLAYER_ENTITY_ID_3 = f"media_player.beosound_premiere_{TEST_SERIAL_NUMBER_3}"
6566
TEST_HOST_3 = "192.168.0.3"
6667

67-
TEST_FRIENDLY_NAME_4 = "Lounge room Balance"
68-
TEST_JID_4 = f"{TEST_TYPE_NUMBER}.{TEST_ITEM_NUMBER}[email protected]"
69-
TEST_MEDIA_PLAYER_ENTITY_ID_4 = "media_player.beosound_balance_44444444"
68+
TEST_FRIENDLY_NAME_4 = "Lounge room A5"
69+
TEST_SERIAL_NUMBER_4 = "44444444"
70+
TEST_NAME_4 = f"{TEST_MODEL_A5}-{TEST_SERIAL_NUMBER_4}"
71+
TEST_JID_4 = f"{TEST_TYPE_NUMBER}.{TEST_ITEM_NUMBER}.{TEST_SERIAL_NUMBER_4}@products.bang-olufsen.com"
72+
TEST_MEDIA_PLAYER_ENTITY_ID_4 = f"media_player.beosound_a5_{TEST_SERIAL_NUMBER_4}"
7073
TEST_HOST_4 = "192.168.0.4"
7174

7275
# Beoremote One
@@ -105,6 +108,13 @@
105108
CONF_NAME: TEST_NAME_3,
106109
}
107110

111+
TEST_DATA_CREATE_ENTRY_4 = {
112+
CONF_HOST: TEST_HOST_4,
113+
CONF_MODEL: TEST_MODEL_A5,
114+
CONF_BEOLINK_JID: TEST_JID_4,
115+
CONF_NAME: TEST_NAME_4,
116+
}
117+
108118
TEST_DATA_ZEROCONF = ZeroconfServiceInfo(
109119
ip_address=IPv4Address(TEST_HOST),
110120
ip_addresses=[IPv4Address(TEST_HOST)],

tests/components/bang_olufsen/snapshots/test_diagnostics.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
'beolink': dict({
4646
'listeners': dict({
4747
'Bedroom Premiere': '[email protected]',
48-
'Lounge room Balance': '[email protected]',
48+
'Lounge room A5': '[email protected]',
4949
}),
5050
'peers': dict({
5151
'Bedroom Premiere': '[email protected]',
52-
'Lounge room Balance': '[email protected]',
52+
'Lounge room A5': '[email protected]',
5353
}),
5454
'self': dict({
5555
'Living room Balance': '[email protected]',

tests/components/bang_olufsen/snapshots/test_event.ambr

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,108 @@
11
# serializer version: 1
2+
# name: test_button_event_creation_a5
3+
list([
4+
'event.beosound_a5_44444444_bluetooth',
5+
'event.beosound_a5_44444444_next',
6+
'event.beosound_a5_44444444_play_pause',
7+
'event.beosound_a5_44444444_favorite_1',
8+
'event.beosound_a5_44444444_favorite_2',
9+
'event.beosound_a5_44444444_favorite_3',
10+
'event.beosound_a5_44444444_favorite_4',
11+
'event.beosound_a5_44444444_previous',
12+
'event.beosound_a5_44444444_volume',
13+
'event.beoremote_one_55555555_44444444_light_blue',
14+
'event.beoremote_one_55555555_44444444_light_digit_0',
15+
'event.beoremote_one_55555555_44444444_light_digit_1',
16+
'event.beoremote_one_55555555_44444444_light_digit_2',
17+
'event.beoremote_one_55555555_44444444_light_digit_3',
18+
'event.beoremote_one_55555555_44444444_light_digit_4',
19+
'event.beoremote_one_55555555_44444444_light_digit_5',
20+
'event.beoremote_one_55555555_44444444_light_digit_6',
21+
'event.beoremote_one_55555555_44444444_light_digit_7',
22+
'event.beoremote_one_55555555_44444444_light_digit_8',
23+
'event.beoremote_one_55555555_44444444_light_digit_9',
24+
'event.beoremote_one_55555555_44444444_light_down',
25+
'event.beoremote_one_55555555_44444444_light_green',
26+
'event.beoremote_one_55555555_44444444_light_left',
27+
'event.beoremote_one_55555555_44444444_light_play',
28+
'event.beoremote_one_55555555_44444444_light_red',
29+
'event.beoremote_one_55555555_44444444_light_rewind',
30+
'event.beoremote_one_55555555_44444444_light_right',
31+
'event.beoremote_one_55555555_44444444_light_select',
32+
'event.beoremote_one_55555555_44444444_light_stop',
33+
'event.beoremote_one_55555555_44444444_light_up',
34+
'event.beoremote_one_55555555_44444444_light_wind',
35+
'event.beoremote_one_55555555_44444444_light_yellow',
36+
'event.beoremote_one_55555555_44444444_light_function_1',
37+
'event.beoremote_one_55555555_44444444_light_function_2',
38+
'event.beoremote_one_55555555_44444444_light_function_3',
39+
'event.beoremote_one_55555555_44444444_light_function_4',
40+
'event.beoremote_one_55555555_44444444_light_function_5',
41+
'event.beoremote_one_55555555_44444444_light_function_6',
42+
'event.beoremote_one_55555555_44444444_light_function_7',
43+
'event.beoremote_one_55555555_44444444_light_function_8',
44+
'event.beoremote_one_55555555_44444444_light_function_9',
45+
'event.beoremote_one_55555555_44444444_light_function_10',
46+
'event.beoremote_one_55555555_44444444_light_function_11',
47+
'event.beoremote_one_55555555_44444444_light_function_12',
48+
'event.beoremote_one_55555555_44444444_light_function_13',
49+
'event.beoremote_one_55555555_44444444_light_function_14',
50+
'event.beoremote_one_55555555_44444444_light_function_15',
51+
'event.beoremote_one_55555555_44444444_light_function_16',
52+
'event.beoremote_one_55555555_44444444_light_function_17',
53+
'event.beoremote_one_55555555_44444444_control_blue',
54+
'event.beoremote_one_55555555_44444444_control_digit_0',
55+
'event.beoremote_one_55555555_44444444_control_digit_1',
56+
'event.beoremote_one_55555555_44444444_control_digit_2',
57+
'event.beoremote_one_55555555_44444444_control_digit_3',
58+
'event.beoremote_one_55555555_44444444_control_digit_4',
59+
'event.beoremote_one_55555555_44444444_control_digit_5',
60+
'event.beoremote_one_55555555_44444444_control_digit_6',
61+
'event.beoremote_one_55555555_44444444_control_digit_7',
62+
'event.beoremote_one_55555555_44444444_control_digit_8',
63+
'event.beoremote_one_55555555_44444444_control_digit_9',
64+
'event.beoremote_one_55555555_44444444_control_down',
65+
'event.beoremote_one_55555555_44444444_control_green',
66+
'event.beoremote_one_55555555_44444444_control_left',
67+
'event.beoremote_one_55555555_44444444_control_play',
68+
'event.beoremote_one_55555555_44444444_control_red',
69+
'event.beoremote_one_55555555_44444444_control_rewind',
70+
'event.beoremote_one_55555555_44444444_control_right',
71+
'event.beoremote_one_55555555_44444444_control_select',
72+
'event.beoremote_one_55555555_44444444_control_stop',
73+
'event.beoremote_one_55555555_44444444_control_up',
74+
'event.beoremote_one_55555555_44444444_control_wind',
75+
'event.beoremote_one_55555555_44444444_control_yellow',
76+
'event.beoremote_one_55555555_44444444_control_function_1',
77+
'event.beoremote_one_55555555_44444444_control_function_2',
78+
'event.beoremote_one_55555555_44444444_control_function_3',
79+
'event.beoremote_one_55555555_44444444_control_function_4',
80+
'event.beoremote_one_55555555_44444444_control_function_5',
81+
'event.beoremote_one_55555555_44444444_control_function_6',
82+
'event.beoremote_one_55555555_44444444_control_function_7',
83+
'event.beoremote_one_55555555_44444444_control_function_8',
84+
'event.beoremote_one_55555555_44444444_control_function_9',
85+
'event.beoremote_one_55555555_44444444_control_function_10',
86+
'event.beoremote_one_55555555_44444444_control_function_11',
87+
'event.beoremote_one_55555555_44444444_control_function_12',
88+
'event.beoremote_one_55555555_44444444_control_function_13',
89+
'event.beoremote_one_55555555_44444444_control_function_14',
90+
'event.beoremote_one_55555555_44444444_control_function_15',
91+
'event.beoremote_one_55555555_44444444_control_function_16',
92+
'event.beoremote_one_55555555_44444444_control_function_17',
93+
'event.beoremote_one_55555555_44444444_control_function_18',
94+
'event.beoremote_one_55555555_44444444_control_function_19',
95+
'event.beoremote_one_55555555_44444444_control_function_20',
96+
'event.beoremote_one_55555555_44444444_control_function_21',
97+
'event.beoremote_one_55555555_44444444_control_function_22',
98+
'event.beoremote_one_55555555_44444444_control_function_23',
99+
'event.beoremote_one_55555555_44444444_control_function_24',
100+
'event.beoremote_one_55555555_44444444_control_function_25',
101+
'event.beoremote_one_55555555_44444444_control_function_26',
102+
'event.beoremote_one_55555555_44444444_control_function_27',
103+
'media_player.beosound_a5_44444444',
104+
])
105+
# ---
2106
# name: test_button_event_creation_balance
3107
list([
4108
'event.beosound_balance_11111111_bluetooth',
@@ -104,9 +208,8 @@
104208
'media_player.beosound_balance_11111111',
105209
])
106210
# ---
107-
# name: test_button_event_creation_beosound_premiere
211+
# name: test_button_event_creation_premiere
108212
list([
109-
'event.beosound_premiere_33333333_microphone',
110213
'event.beosound_premiere_33333333_next',
111214
'event.beosound_premiere_33333333_play_pause',
112215
'event.beosound_premiere_33333333_favorite_1',
@@ -208,7 +311,7 @@
208311
'media_player.beosound_premiere_33333333',
209312
])
210313
# ---
211-
# name: test_no_button_and_remote_key_event_creation
314+
# name: test_no_button_and_remote_key_event_creation_core
212315
list([
213316
'media_player.beoconnect_core_22222222',
214317
])

0 commit comments

Comments
 (0)