Cleanup deprecated async_get_registry in tests (#72059)
This commit is contained in:
parent
8492f282cb
commit
4eb46d45ca
19 changed files with 38 additions and 46 deletions
|
@ -49,7 +49,7 @@ async def test_async_setup_entry_auth_failed(hass: HomeAssistant):
|
|||
async def test_device_info(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
|
||||
"""Test device info."""
|
||||
entry = await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN)
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ async def test_update_failed(
|
|||
async def test_device_info(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
|
||||
"""Test device info."""
|
||||
entry = await async_init_integration(hass, aioclient_mock)
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||
assert device.model == HYPERION_MODEL_NAME
|
||||
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
||||
|
||||
entity_registry = await er.async_get_registry(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
entities_from_device = [
|
||||
entry.entity_id
|
||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||
|
|
|
@ -1331,7 +1331,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||
assert device.model == HYPERION_MODEL_NAME
|
||||
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
||||
|
||||
entity_registry = await er.async_get_registry(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
entities_from_device = [
|
||||
entry.entity_id
|
||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||
|
|
|
@ -172,7 +172,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||
assert device.model == HYPERION_MODEL_NAME
|
||||
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
||||
|
||||
entity_registry = await er.async_get_registry(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
entities_from_device = [
|
||||
entry.entity_id
|
||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||
|
|
|
@ -17,7 +17,7 @@ from homeassistant.components.insteon.api.device import (
|
|||
async_device_name,
|
||||
)
|
||||
from homeassistant.components.insteon.const import DOMAIN, MULTIPLE
|
||||
from homeassistant.helpers.device_registry import async_get_registry
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .const import MOCK_USER_INPUT_PLM
|
||||
from .mock_devices import MockDevices
|
||||
|
@ -40,7 +40,7 @@ async def _async_setup(hass, hass_ws_client):
|
|||
devices = MockDevices()
|
||||
await devices.async_load()
|
||||
|
||||
dev_reg = await async_get_registry(hass)
|
||||
dev_reg = dr.async_get(hass)
|
||||
# Create device registry entry for mock node
|
||||
ha_device = dev_reg.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
|
@ -94,7 +94,7 @@ async def test_no_insteon_device(hass, hass_ws_client):
|
|||
devices = MockDevices()
|
||||
await devices.async_load()
|
||||
|
||||
dev_reg = await async_get_registry(hass)
|
||||
dev_reg = dr.async_get(hass)
|
||||
# Create device registry entry for a Insteon device not in the Insteon devices list
|
||||
ha_device_1 = dev_reg.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
|
|
|
@ -6,10 +6,8 @@ from homeassistant.components.knx.const import CONF_STATE_ADDRESS, CONF_SYNC_STA
|
|||
from homeassistant.components.knx.schema import BinarySensorSchema
|
||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, STATE_OFF, STATE_ON
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_registry import (
|
||||
async_get_registry as async_get_entity_registry,
|
||||
)
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .conftest import KNXTestKit
|
||||
|
@ -35,7 +33,7 @@ async def test_binary_sensor_entity_category(hass: HomeAssistant, knx: KNXTestKi
|
|||
await knx.assert_read("1/1/1")
|
||||
await knx.receive_response("1/1/1", True)
|
||||
|
||||
registry = await async_get_entity_registry(hass)
|
||||
registry = er.async_get(hass)
|
||||
entity = registry.async_get("binary_sensor.test_normal")
|
||||
assert entity.entity_category is EntityCategory.DIAGNOSTIC
|
||||
|
||||
|
|
|
@ -4,10 +4,8 @@ from homeassistant.components.knx.const import KNX_ADDRESS
|
|||
from homeassistant.components.knx.schema import SceneSchema
|
||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_registry import (
|
||||
async_get_registry as async_get_entity_registry,
|
||||
)
|
||||
|
||||
from .conftest import KNXTestKit
|
||||
|
||||
|
@ -28,7 +26,7 @@ async def test_activate_knx_scene(hass: HomeAssistant, knx: KNXTestKit):
|
|||
)
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
||||
registry = await async_get_entity_registry(hass)
|
||||
registry = er.async_get(hass)
|
||||
entity = registry.async_get("scene.test")
|
||||
assert entity.entity_category is EntityCategory.DIAGNOSTIC
|
||||
assert entity.unique_id == "1/1/1_24"
|
||||
|
|
|
@ -76,7 +76,7 @@ async def test_unload_entry(hass):
|
|||
entry.add_to_hass(hass)
|
||||
|
||||
with patch.object(mikrotik, "MikrotikHub") as mock_hub, patch(
|
||||
"homeassistant.helpers.device_registry.async_get_registry",
|
||||
"homeassistant.helpers.device_registry.async_get",
|
||||
return_value=Mock(),
|
||||
):
|
||||
mock_hub.return_value.async_setup = AsyncMock(return_value=True)
|
||||
|
|
|
@ -42,7 +42,6 @@ from homeassistant.const import ATTR_DEVICE_ID, ATTR_ENTITY_ID, CONF_URL
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.device_registry import async_get_registry
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from . import (
|
||||
|
@ -138,8 +137,8 @@ async def test_setup_camera_new_data_same(hass: HomeAssistant) -> None:
|
|||
|
||||
async def test_setup_camera_new_data_camera_removed(hass: HomeAssistant) -> None:
|
||||
"""Test a data refresh with a removed camera."""
|
||||
device_registry = await async_get_registry(hass)
|
||||
entity_registry = await er.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
client = create_mock_motioneye_client()
|
||||
config_entry = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
@ -328,7 +327,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||
assert device.model == MOTIONEYE_MANUFACTURER
|
||||
assert device.name == TEST_CAMERA_NAME
|
||||
|
||||
entity_registry = await er.async_get_registry(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
entities_from_device = [
|
||||
entry.entity_id
|
||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||
|
|
|
@ -80,7 +80,7 @@ async def test_async_browse_media_success(hass: HomeAssistant) -> None:
|
|||
client = create_mock_motioneye_client()
|
||||
config = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_or_create(
|
||||
config_entry_id=config.entry_id,
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
|
||||
|
@ -301,7 +301,7 @@ async def test_async_browse_media_images_success(hass: HomeAssistant) -> None:
|
|||
client = create_mock_motioneye_client()
|
||||
config = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_or_create(
|
||||
config_entry_id=config.entry_id,
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
|
||||
|
@ -353,7 +353,7 @@ async def test_async_resolve_media_success(hass: HomeAssistant) -> None:
|
|||
|
||||
config = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_or_create(
|
||||
config_entry_id=config.entry_id,
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
|
||||
|
@ -391,7 +391,7 @@ async def test_async_resolve_media_failure(hass: HomeAssistant) -> None:
|
|||
|
||||
config = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_or_create(
|
||||
config_entry_id=config.entry_id,
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
|
||||
|
|
|
@ -91,7 +91,7 @@ async def test_sensor_device_info(hass: HomeAssistant) -> None:
|
|||
device = device_registry.async_get_device({device_identifer})
|
||||
assert device
|
||||
|
||||
entity_registry = await er.async_get_registry(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
entities_from_device = [
|
||||
entry.entity_id
|
||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||
|
|
|
@ -196,7 +196,7 @@ async def test_switch_device_info(hass: HomeAssistant) -> None:
|
|||
device = device_registry.async_get_device({device_identifer})
|
||||
assert device
|
||||
|
||||
entity_registry = await er.async_get_registry(hass)
|
||||
entity_registry = er.async_get(hass)
|
||||
entities_from_device = [
|
||||
entry.entity_id
|
||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||
|
|
|
@ -67,7 +67,7 @@ async def test_setup_camera_without_webhook(hass: HomeAssistant) -> None:
|
|||
client = create_mock_motioneye_client()
|
||||
config_entry = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}
|
||||
)
|
||||
|
@ -122,7 +122,7 @@ async def test_setup_camera_with_wrong_webhook(
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}
|
||||
)
|
||||
|
@ -175,7 +175,7 @@ async def test_setup_camera_with_old_webhook(
|
|||
)
|
||||
assert client.async_set_camera.called
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}
|
||||
)
|
||||
|
@ -211,7 +211,7 @@ async def test_setup_camera_with_correct_webhook(
|
|||
hass, data={CONF_URL: TEST_URL, CONF_WEBHOOK_ID: "webhook_secret_id"}
|
||||
)
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
|
||||
|
@ -281,7 +281,7 @@ async def test_good_query(hass: HomeAssistant, hass_client_no_auth: Any) -> None
|
|||
"""Test good callbacks."""
|
||||
await async_setup_component(hass, "http", {"http": {}})
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
client = create_mock_motioneye_client()
|
||||
config_entry = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
||||
|
@ -378,7 +378,7 @@ async def test_event_media_data(hass: HomeAssistant, hass_client_no_auth: Any) -
|
|||
"""Test an event with a file path generates media data."""
|
||||
await async_setup_component(hass, "http", {"http": {}})
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
client = create_mock_motioneye_client()
|
||||
config_entry = await setup_mock_motioneye_config_entry(hass, client=client)
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ async def test_config_flow_entry_migrate(hass):
|
|||
"homeassistant.util.location.async_detect_location_info",
|
||||
return_value=MOCK_LOCATION,
|
||||
), patch(
|
||||
"homeassistant.helpers.entity_registry.async_get_registry",
|
||||
"homeassistant.helpers.entity_registry.async_get",
|
||||
return_value=mock_e_registry,
|
||||
):
|
||||
await ps4.async_migrate_entry(hass, mock_entry)
|
||||
|
|
|
@ -41,7 +41,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||
entry = create_entry(hass)
|
||||
with patch_interface():
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
await hass.async_block_till_done()
|
||||
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ async def device_fixture(hass: HomeAssistant, mock_entry: MockEntityFixture):
|
|||
await hass.config_entries.async_setup(mock_entry.entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
return list(device_registry.devices.values())[0]
|
||||
|
||||
|
@ -48,7 +48,7 @@ async def subdevice_fixture(
|
|||
await hass.config_entries.async_setup(mock_entry.entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
return [d for d in device_registry.devices.values() if d.name != "UnifiProtect"][0]
|
||||
|
||||
|
|
|
@ -11,10 +11,7 @@ from homeassistant.components.uptimerobot.const import (
|
|||
)
|
||||
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import (
|
||||
async_entries_for_config_entry,
|
||||
async_get_registry,
|
||||
)
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .common import (
|
||||
|
@ -187,9 +184,9 @@ async def test_update_errors(hass: HomeAssistant, caplog: LogCaptureFixture):
|
|||
async def test_device_management(hass: HomeAssistant):
|
||||
"""Test that we are adding and removing devices for monitors returned from the API."""
|
||||
mock_entry = await setup_uptimerobot_integration(hass)
|
||||
dev_reg = await async_get_registry(hass)
|
||||
dev_reg = dr.async_get(hass)
|
||||
|
||||
devices = async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
|
||||
devices = dr.async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
|
||||
assert len(devices) == 1
|
||||
|
||||
assert devices[0].identifiers == {(DOMAIN, "1234")}
|
||||
|
@ -207,7 +204,7 @@ async def test_device_management(hass: HomeAssistant):
|
|||
async_fire_time_changed(hass, dt.utcnow() + COORDINATOR_UPDATE_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
devices = async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
|
||||
devices = dr.async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
|
||||
assert len(devices) == 2
|
||||
assert devices[0].identifiers == {(DOMAIN, "1234")}
|
||||
assert devices[1].identifiers == {(DOMAIN, "12345")}
|
||||
|
@ -224,7 +221,7 @@ async def test_device_management(hass: HomeAssistant):
|
|||
async_fire_time_changed(hass, dt.utcnow() + COORDINATOR_UPDATE_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
devices = async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
|
||||
devices = dr.async_entries_for_config_entry(dev_reg, mock_entry.entry_id)
|
||||
assert len(devices) == 1
|
||||
assert devices[0].identifiers == {(DOMAIN, "1234")}
|
||||
|
||||
|
|
|
@ -900,7 +900,7 @@ async def test_domain_control_unknown(hass, mock_entities):
|
|||
calls.append(call)
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.entity_registry.async_get_registry",
|
||||
"homeassistant.helpers.entity_registry.async_get",
|
||||
return_value=Mock(entities=mock_entities),
|
||||
):
|
||||
protected_mock_service = service.verify_domain_control(hass, "test_domain")(
|
||||
|
|
Loading…
Add table
Reference in a new issue