Retry SmartThings setup when the cloud is unreachable while fetching (#180542)

This commit is contained in:
Franck Nijhof
2026-08-28 15:51:24 -04:00
committed by GitHub
parent ef90070ace
commit a9346a6249
2 changed files with 35 additions and 5 deletions
@@ -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(
+27
View File
@@ -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,