diff --git a/homeassistant/components/smartthings/__init__.py b/homeassistant/components/smartthings/__init__.py index 49840d0e5a03..f7ad18bb531b 100644 --- a/homeassistant/components/smartthings/__init__.py +++ b/homeassistant/components/smartthings/__init__.py @@ -238,17 +238,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: SmartThingsConfigEntry) device_status[device.device_id] = FullDevice( device=device, status=status, online=online.state == HealthStatus.ONLINE ) + scenes = { + scene.scene_id: scene + for scene in await client.get_scenes( + location_id=entry.data[CONF_LOCATION_ID] + ) + } except SmartThingsAuthenticationFailedError as err: raise ConfigEntryAuthFailed from err + except SmartThingsConnectionError as err: + raise ConfigEntryNotReady from err device_registry = dr.async_get(hass) create_devices(device_registry, device_status, entry, rooms) - scenes = { - scene.scene_id: scene - for scene in await client.get_scenes(location_id=entry.data[CONF_LOCATION_ID]) - } - def handle_deleted_device(device_id: str) -> None: """Handle a deleted device.""" dev_entry = device_registry.async_get_device_by_identifier( diff --git a/tests/components/smartthings/test_init.py b/tests/components/smartthings/test_init.py index cee6ca7a3b12..288197015621 100644 --- a/tests/components/smartthings/test_init.py +++ b/tests/components/smartthings/test_init.py @@ -215,6 +215,33 @@ async def test_create_subscription_error( assert CONF_SUBSCRIPTION_ID not in mock_config_entry.data +@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"]) +@pytest.mark.parametrize( + "call", + [ + "get_rooms", + "get_devices", + "get_device_status", + "get_device_health", + "get_scenes", + ], +) +async def test_initial_fetch_connection_error( + hass: HomeAssistant, + devices: AsyncMock, + mock_config_entry: MockConfigEntry, + call: str, +) -> None: + """Test retrying setup when the cloud is unreachable while fetching.""" + getattr(devices, call).side_effect = SmartThingsConnectionError( + "Timeout occurred while connecting to SmartThings" + ) + + await setup_integration(hass, mock_config_entry) + + assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY + + @pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"]) async def test_update_subscription_identifier( hass: HomeAssistant,