Skip to content

Commit

Permalink
Migrate trafikverket_camera to use async_update_entry to alter config…
Browse files Browse the repository at this point in the history
… entries (home-assistant#110393)
  • Loading branch information
bdraco authored Feb 12, 2024
1 parent 6e4fd69 commit 2f0d294
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions homeassistant/components/trafikverket_camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return False

if camera_id := camera_info.camera_id:
entry.version = 2
hass.config_entries.async_update_entry(
entry,
unique_id=f"{DOMAIN}-{camera_id}",
version=2,
)
_LOGGER.debug(
"Migrated Trafikverket Camera config entry unique id to %s",
Expand All @@ -84,15 +84,14 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return False

if camera_id := camera_info.camera_id:
entry.version = 3
_LOGGER.debug(
"Migrate Trafikverket Camera config entry unique id to %s",
camera_id,
)
new_data = entry.data.copy()
new_data.pop(CONF_LOCATION)
new_data[CONF_ID] = camera_id
hass.config_entries.async_update_entry(entry, data=new_data)
hass.config_entries.async_update_entry(entry, data=new_data, version=3)
return True
_LOGGER.error("Could not migrate the config entry. Camera has no id")
return False
Expand Down

0 comments on commit 2f0d294

Please sign in to comment.