Fix Shelly sleeping Gen2 - do not refresh from zeroconf discovery (#86296)

pull/86325/head
Shay Levy 2023-01-20 21:27:31 +02:00 committed by GitHub
parent 914704e459
commit df77646c8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -596,7 +596,8 @@ async def async_reconnect_soon(
) -> None:
"""Try to reconnect soon."""
if (
not hass.is_stopping
not entry.data.get(CONF_SLEEP_PERIOD)
and not hass.is_stopping
and entry.state == config_entries.ConfigEntryState.LOADED
and (entry_data := get_entry_data(hass).get(entry.entry_id))
and (coordinator := entry_data.rpc)

View File

@ -1187,3 +1187,39 @@ async def test_zeroconf_already_configured_triggers_refresh(
mock_rpc_device.mock_disconnected()
await hass.async_block_till_done()
assert len(mock_rpc_device.initialize.mock_calls) == 2
async def test_zeroconf_sleeping_device_not_triggers_refresh(
hass, mock_rpc_device, monkeypatch, caplog
):
"""Test zeroconf discovery does not triggers refresh for sleeping device."""
entry = MockConfigEntry(
domain="shelly",
unique_id="AABBCCDDEEFF",
data={"host": "1.1.1.1", "gen": 2, "sleep_period": 1000, "model": "SHSW-1"},
)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
mock_rpc_device.mock_update()
assert "online, resuming setup" in caplog.text
with patch(
"aioshelly.common.get_info",
return_value={"mac": "AABBCCDDEEFF", "type": "SHSW-1", "auth": False},
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
data=DISCOVERY_INFO,
context={"source": config_entries.SOURCE_ZEROCONF},
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "already_configured"
monkeypatch.setattr(mock_rpc_device, "connected", False)
mock_rpc_device.mock_disconnected()
await hass.async_block_till_done()
assert len(mock_rpc_device.initialize.mock_calls) == 0
assert "device did not update" not in caplog.text