mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 14:29:21 -04:00
Do not cache Matter device info forever (#183341)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""The Matter integration."""
|
||||
|
||||
import asyncio
|
||||
from functools import cache
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from aiohasupervisor.models import InterfaceMethod
|
||||
@@ -63,7 +62,6 @@ CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
@callback
|
||||
@cache
|
||||
def get_matter_device_info(
|
||||
hass: HomeAssistant, device_id: str
|
||||
) -> MatterDeviceInfo | None:
|
||||
|
||||
@@ -15,7 +15,10 @@ from matter_server.client.exceptions import (
|
||||
from matter_server.common.errors import MatterError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.matter import _derive_ble_proxy_url
|
||||
from homeassistant.components.matter import (
|
||||
_derive_ble_proxy_url,
|
||||
get_matter_device_info,
|
||||
)
|
||||
from homeassistant.components.matter.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryDisabler, ConfigEntryState
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_UNAVAILABLE
|
||||
@@ -988,6 +991,38 @@ async def test_remove_config_entry_device_rejects_child_device(
|
||||
assert device_registry.async_get(child_device.id)
|
||||
|
||||
|
||||
async def test_get_matter_device_info(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test Matter device info follows the loaded state of the integration."""
|
||||
node = await setup_integration_with_node_fixture(
|
||||
hass, "device_diagnostics", matter_client
|
||||
)
|
||||
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
device_entry = dr.async_entries_for_config_entry(
|
||||
device_registry, config_entry.entry_id
|
||||
)[0]
|
||||
expected_device_info = {
|
||||
"unique_id": node.device_info.uniqueID,
|
||||
"vendor_id": hex(node.device_info.vendorID),
|
||||
"product_id": hex(node.device_info.productID),
|
||||
}
|
||||
|
||||
assert get_matter_device_info(hass, device_entry.id) == expected_device_info
|
||||
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert get_matter_device_info(hass, device_entry.id) is None
|
||||
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert get_matter_device_info(hass, device_entry.id) == expected_device_info
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("matter_ws_url", "expected"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user