mirror of
https://github.com/home-assistant/core
synced 2024-10-05 17:38:03 +00:00
Adjust registry access in tests root (#88880)
This commit is contained in:
parent
0e4c32efe2
commit
1bed5c7775
|
@ -50,13 +50,13 @@ from homeassistant.core import (
|
||||||
callback,
|
callback,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
area_registry,
|
area_registry as ar,
|
||||||
device_registry,
|
device_registry as dr,
|
||||||
entity,
|
entity,
|
||||||
entity_platform,
|
entity_platform,
|
||||||
entity_registry,
|
entity_registry as er,
|
||||||
intent,
|
intent,
|
||||||
issue_registry,
|
issue_registry as ir,
|
||||||
recorder as recorder_helper,
|
recorder as recorder_helper,
|
||||||
restore_state,
|
restore_state,
|
||||||
storage,
|
storage,
|
||||||
|
@ -251,10 +251,10 @@ async def async_test_home_assistant(event_loop, load_registries=True):
|
||||||
if load_registries:
|
if load_registries:
|
||||||
with patch("homeassistant.helpers.storage.Store.async_load", return_value=None):
|
with patch("homeassistant.helpers.storage.Store.async_load", return_value=None):
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
area_registry.async_load(hass),
|
ar.async_load(hass),
|
||||||
device_registry.async_load(hass),
|
dr.async_load(hass),
|
||||||
entity_registry.async_load(hass),
|
er.async_load(hass),
|
||||||
issue_registry.async_load(hass),
|
ir.async_load(hass),
|
||||||
)
|
)
|
||||||
hass.data[bootstrap.DATA_REGISTRIES_LOADED] = None
|
hass.data[bootstrap.DATA_REGISTRIES_LOADED] = None
|
||||||
|
|
||||||
|
@ -481,8 +481,8 @@ def mock_component(hass: HomeAssistant, component: str) -> None:
|
||||||
|
|
||||||
def mock_registry(
|
def mock_registry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_entries: dict[str, entity_registry.RegistryEntry] | None = None,
|
mock_entries: dict[str, er.RegistryEntry] | None = None,
|
||||||
) -> entity_registry.EntityRegistry:
|
) -> er.EntityRegistry:
|
||||||
"""Mock the Entity Registry.
|
"""Mock the Entity Registry.
|
||||||
|
|
||||||
This should only be used if you need to mock/re-stage a clean mocked
|
This should only be used if you need to mock/re-stage a clean mocked
|
||||||
|
@ -494,20 +494,20 @@ def mock_registry(
|
||||||
If you just need to access the existing registry, use the `entity_registry`
|
If you just need to access the existing registry, use the `entity_registry`
|
||||||
fixture instead.
|
fixture instead.
|
||||||
"""
|
"""
|
||||||
registry = entity_registry.EntityRegistry(hass)
|
registry = er.EntityRegistry(hass)
|
||||||
if mock_entries is None:
|
if mock_entries is None:
|
||||||
mock_entries = {}
|
mock_entries = {}
|
||||||
registry.entities = entity_registry.EntityRegistryItems()
|
registry.entities = er.EntityRegistryItems()
|
||||||
for key, entry in mock_entries.items():
|
for key, entry in mock_entries.items():
|
||||||
registry.entities[key] = entry
|
registry.entities[key] = entry
|
||||||
|
|
||||||
hass.data[entity_registry.DATA_REGISTRY] = registry
|
hass.data[er.DATA_REGISTRY] = registry
|
||||||
return registry
|
return registry
|
||||||
|
|
||||||
|
|
||||||
def mock_area_registry(
|
def mock_area_registry(
|
||||||
hass: HomeAssistant, mock_entries: dict[str, area_registry.AreaEntry] | None = None
|
hass: HomeAssistant, mock_entries: dict[str, ar.AreaEntry] | None = None
|
||||||
) -> area_registry.AreaRegistry:
|
) -> ar.AreaRegistry:
|
||||||
"""Mock the Area Registry.
|
"""Mock the Area Registry.
|
||||||
|
|
||||||
This should only be used if you need to mock/re-stage a clean mocked
|
This should only be used if you need to mock/re-stage a clean mocked
|
||||||
|
@ -519,17 +519,17 @@ def mock_area_registry(
|
||||||
If you just need to access the existing registry, use the `area_registry`
|
If you just need to access the existing registry, use the `area_registry`
|
||||||
fixture instead.
|
fixture instead.
|
||||||
"""
|
"""
|
||||||
registry = area_registry.AreaRegistry(hass)
|
registry = ar.AreaRegistry(hass)
|
||||||
registry.areas = mock_entries or OrderedDict()
|
registry.areas = mock_entries or OrderedDict()
|
||||||
|
|
||||||
hass.data[area_registry.DATA_REGISTRY] = registry
|
hass.data[ar.DATA_REGISTRY] = registry
|
||||||
return registry
|
return registry
|
||||||
|
|
||||||
|
|
||||||
def mock_device_registry(
|
def mock_device_registry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_entries: dict[str, device_registry.DeviceEntry] | None = None,
|
mock_entries: dict[str, dr.DeviceEntry] | None = None,
|
||||||
) -> device_registry.DeviceRegistry:
|
) -> dr.DeviceRegistry:
|
||||||
"""Mock the Device Registry.
|
"""Mock the Device Registry.
|
||||||
|
|
||||||
This should only be used if you need to mock/re-stage a clean mocked
|
This should only be used if you need to mock/re-stage a clean mocked
|
||||||
|
@ -541,15 +541,15 @@ def mock_device_registry(
|
||||||
If you just need to access the existing registry, use the `device_registry`
|
If you just need to access the existing registry, use the `device_registry`
|
||||||
fixture instead.
|
fixture instead.
|
||||||
"""
|
"""
|
||||||
registry = device_registry.DeviceRegistry(hass)
|
registry = dr.DeviceRegistry(hass)
|
||||||
registry.devices = device_registry.DeviceRegistryItems()
|
registry.devices = dr.DeviceRegistryItems()
|
||||||
if mock_entries is None:
|
if mock_entries is None:
|
||||||
mock_entries = {}
|
mock_entries = {}
|
||||||
for key, entry in mock_entries.items():
|
for key, entry in mock_entries.items():
|
||||||
registry.devices[key] = entry
|
registry.devices[key] = entry
|
||||||
registry.deleted_devices = device_registry.DeviceRegistryItems()
|
registry.deleted_devices = dr.DeviceRegistryItems()
|
||||||
|
|
||||||
hass.data[device_registry.DATA_REGISTRY] = registry
|
hass.data[dr.DATA_REGISTRY] = registry
|
||||||
return registry
|
return registry
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue