Fix bang olufsen flaky tests in Python 3.14.3 (#169345)

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
epenet
2026-04-28 09:23:31 +02:00
committed by GitHub
parent 4eb000d863
commit fa6c6ee4fc
5 changed files with 46 additions and 10 deletions
@@ -124,7 +124,7 @@
'battery_level': dict({
'attributes': dict({
'device_class': 'battery',
'friendly_name': 'Living room Balance Battery',
'friendly_name': 'Lounge room A5 Battery',
'state_class': 'measurement',
'unit_of_measurement': '%',
}),
@@ -134,7 +134,7 @@
'charging': dict({
'attributes': dict({
'device_class': 'battery_charging',
'friendly_name': 'Living room Balance Charging',
'friendly_name': 'Lounge room A5 Charging',
}),
'entity_id': 'binary_sensor.lounge_room_a5_charging',
'state': 'off',
@@ -174,12 +174,12 @@
'Lounge room A5': '1111.1111111.44444444@products.bang-olufsen.com',
}),
'self': dict({
'Living room Balance': '1111.1111111.44444444@products.bang-olufsen.com',
'Lounge room A5': '1111.1111111.44444444@products.bang-olufsen.com',
}),
}),
'device_class': 'speaker',
'entity_picture_local': None,
'friendly_name': 'Living room Balance',
'friendly_name': 'Lounge room A5',
'group_members': list([
'media_player.lounge_room_a5',
'listener_not_in_hass-1111.1111111.33333333@products.bang-olufsen.com',
@@ -2,14 +2,19 @@
from unittest.mock import AsyncMock
from mozart_api.models import BatteryState
from mozart_api.models import BatteryState, BeolinkSelf
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import EntityRegistry
from .conftest import mock_websocket_connection
from .const import TEST_BATTERY, TEST_BATTERY_CHARGING_BINARY_SENSOR_ENTITY_ID
from .const import (
TEST_BATTERY,
TEST_BATTERY_CHARGING_BINARY_SENSOR_ENTITY_ID,
TEST_FRIENDLY_NAME_4,
TEST_JID_4,
)
from tests.common import MockConfigEntry
@@ -23,6 +28,9 @@ async def test_battery_charging(
"""Test the battery charging time entity."""
# Ensure battery entities are created
mock_mozart_client.get_battery_state.return_value = TEST_BATTERY
mock_mozart_client.get_beolink_self.return_value = BeolinkSelf(
friendly_name=TEST_FRIENDLY_NAME_4, jid=TEST_JID_4
)
# Load entry
mock_config_entry_a5.add_to_hass(hass)
@@ -1,6 +1,6 @@
"""Test bang_olufsen config entry diagnostics."""
from mozart_api.models import BatteryState
from mozart_api.models import BatteryState, BeolinkSelf
from syrupy.assertion import SnapshotAssertion
from syrupy.filters import props
@@ -8,7 +8,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import EntityRegistry
from .conftest import mock_websocket_connection
from .const import TEST_BUTTON_EVENT_ENTITY_ID, TEST_REMOTE_KEY_EVENT_ENTITY_ID
from .const import (
TEST_BUTTON_EVENT_ENTITY_ID,
TEST_FRIENDLY_NAME_4,
TEST_JID_4,
TEST_REMOTE_KEY_EVENT_ENTITY_ID,
)
from tests.common import AsyncMock, MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry
@@ -65,6 +70,9 @@ async def test_async_get_config_entry_diagnostics_with_battery(
mock_mozart_client.get_battery_state.return_value = BatteryState(
battery_level=1, state="BatteryVeryLow"
)
mock_mozart_client.get_beolink_self.return_value = BeolinkSelf(
friendly_name=TEST_FRIENDLY_NAME_4, jid=TEST_JID_4
)
# Load entry
mock_config_entry_a5.add_to_hass(hass)
+16 -1
View File
@@ -2,7 +2,12 @@
from unittest.mock import AsyncMock
from mozart_api.models import BeoRemoteButton, ButtonEvent, PairedRemoteResponse
from mozart_api.models import (
BeolinkSelf,
BeoRemoteButton,
ButtonEvent,
PairedRemoteResponse,
)
from pytest_unordered import unordered
from syrupy.assertion import SnapshotAssertion
@@ -20,6 +25,10 @@ from .conftest import mock_websocket_connection
from .const import (
TEST_BATTERY,
TEST_BUTTON_EVENT_ENTITY_ID,
TEST_FRIENDLY_NAME_3,
TEST_FRIENDLY_NAME_4,
TEST_JID_3,
TEST_JID_4,
TEST_REMOTE_KEY_EVENT_ENTITY_ID,
TEST_SERIAL_NUMBER_3,
TEST_SERIAL_NUMBER_4,
@@ -109,6 +118,9 @@ async def test_button_event_creation_premiere(
snapshot: SnapshotAssertion,
) -> None:
"""Test Bluetooth and Microphone button event entities are not created when using a Beosound Premiere."""
mock_mozart_client.get_beolink_self.return_value = BeolinkSelf(
friendly_name=TEST_FRIENDLY_NAME_3, jid=TEST_JID_3
)
await _check_button_event_creation(
hass,
@@ -132,6 +144,9 @@ async def test_button_event_creation_a5(
) -> None:
"""Test Microphone button event entity is not created when using a Beosound A5."""
mock_mozart_client.get_battery_state.return_value = TEST_BATTERY
mock_mozart_client.get_beolink_self.return_value = BeolinkSelf(
friendly_name=TEST_FRIENDLY_NAME_4, jid=TEST_JID_4
)
await _check_button_event_creation(
hass,
+6 -1
View File
@@ -3,7 +3,7 @@
from unittest.mock import AsyncMock
from freezegun.api import FrozenDateTimeFactory
from mozart_api.models import PairedRemote, PairedRemoteResponse
from mozart_api.models import BeolinkSelf, PairedRemote, PairedRemoteResponse
from homeassistant.components.bang_olufsen.sensor import SCAN_INTERVAL
from homeassistant.const import STATE_UNKNOWN
@@ -13,6 +13,8 @@ from .conftest import mock_websocket_connection
from .const import (
TEST_BATTERY,
TEST_BATTERY_SENSOR_ENTITY_ID,
TEST_FRIENDLY_NAME_4,
TEST_JID_4,
TEST_REMOTE_BATTERY_LEVEL_SENSOR_ENTITY_ID,
TEST_REMOTE_SERIAL,
)
@@ -28,6 +30,9 @@ async def test_battery_level(
"""Test the battery level entity."""
# Ensure battery entities are created
mock_mozart_client.get_battery_state.return_value = TEST_BATTERY
mock_mozart_client.get_beolink_self.return_value = BeolinkSelf(
friendly_name=TEST_FRIENDLY_NAME_4, jid=TEST_JID_4
)
# Load entry
mock_config_entry_a5.add_to_hass(hass)