Shelly RPC - do not stop BLE scanner if a sleeping device (#124147)

pull/124163/head
Shay Levy 2024-08-18 18:35:02 +03:00 committed by GitHub
parent 4ab3f1f41f
commit 49c59339d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -711,7 +711,8 @@ class ShellyRpcCoordinator(ShellyCoordinatorBase[RpcDevice]):
"""Shutdown the coordinator."""
if self.device.connected:
try:
await async_stop_scanner(self.device)
if not self.sleep_period:
await async_stop_scanner(self.device)
await super().shutdown()
except InvalidAuthError:
self.entry.async_start_reauth(self.hass)

View File

@ -854,6 +854,27 @@ async def test_rpc_runs_connected_events_when_initialized(
assert call.script_list() in mock_rpc_device.mock_calls
async def test_rpc_sleeping_device_unload_ignore_ble_scanner(
hass: HomeAssistant,
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC sleeping device does not stop ble scanner on unload."""
monkeypatch.setattr(mock_rpc_device, "connected", True)
entry = await init_integration(hass, 2, sleep_period=1000)
# Make device online
mock_rpc_device.mock_online()
await hass.async_block_till_done(wait_background_tasks=True)
# Unload
await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
# BLE script list is called during stop ble scanner
assert call.script_list() not in mock_rpc_device.mock_calls
async def test_block_sleeping_device_connection_error(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,