Skip to content

Commit

Permalink
Do not check ble scanner state for sleepy shelly devices
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jan 9, 2023
1 parent b6316b4 commit d6ba2d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion homeassistant/components/shelly/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ async def _async_run_connected_events(self) -> None:
This will be executed on connect or when the config entry
is updated.
"""
await self._async_connect_ble_scanner()
if not self.entry.data.get(CONF_SLEEP_PERIOD):
await self._async_connect_ble_scanner()

async def _async_connect_ble_scanner(self) -> None:
"""Connect BLE scanner."""
Expand Down
16 changes: 15 additions & 1 deletion tests/components/shelly/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def test_entry_unload_not_connected(hass, mock_rpc_device, monkeypatch):
assert entry.state is ConfigEntryState.LOADED


async def test_entry_unload_not_connected_but_we_with_we_are(
async def test_entry_unload_not_connected_but_we_think_we_are(
hass, mock_rpc_device, monkeypatch
):
"""Test entry unload when not connected but we think we are still connected."""
Expand All @@ -238,3 +238,17 @@ async def test_entry_unload_not_connected_but_we_with_we_are(

assert not mock_stop_scanner.call_count
assert entry.state is ConfigEntryState.LOADED


async def test_no_attempt_to_stop_scanner_with_sleepy_devices(hass, mock_rpc_device):
"""Test we do not try to stop the scanner if its disabled with a sleepy device."""
with patch(
"homeassistant.components.shelly.coordinator.async_stop_scanner",
) as mock_stop_scanner:
entry = await init_integration(hass, 2, sleep_period=7200)
assert entry.state is ConfigEntryState.LOADED
assert not mock_stop_scanner.call_count

mock_rpc_device.mock_update()
await hass.async_block_till_done()
assert not mock_stop_scanner.call_count

0 comments on commit d6ba2d6

Please sign in to comment.