Remove tag_id from tag store (#118713)

pull/118845/head
Erik Montnemery 2024-06-03 17:15:57 +02:00 committed by Franck Nijhof
parent 85982d2b87
commit f3d1157bc4
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
3 changed files with 9 additions and 6 deletions

View File

@ -34,7 +34,7 @@ LAST_SCANNED = "last_scanned"
LAST_SCANNED_BY_DEVICE_ID = "last_scanned_by_device_id"
STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1
STORAGE_VERSION_MINOR = 2
STORAGE_VERSION_MINOR = 3
TAG_DATA: HassKey[TagStorageCollection] = HassKey(DOMAIN)
SIGNAL_TAG_CHANGED = "signal_tag_changed"
@ -109,6 +109,12 @@ class TagStore(Store[collection.SerializedStorageCollection]):
# Copy name in tag store to the entity registry
_create_entry(entity_registry, tag[CONF_ID], tag.get(CONF_NAME))
tag["migrated"] = True
if old_major_version == 1 and old_minor_version < 3:
# Version 1.3 removes tag_id from the store
for tag in data["items"]:
if TAG_ID not in tag:
continue
del tag[TAG_ID]
if old_major_version > 1:
raise NotImplementedError

View File

@ -7,7 +7,6 @@
'id': 'test tag id',
'migrated': True,
'name': 'test tag name',
'tag_id': 'test tag id',
}),
dict({
'device_id': 'some_scanner',
@ -20,7 +19,7 @@
]),
}),
'key': 'tag',
'minor_version': 2,
'minor_version': 3,
'version': 1,
})
# ---

View File

@ -97,9 +97,7 @@ async def test_migration(
await client.send_json_auto_id({"type": f"{DOMAIN}/list"})
resp = await client.receive_json()
assert resp["success"]
assert resp["result"] == [
{"id": TEST_TAG_ID, "name": "test tag name", "tag_id": TEST_TAG_ID}
]
assert resp["result"] == [{"id": TEST_TAG_ID, "name": "test tag name"}]
# Scan a new tag
await async_scan_tag(hass, "new tag", "some_scanner")