Skip to content

Commit 8fa7a05

Browse files
committed
fix flaky tests
1 parent 24ea8ad commit 8fa7a05

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

tests/test_diagnostics.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
from homeassistant.config_entries import ConfigEntry
1616
from homeassistant.core import HomeAssistant
1717
from homeassistant.helpers import device_registry as dr
18+
from homeassistant.helpers.discovery_flow import DiscoveryKey
1819
from tests.bluetooth import inject_bluetooth_service_info_bleak
1920
from tests.conftest import MockBleakClient, MockBMS, mock_config
2021

2122
BT_ADAPTER: Final[dict[str, Any]] = {
2223
"connections": {(BT_DOMAIN, "local")},
23-
"hw_version": 14,
24+
"hw_version": "14",
2425
"manufacturer": "adapter mnf",
2526
"model": "adapter model",
26-
"model_id": 2,
27+
"model_id": "2",
2728
"name": "mock adapter",
28-
"sw_version": 3,
29+
"sw_version": "3",
2930
}
3031

3132
BMS_DEV: Final[dict[str, Any]] = {
@@ -81,7 +82,15 @@ async def test_diagnostics(
8182
"type": "aiobmsble.bms.mock_BMS",
8283
},
8384
"disabled_by": None,
84-
"discovery_keys": {},
85+
"discovery_keys": {
86+
"bluetooth": (
87+
DiscoveryKey(
88+
domain="bluetooth",
89+
key="cc:cc:cc:cc:cc:cc",
90+
version=1,
91+
),
92+
),
93+
},
8594
"domain": DOMAIN,
8695
"entry_id": REDACTED,
8796
"minor_version": 0,
@@ -135,10 +144,16 @@ async def test_diagnostics(
135144
inject_bluetooth_service_info_bleak(hass, bt_discovery)
136145
await ce.runtime_data._async_setup()
137146
await ce.runtime_data.async_refresh()
147+
await hass.async_block_till_done(wait_background_tasks=True)
138148

139149
diag_data: dict[str, Any] = await async_get_config_entry_diagnostics(
140150
hass, config_entry
141151
)
152+
# patch the modified_at timestamp to match the expected value, since it is generated at runtime
153+
expected_diag_data["config_entry"]["modified_at"] = (
154+
expected_diag_data["config_entry"]["modified_at"][:20]
155+
+ diag_data["config_entry"]["modified_at"][20:]
156+
)
142157

143158
assert repr(diag_data.pop("advertisement_data")) == repr(
144159
expected_diag_data.pop("advertisement_data")

0 commit comments

Comments
 (0)