Remove tag_id from tag store (#118713)

This commit is contained in:
Erik Montnemery 2024-06-03 17:15:57 +02:00 committed by GitHub
parent 01b4589ef6
commit 99e02fe2b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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" LAST_SCANNED_BY_DEVICE_ID = "last_scanned_by_device_id"
STORAGE_KEY = DOMAIN STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1 STORAGE_VERSION = 1
STORAGE_VERSION_MINOR = 2 STORAGE_VERSION_MINOR = 3
TAG_DATA: HassKey[TagStorageCollection] = HassKey(DOMAIN) TAG_DATA: HassKey[TagStorageCollection] = HassKey(DOMAIN)
SIGNAL_TAG_CHANGED = "signal_tag_changed" SIGNAL_TAG_CHANGED = "signal_tag_changed"
@ -109,6 +109,12 @@ class TagStore(Store[collection.SerializedStorageCollection]):
# Copy name in tag store to the entity registry # Copy name in tag store to the entity registry
_create_entry(entity_registry, tag[CONF_ID], tag.get(CONF_NAME)) _create_entry(entity_registry, tag[CONF_ID], tag.get(CONF_NAME))
tag["migrated"] = True 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: if old_major_version > 1:
raise NotImplementedError raise NotImplementedError

View File

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

View File

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