From ac96c7bb1fa2d29eb47ca3d351b6b1bcd838f1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Klomp?= Date: Wed, 17 Nov 2021 11:28:18 +0100 Subject: [PATCH] Move creation of DeviceInfo outside try statement in SMA (#59821) --- homeassistant/components/sma/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/sma/__init__.py b/homeassistant/components/sma/__init__.py index 6a7243b0343..06be21d7ac6 100644 --- a/homeassistant/components/sma/__init__.py +++ b/homeassistant/components/sma/__init__.py @@ -145,14 +145,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: # Get updated device info sma_device_info = await sma.device_info() - device_info = DeviceInfo( - configuration_url=url, - identifiers={(DOMAIN, entry.unique_id)}, - manufacturer=sma_device_info["manufacturer"], - model=sma_device_info["type"], - name=sma_device_info["name"], - sw_version=sma_device_info["sw_version"], - ) # Get all device sensors sensor_def = await sma.get_sensors() except ( @@ -161,6 +153,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) as exc: raise ConfigEntryNotReady from exc + # Create DeviceInfo object from sma_device_info + device_info = DeviceInfo( + configuration_url=url, + identifiers={(DOMAIN, entry.unique_id)}, + manufacturer=sma_device_info["manufacturer"], + model=sma_device_info["type"], + name=sma_device_info["name"], + sw_version=sma_device_info["sw_version"], + ) + # Parse legacy options if initial setup was done from yaml if entry.source == SOURCE_IMPORT: config_sensors = _parse_legacy_options(entry, sensor_def)