mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Use async_update_entry rather than updating config_entry.data directly in Axis (#46078)
Don't step version in migrate_entry to support rollbacking
This commit is contained in:
parent
a74ae3585a
commit
94ecb792ec
@ -48,8 +48,11 @@ async def async_migrate_entry(hass, config_entry):
|
||||
|
||||
# Flatten configuration but keep old data if user rollbacks HASS prior to 0.106
|
||||
if config_entry.version == 1:
|
||||
config_entry.data = {**config_entry.data, **config_entry.data[CONF_DEVICE]}
|
||||
config_entry.unique_id = config_entry.data[CONF_MAC]
|
||||
unique_id = config_entry.data[CONF_MAC]
|
||||
data = {**config_entry.data, **config_entry.data[CONF_DEVICE]}
|
||||
hass.config_entries.async_update_entry(
|
||||
config_entry, unique_id=unique_id, data=data
|
||||
)
|
||||
config_entry.version = 2
|
||||
|
||||
# Normalise MAC address of device which also affects entity unique IDs
|
||||
@ -66,10 +69,12 @@ async def async_migrate_entry(hass, config_entry):
|
||||
)
|
||||
}
|
||||
|
||||
await async_migrate_entries(hass, config_entry.entry_id, update_unique_id)
|
||||
if old_unique_id != new_unique_id:
|
||||
await async_migrate_entries(hass, config_entry.entry_id, update_unique_id)
|
||||
|
||||
config_entry.unique_id = new_unique_id
|
||||
config_entry.version = 3
|
||||
hass.config_entries.async_update_entry(
|
||||
config_entry, unique_id=new_unique_id
|
||||
)
|
||||
|
||||
_LOGGER.info("Migration to version %s successful", config_entry.version)
|
||||
|
||||
|
@ -109,7 +109,7 @@ async def test_migrate_entry(hass):
|
||||
CONF_MODEL: "model",
|
||||
CONF_NAME: "name",
|
||||
}
|
||||
assert entry.version == 3
|
||||
assert entry.version == 2 # Keep version to support rollbacking
|
||||
assert entry.unique_id == "00:40:8c:12:34:56"
|
||||
|
||||
vmd4_entity = registry.async_get("binary_sensor.vmd4")
|
||||
|
Loading…
x
Reference in New Issue
Block a user