|
16 | 16 | from inkbird_ble.parser import Model |
17 | 17 | from sensor_state_data import SensorDeviceClass |
18 | 18 |
|
| 19 | +from homeassistant.components.bluetooth import async_last_service_info |
19 | 20 | from homeassistant.components.inkbird.const import ( |
20 | 21 | CONF_DEVICE_DATA, |
21 | 22 | CONF_DEVICE_TYPE, |
@@ -175,6 +176,40 @@ async def test_polling_sensor(hass: HomeAssistant) -> None: |
175 | 176 | await hass.async_block_till_done() |
176 | 177 |
|
177 | 178 |
|
| 179 | +async def test_fallback_poll_queries_latest_service_info(hass: HomeAssistant) -> None: |
| 180 | + """Fallback timer queries the bluetooth manager for the latest service info. |
| 181 | +
|
| 182 | + Regression test for the case where HA dedupes repeat advertisements with the |
| 183 | + same payload; ``_last_service_info`` then goes stale even though the device |
| 184 | + is still broadcasting, so the fallback recency check must consult the |
| 185 | + bluetooth manager's freshest observation instead of the dispatched event. |
| 186 | + """ |
| 187 | + entry = MockConfigEntry( |
| 188 | + domain=DOMAIN, |
| 189 | + unique_id="AA:BB:CC:DD:EE:FF", |
| 190 | + data={CONF_DEVICE_TYPE: "IBS-TH"}, |
| 191 | + ) |
| 192 | + entry.add_to_hass(hass) |
| 193 | + assert await hass.config_entries.async_setup(entry.entry_id) |
| 194 | + await hass.async_block_till_done() |
| 195 | + inject_bluetooth_service_info(hass, SPS_PASSIVE_SERVICE_INFO) |
| 196 | + await hass.async_block_till_done() |
| 197 | + |
| 198 | + with patch( |
| 199 | + "homeassistant.components.inkbird.coordinator.async_last_service_info", |
| 200 | + wraps=async_last_service_info, |
| 201 | + ) as mock_async_last_service_info: |
| 202 | + async_fire_time_changed(hass, dt_util.utcnow() + FALLBACK_POLL_INTERVAL) |
| 203 | + await hass.async_block_till_done() |
| 204 | + |
| 205 | + mock_async_last_service_info.assert_called_once_with( |
| 206 | + hass, "AA:BB:CC:DD:EE:FF", connectable=False |
| 207 | + ) |
| 208 | + |
| 209 | + assert await hass.config_entries.async_unload(entry.entry_id) |
| 210 | + await hass.async_block_till_done() |
| 211 | + |
| 212 | + |
178 | 213 | async def test_notify_sensor_no_advertisement(hass: HomeAssistant) -> None: |
179 | 214 | """Test setting up a notify sensor that has no advertisement.""" |
180 | 215 | entry = MockConfigEntry( |
|
0 commit comments