Move creation of DeviceInfo outside try statement in SMA (#59821)

This commit is contained in:
René Klomp 2021-11-17 11:28:18 +01:00 committed by GitHub
parent 5133269e2b
commit ac96c7bb1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)