Add guard for already migrated Hue entity (#59930)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
pull/60058/head
Marcel van der Veldt 2021-11-20 23:46:11 +01:00 committed by GitHub
parent 4820acb897
commit 7161a0bf2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 2 deletions

View File

@ -147,7 +147,18 @@ async def handle_v2_migration(hass: core.HomeAssistant, entry: ConfigEntry) -> N
ent.unique_id,
new_unique_id,
)
ent_reg.async_update_entity(ent.entity_id, new_unique_id=sensor.id)
try:
ent_reg.async_update_entity(
ent.entity_id, new_unique_id=sensor.id
)
except ValueError:
# assume edge case where the entity was already migrated in a previous run
# which got aborted somehow and we do not want
# to crash the entire integration init
LOGGER.warning(
"Skip migration of %s because it already exists",
ent.entity_id,
)
break
# migrate entities that are not connected to a device (groups)
@ -170,5 +181,14 @@ async def handle_v2_migration(hass: core.HomeAssistant, entry: ConfigEntry) -> N
ent.unique_id,
new_unique_id,
)
try:
ent_reg.async_update_entity(ent.entity_id, new_unique_id=new_unique_id)
except ValueError:
# assume edge case where the entity was already migrated in a previous run
# which got aborted somehow and we do not want
# to crash the entire integration init
LOGGER.warning(
"Skip migration of %s because it already exists",
ent.entity_id,
)
LOGGER.info("Migration of devices and entities to support API schema 2 finished")