diff --git a/homeassistant/components/shelly/coordinator.py b/homeassistant/components/shelly/coordinator.py index 2d321c8df9d..1c4ba7d4763 100644 --- a/homeassistant/components/shelly/coordinator.py +++ b/homeassistant/components/shelly/coordinator.py @@ -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) diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index 7338747cbaf..fbaf2d98ba2 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -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