1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add support for adding model_id in device info (#121989)

This commit is contained in:
Joost Lekkerkerker
2024-07-16 15:12:25 +02:00
committed by GitHub
parent 336740dbfa
commit f8ba4d41ba
66 changed files with 786 additions and 11 deletions

View File

@@ -201,6 +201,7 @@ async def test_loading_from_storage(
"labels": {"label1", "label2"},
"manufacturer": "manufacturer",
"model": "model",
"model_id": "model_id",
"name_by_user": "Test Friendly Name",
"name": "name",
"primary_config_entry": mock_config_entry.entry_id,
@@ -246,6 +247,7 @@ async def test_loading_from_storage(
labels={"label1", "label2"},
manufacturer="manufacturer",
model="model",
model_id="model_id",
name_by_user="Test Friendly Name",
name="name",
primary_config_entry=mock_config_entry.entry_id,
@@ -281,12 +283,12 @@ async def test_loading_from_storage(
@pytest.mark.parametrize("load_registries", [False])
async def test_migration_1_1_to_1_6(
async def test_migration_1_1_to_1_7(
hass: HomeAssistant,
hass_storage: dict[str, Any],
mock_config_entry: MockConfigEntry,
) -> None:
"""Test migration from version 1.1 to 1.6."""
"""Test migration from version 1.1 to 1.7."""
hass_storage[dr.STORAGE_KEY] = {
"version": 1,
"minor_version": 1,
@@ -373,6 +375,7 @@ async def test_migration_1_1_to_1_6(
"labels": [],
"manufacturer": "manufacturer",
"model": "model",
"model_id": None,
"name": "name",
"name_by_user": None,
"primary_config_entry": mock_config_entry.entry_id,
@@ -393,6 +396,7 @@ async def test_migration_1_1_to_1_6(
"labels": [],
"manufacturer": None,
"model": None,
"model_id": None,
"name_by_user": None,
"name": None,
"primary_config_entry": None,
@@ -415,12 +419,12 @@ async def test_migration_1_1_to_1_6(
@pytest.mark.parametrize("load_registries", [False])
async def test_migration_1_2_to_1_6(
async def test_migration_1_2_to_1_7(
hass: HomeAssistant,
hass_storage: dict[str, Any],
mock_config_entry: MockConfigEntry,
) -> None:
"""Test migration from version 1.2 to 1.6."""
"""Test migration from version 1.2 to 1.7."""
hass_storage[dr.STORAGE_KEY] = {
"version": 1,
"minor_version": 2,
@@ -506,6 +510,7 @@ async def test_migration_1_2_to_1_6(
"labels": [],
"manufacturer": "manufacturer",
"model": "model",
"model_id": None,
"name": "name",
"name_by_user": None,
"primary_config_entry": mock_config_entry.entry_id,
@@ -526,6 +531,7 @@ async def test_migration_1_2_to_1_6(
"labels": [],
"manufacturer": None,
"model": None,
"model_id": None,
"name_by_user": None,
"name": None,
"primary_config_entry": None,
@@ -540,12 +546,12 @@ async def test_migration_1_2_to_1_6(
@pytest.mark.parametrize("load_registries", [False])
async def test_migration_1_3_to_1_6(
async def test_migration_1_3_to_1_7(
hass: HomeAssistant,
hass_storage: dict[str, Any],
mock_config_entry: MockConfigEntry,
) -> None:
"""Test migration from version 1.3 to 1.6."""
"""Test migration from version 1.3 to 1.7."""
hass_storage[dr.STORAGE_KEY] = {
"version": 1,
"minor_version": 3,
@@ -633,6 +639,7 @@ async def test_migration_1_3_to_1_6(
"labels": [],
"manufacturer": "manufacturer",
"model": "model",
"model_id": None,
"name": "name",
"name_by_user": None,
"primary_config_entry": mock_config_entry.entry_id,
@@ -653,6 +660,7 @@ async def test_migration_1_3_to_1_6(
"labels": [],
"manufacturer": None,
"model": None,
"model_id": None,
"name": None,
"name_by_user": None,
"primary_config_entry": None,
@@ -667,12 +675,12 @@ async def test_migration_1_3_to_1_6(
@pytest.mark.parametrize("load_registries", [False])
async def test_migration_1_4_to_1_6(
async def test_migration_1_4_to_1_7(
hass: HomeAssistant,
hass_storage: dict[str, Any],
mock_config_entry: MockConfigEntry,
) -> None:
"""Test migration from version 1.4 to 1.6."""
"""Test migration from version 1.4 to 1.7."""
hass_storage[dr.STORAGE_KEY] = {
"version": 1,
"minor_version": 4,
@@ -762,6 +770,7 @@ async def test_migration_1_4_to_1_6(
"labels": [],
"manufacturer": "manufacturer",
"model": "model",
"model_id": None,
"name": "name",
"name_by_user": None,
"primary_config_entry": mock_config_entry.entry_id,
@@ -782,6 +791,7 @@ async def test_migration_1_4_to_1_6(
"labels": [],
"manufacturer": None,
"model": None,
"model_id": None,
"name_by_user": None,
"name": None,
"primary_config_entry": None,
@@ -796,12 +806,12 @@ async def test_migration_1_4_to_1_6(
@pytest.mark.parametrize("load_registries", [False])
async def test_migration_1_5_to_1_6(
async def test_migration_1_5_to_1_7(
hass: HomeAssistant,
hass_storage: dict[str, Any],
mock_config_entry: MockConfigEntry,
) -> None:
"""Test migration from version 1.5 to 1.6."""
"""Test migration from version 1.5 to 1.7."""
hass_storage[dr.STORAGE_KEY] = {
"version": 1,
"minor_version": 5,
@@ -894,6 +904,7 @@ async def test_migration_1_5_to_1_6(
"manufacturer": "manufacturer",
"model": "model",
"name": "name",
"model_id": None,
"name_by_user": None,
"primary_config_entry": mock_config_entry.entry_id,
"serial_number": None,
@@ -913,6 +924,142 @@ async def test_migration_1_5_to_1_6(
"labels": ["blah"],
"manufacturer": None,
"model": None,
"model_id": None,
"name_by_user": None,
"name": None,
"primary_config_entry": None,
"serial_number": None,
"sw_version": None,
"via_device_id": None,
},
],
"deleted_devices": [],
},
}
@pytest.mark.parametrize("load_registries", [False])
async def test_migration_1_6_to_1_7(
hass: HomeAssistant,
hass_storage: dict[str, Any],
mock_config_entry: MockConfigEntry,
) -> None:
"""Test migration from version 1.6 to 1.7."""
hass_storage[dr.STORAGE_KEY] = {
"version": 1,
"minor_version": 6,
"key": dr.STORAGE_KEY,
"data": {
"devices": [
{
"area_id": None,
"config_entries": [mock_config_entry.entry_id],
"configuration_url": None,
"connections": [["Zigbee", "01.23.45.67.89"]],
"disabled_by": None,
"entry_type": "service",
"hw_version": "hw_version",
"id": "abcdefghijklm",
"identifiers": [["serial", "123456ABCDEF"]],
"labels": ["blah"],
"manufacturer": "manufacturer",
"model": "model",
"name": "name",
"name_by_user": None,
"primary_config_entry": mock_config_entry.entry_id,
"serial_number": None,
"sw_version": "new_version",
"via_device_id": None,
},
{
"area_id": None,
"config_entries": [None],
"configuration_url": None,
"connections": [],
"disabled_by": None,
"entry_type": None,
"hw_version": None,
"id": "invalid-entry-type",
"identifiers": [["serial", "mock-id-invalid-entry"]],
"labels": ["blah"],
"manufacturer": None,
"model": None,
"name_by_user": None,
"primary_config_entry": None,
"name": None,
"serial_number": None,
"sw_version": None,
"via_device_id": None,
},
],
"deleted_devices": [],
},
}
await dr.async_load(hass)
registry = dr.async_get(hass)
# Test data was loaded
entry = registry.async_get_or_create(
config_entry_id=mock_config_entry.entry_id,
connections={("Zigbee", "01.23.45.67.89")},
identifiers={("serial", "123456ABCDEF")},
)
assert entry.id == "abcdefghijklm"
# Update to trigger a store
entry = registry.async_get_or_create(
config_entry_id=mock_config_entry.entry_id,
connections={("Zigbee", "01.23.45.67.89")},
identifiers={("serial", "123456ABCDEF")},
sw_version="new_version",
)
assert entry.id == "abcdefghijklm"
# Check we store migrated data
await flush_store(registry._store)
assert hass_storage[dr.STORAGE_KEY] == {
"version": dr.STORAGE_VERSION_MAJOR,
"minor_version": dr.STORAGE_VERSION_MINOR,
"key": dr.STORAGE_KEY,
"data": {
"devices": [
{
"area_id": None,
"config_entries": [mock_config_entry.entry_id],
"configuration_url": None,
"connections": [["Zigbee", "01.23.45.67.89"]],
"disabled_by": None,
"entry_type": "service",
"hw_version": "hw_version",
"id": "abcdefghijklm",
"identifiers": [["serial", "123456ABCDEF"]],
"labels": ["blah"],
"manufacturer": "manufacturer",
"model": "model",
"name": "name",
"model_id": None,
"name_by_user": None,
"primary_config_entry": mock_config_entry.entry_id,
"serial_number": None,
"sw_version": "new_version",
"via_device_id": None,
},
{
"area_id": None,
"config_entries": [None],
"configuration_url": None,
"connections": [],
"disabled_by": None,
"entry_type": None,
"hw_version": None,
"id": "invalid-entry-type",
"identifiers": [["serial", "mock-id-invalid-entry"]],
"labels": ["blah"],
"manufacturer": None,
"model": None,
"model_id": None,
"name_by_user": None,
"name": None,
"primary_config_entry": None,
@@ -1424,6 +1571,7 @@ async def test_update(
labels={"label1", "label2"},
manufacturer="Test Producer",
model="Test Model",
model_id="Test Model Name",
name_by_user="Test Friendly Name",
name="name",
new_connections=new_connections,
@@ -1449,6 +1597,7 @@ async def test_update(
labels={"label1", "label2"},
manufacturer="Test Producer",
model="Test Model",
model_id="Test Model Name",
name_by_user="Test Friendly Name",
name="name",
serial_number="serial_no",
@@ -1503,6 +1652,7 @@ async def test_update(
"labels": set(),
"manufacturer": None,
"model": None,
"model_id": None,
"name": None,
"name_by_user": None,
"serial_number": None,
@@ -2474,6 +2624,7 @@ async def test_loading_invalid_configuration_url_from_storage(
"labels": [],
"manufacturer": None,
"model": None,
"model_id": None,
"name_by_user": None,
"name": None,
"primary_config_entry": "1234",