Update tests p-s to use async_get() instead of async_get_registry() (#47654)

This commit is contained in:
Erik Montnemery 2021-03-09 14:28:32 +01:00 committed by GitHub
parent b3fecb1c95
commit ba2978c693
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 103 additions and 86 deletions

View file

@ -22,7 +22,7 @@ from homeassistant.const import (
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.core import Context, CoreState, State from homeassistant.core import Context, CoreState, State
from homeassistant.helpers import collection, entity_registry from homeassistant.helpers import collection, entity_registry as er
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import mock_component, mock_restore_cache from tests.common import mock_component, mock_restore_cache
@ -589,7 +589,7 @@ async def test_ws_delete(hass, hass_ws_client, storage_setup):
assert resp["success"] assert resp["success"]
assert len(hass.states.async_entity_ids("person")) == 0 assert len(hass.states.async_entity_ids("person")) == 0
ent_reg = await hass.helpers.entity_registry.async_get_registry() ent_reg = er.async_get(hass)
assert not ent_reg.async_is_registered("person.tracked_person") assert not ent_reg.async_is_registered("person.tracked_person")
@ -681,7 +681,7 @@ async def test_update_person_when_user_removed(
async def test_removing_device_tracker(hass, storage_setup): async def test_removing_device_tracker(hass, storage_setup):
"""Test we automatically remove removed device trackers.""" """Test we automatically remove removed device trackers."""
storage_collection = hass.data[DOMAIN][1] storage_collection = hass.data[DOMAIN][1]
reg = await entity_registry.async_get_registry(hass) reg = er.async_get(hass)
entry = reg.async_get_or_create( entry = reg.async_get_or_create(
"device_tracker", "mobile_app", "bla", suggested_object_id="pixel" "device_tracker", "mobile_app", "bla", suggested_object_id="pixel"
) )

View file

@ -1,9 +1,9 @@
"""The sensor tests for the powerwall platform.""" """The sensor tests for the powerwall platform."""
from unittest.mock import patch from unittest.mock import patch
from homeassistant.components.powerwall.const import DOMAIN from homeassistant.components.powerwall.const import DOMAIN
from homeassistant.const import CONF_IP_ADDRESS, PERCENTAGE from homeassistant.const import CONF_IP_ADDRESS, PERCENTAGE
from homeassistant.helpers import device_registry as dr
from .mocks import _mock_powerwall_with_fixtures from .mocks import _mock_powerwall_with_fixtures
@ -26,7 +26,7 @@ async def test_sensors(hass):
assert await hass.config_entries.async_setup(config_entry.entry_id) assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device( reg_device = device_registry.async_get_device(
identifiers={("powerwall", "TG0123456789AB_TG9876543210BA")}, identifiers={("powerwall", "TG0123456789AB_TG9876543210BA")},
) )

View file

@ -7,7 +7,7 @@ from pytz import timezone
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.pvpc_hourly_pricing import ATTR_TARIFF, DOMAIN from homeassistant.components.pvpc_hourly_pricing import ATTR_TARIFF, DOMAIN
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
from homeassistant.helpers import entity_registry from homeassistant.helpers import entity_registry as er
from .conftest import check_valid_state from .conftest import check_valid_state
@ -60,7 +60,7 @@ async def test_config_flow(
assert pvpc_aioclient_mock.call_count == 1 assert pvpc_aioclient_mock.call_count == 1
# Check removal # Check removal
registry = await entity_registry.async_get_registry(hass) registry = er.async_get(hass)
registry_entity = registry.async_get("sensor.test") registry_entity = registry.async_get("sensor.test")
assert await hass.config_entries.async_remove(registry_entity.config_entry_id) assert await hass.config_entries.async_remove(registry_entity.config_entry_id)

View file

@ -6,13 +6,7 @@ import serial.tools.list_ports
from homeassistant import config_entries, data_entry_flow, setup from homeassistant import config_entries, data_entry_flow, setup
from homeassistant.components.rfxtrx import DOMAIN, config_flow from homeassistant.components.rfxtrx import DOMAIN, config_flow
from homeassistant.helpers.device_registry import ( from homeassistant.helpers import device_registry as dr, entity_registry as er
async_entries_for_config_entry,
async_get_registry as async_get_device_registry,
)
from homeassistant.helpers.entity_registry import (
async_get_registry as async_get_entity_registry,
)
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -610,8 +604,8 @@ async def test_options_add_remove_device(hass):
assert state.state == "off" assert state.state == "off"
assert state.attributes.get("friendly_name") == "AC 213c7f2:48" assert state.attributes.get("friendly_name") == "AC 213c7f2:48"
device_registry = await async_get_device_registry(hass) device_registry = dr.async_get(hass)
device_entries = async_entries_for_config_entry(device_registry, entry.entry_id) device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
assert device_entries[0].id assert device_entries[0].id
@ -704,8 +698,8 @@ async def test_options_replace_sensor_device(hass):
) )
assert state assert state
device_registry = await async_get_device_registry(hass) device_registry = dr.async_get(hass)
device_entries = async_entries_for_config_entry(device_registry, entry.entry_id) device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
old_device = next( old_device = next(
( (
@ -751,7 +745,7 @@ async def test_options_replace_sensor_device(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
entity_registry = await async_get_entity_registry(hass) entity_registry = er.async_get(hass)
entry = entity_registry.async_get( entry = entity_registry.async_get(
"sensor.thgn122_123_thgn132_thgr122_228_238_268_f0_04_rssi_numeric" "sensor.thgn122_123_thgn132_thgr122_228_238_268_f0_04_rssi_numeric"
@ -843,8 +837,8 @@ async def test_options_replace_control_device(hass):
state = hass.states.get("switch.ac_1118cdea_2") state = hass.states.get("switch.ac_1118cdea_2")
assert state assert state
device_registry = await async_get_device_registry(hass) device_registry = dr.async_get(hass)
device_entries = async_entries_for_config_entry(device_registry, entry.entry_id) device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
old_device = next( old_device = next(
( (
@ -890,7 +884,7 @@ async def test_options_replace_control_device(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
entity_registry = await async_get_entity_registry(hass) entity_registry = er.async_get(hass)
entry = entity_registry.async_get("binary_sensor.ac_118cdea_2") entry = entity_registry.async_get("binary_sensor.ac_118cdea_2")
assert entry assert entry
@ -941,8 +935,8 @@ async def test_options_remove_multiple_devices(hass):
state = hass.states.get("binary_sensor.ac_1118cdea_2") state = hass.states.get("binary_sensor.ac_1118cdea_2")
assert state assert state
device_registry = await async_get_device_registry(hass) device_registry = dr.async_get(hass)
device_entries = async_entries_for_config_entry(device_registry, entry.entry_id) device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
assert len(device_entries) == 3 assert len(device_entries) == 3
@ -1061,8 +1055,8 @@ async def test_options_add_and_configure_device(hass):
assert state.state == "off" assert state.state == "off"
assert state.attributes.get("friendly_name") == "PT2262 22670e" assert state.attributes.get("friendly_name") == "PT2262 22670e"
device_registry = await async_get_device_registry(hass) device_registry = dr.async_get(hass)
device_entries = async_entries_for_config_entry(device_registry, entry.entry_id) device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
assert device_entries[0].id assert device_entries[0].id
@ -1151,8 +1145,8 @@ async def test_options_configure_rfy_cover_device(hass):
assert entry.data["devices"]["071a000001020301"]["venetian_blind_mode"] == "EU" assert entry.data["devices"]["071a000001020301"]["venetian_blind_mode"] == "EU"
device_registry = await async_get_device_registry(hass) device_registry = dr.async_get(hass)
device_entries = async_entries_for_config_entry(device_registry, entry.entry_id) device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
assert device_entries[0].id assert device_entries[0].id

View file

@ -5,10 +5,7 @@ from unittest.mock import call
from homeassistant.components.rfxtrx import DOMAIN from homeassistant.components.rfxtrx import DOMAIN
from homeassistant.components.rfxtrx.const import EVENT_RFXTRX_EVENT from homeassistant.components.rfxtrx.const import EVENT_RFXTRX_EVENT
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.device_registry import ( from homeassistant.helpers import device_registry as dr
DeviceRegistry,
async_get_registry as async_get_device_registry,
)
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -79,7 +76,7 @@ async def test_fire_event(hass, rfxtrx):
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_start() await hass.async_start()
device_registry: DeviceRegistry = await async_get_device_registry(hass) device_registry: dr.DeviceRegistry = dr.async_get(hass)
calls = [] calls = []

View file

@ -1,5 +1,6 @@
"""The tests for the Ring light platform.""" """The tests for the Ring light platform."""
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.helpers import entity_registry as er
from .common import setup_platform from .common import setup_platform
@ -9,7 +10,7 @@ from tests.common import load_fixture
async def test_entity_registry(hass, requests_mock): async def test_entity_registry(hass, requests_mock):
"""Tests that the devices are registered in the entity registry.""" """Tests that the devices are registered in the entity registry."""
await setup_platform(hass, LIGHT_DOMAIN) await setup_platform(hass, LIGHT_DOMAIN)
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
entry = entity_registry.async_get("light.front_light") entry = entity_registry.async_get("light.front_light")
assert entry.unique_id == 765432 assert entry.unique_id == 765432

View file

@ -1,5 +1,6 @@
"""The tests for the Ring switch platform.""" """The tests for the Ring switch platform."""
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.helpers import entity_registry as er
from .common import setup_platform from .common import setup_platform
@ -9,7 +10,7 @@ from tests.common import load_fixture
async def test_entity_registry(hass, requests_mock): async def test_entity_registry(hass, requests_mock):
"""Tests that the devices are registered in the entity registry.""" """Tests that the devices are registered in the entity registry."""
await setup_platform(hass, SWITCH_DOMAIN) await setup_platform(hass, SWITCH_DOMAIN)
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
entry = entity_registry.async_get("switch.front_siren") entry = entity_registry.async_get("switch.front_siren")
assert entry.unique_id == "765432-siren" assert entry.unique_id == "765432-siren"

View file

@ -27,6 +27,7 @@ from homeassistant.const import (
STATE_ALARM_TRIGGERED, STATE_ALARM_TRIGGERED,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.entity_component import async_update_entity
from .util import TEST_CONFIG, TEST_SITE_UUID, setup_risco from .util import TEST_CONFIG, TEST_SITE_UUID, setup_risco
@ -114,7 +115,7 @@ async def test_cannot_connect(hass):
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID) assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID) assert not registry.async_is_registered(SECOND_ENTITY_ID)
@ -130,14 +131,14 @@ async def test_unauthorized(hass):
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID) assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID) assert not registry.async_is_registered(SECOND_ENTITY_ID)
async def test_setup(hass, two_part_alarm): async def test_setup(hass, two_part_alarm):
"""Test entity setup.""" """Test entity setup."""
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID) assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID) assert not registry.async_is_registered(SECOND_ENTITY_ID)
@ -147,7 +148,7 @@ async def test_setup(hass, two_part_alarm):
assert registry.async_is_registered(FIRST_ENTITY_ID) assert registry.async_is_registered(FIRST_ENTITY_ID)
assert registry.async_is_registered(SECOND_ENTITY_ID) assert registry.async_is_registered(SECOND_ENTITY_ID)
registry = await hass.helpers.device_registry.async_get_registry() registry = dr.async_get(hass)
device = registry.async_get_device({(DOMAIN, TEST_SITE_UUID + "_0")}) device = registry.async_get_device({(DOMAIN, TEST_SITE_UUID + "_0")})
assert device is not None assert device is not None
assert device.manufacturer == "Risco" assert device.manufacturer == "Risco"
@ -251,7 +252,7 @@ async def test_sets_custom_mapping(hass, two_part_alarm):
"""Test settings the various modes when mapping some states.""" """Test settings the various modes when mapping some states."""
await setup_risco(hass, [], CUSTOM_MAPPING_OPTIONS) await setup_risco(hass, [], CUSTOM_MAPPING_OPTIONS)
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
entity = registry.async_get(FIRST_ENTITY_ID) entity = registry.async_get(FIRST_ENTITY_ID)
assert entity.supported_features == EXPECTED_FEATURES assert entity.supported_features == EXPECTED_FEATURES
@ -277,7 +278,7 @@ async def test_sets_full_custom_mapping(hass, two_part_alarm):
"""Test settings the various modes when mapping all states.""" """Test settings the various modes when mapping all states."""
await setup_risco(hass, [], FULL_CUSTOM_MAPPING) await setup_risco(hass, [], FULL_CUSTOM_MAPPING)
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
entity = registry.async_get(FIRST_ENTITY_ID) entity = registry.async_get(FIRST_ENTITY_ID)
assert ( assert (
entity.supported_features == EXPECTED_FEATURES | SUPPORT_ALARM_ARM_CUSTOM_BYPASS entity.supported_features == EXPECTED_FEATURES | SUPPORT_ALARM_ARM_CUSTOM_BYPASS

View file

@ -4,6 +4,7 @@ from unittest.mock import PropertyMock, patch
from homeassistant.components.risco import CannotConnectError, UnauthorizedError from homeassistant.components.risco import CannotConnectError, UnauthorizedError
from homeassistant.components.risco.const import DOMAIN from homeassistant.components.risco.const import DOMAIN
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.entity_component import async_update_entity
from .util import TEST_CONFIG, TEST_SITE_UUID, setup_risco from .util import TEST_CONFIG, TEST_SITE_UUID, setup_risco
@ -26,7 +27,7 @@ async def test_cannot_connect(hass):
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID) assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID) assert not registry.async_is_registered(SECOND_ENTITY_ID)
@ -42,14 +43,14 @@ async def test_unauthorized(hass):
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID) assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID) assert not registry.async_is_registered(SECOND_ENTITY_ID)
async def test_setup(hass, two_zone_alarm): # noqa: F811 async def test_setup(hass, two_zone_alarm): # noqa: F811
"""Test entity setup.""" """Test entity setup."""
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
assert not registry.async_is_registered(FIRST_ENTITY_ID) assert not registry.async_is_registered(FIRST_ENTITY_ID)
assert not registry.async_is_registered(SECOND_ENTITY_ID) assert not registry.async_is_registered(SECOND_ENTITY_ID)
@ -59,7 +60,7 @@ async def test_setup(hass, two_zone_alarm): # noqa: F811
assert registry.async_is_registered(FIRST_ENTITY_ID) assert registry.async_is_registered(FIRST_ENTITY_ID)
assert registry.async_is_registered(SECOND_ENTITY_ID) assert registry.async_is_registered(SECOND_ENTITY_ID)
registry = await hass.helpers.device_registry.async_get_registry() registry = dr.async_get(hass)
device = registry.async_get_device({(DOMAIN, TEST_SITE_UUID + "_zone_0")}) device = registry.async_get_device({(DOMAIN, TEST_SITE_UUID + "_zone_0")})
assert device is not None assert device is not None
assert device.manufacturer == "Risco" assert device.manufacturer == "Risco"

View file

@ -8,6 +8,7 @@ from homeassistant.components.risco import (
UnauthorizedError, UnauthorizedError,
) )
from homeassistant.components.risco.const import DOMAIN from homeassistant.components.risco.const import DOMAIN
from homeassistant.helpers import entity_registry as er
from homeassistant.util import dt from homeassistant.util import dt
from .util import TEST_CONFIG, TEST_SITE_UUID, setup_risco from .util import TEST_CONFIG, TEST_SITE_UUID, setup_risco
@ -120,7 +121,7 @@ async def test_cannot_connect(hass):
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
for id in ENTITY_IDS.values(): for id in ENTITY_IDS.values():
assert not registry.async_is_registered(id) assert not registry.async_is_registered(id)
@ -137,7 +138,7 @@ async def test_unauthorized(hass):
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
for id in ENTITY_IDS.values(): for id in ENTITY_IDS.values():
assert not registry.async_is_registered(id) assert not registry.async_is_registered(id)
@ -167,7 +168,7 @@ def _check_state(hass, category, entity_id):
async def test_setup(hass, two_zone_alarm): # noqa: F811 async def test_setup(hass, two_zone_alarm): # noqa: F811
"""Test entity setup.""" """Test entity setup."""
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
for id in ENTITY_IDS.values(): for id in ENTITY_IDS.values():
assert not registry.async_is_registered(id) assert not registry.async_is_registered(id)

View file

@ -61,6 +61,7 @@ from homeassistant.const import (
STATE_STANDBY, STATE_STANDBY,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
@ -85,7 +86,7 @@ async def test_setup(
"""Test setup with basic config.""" """Test setup with basic config."""
await setup_integration(hass, aioclient_mock) await setup_integration(hass, aioclient_mock)
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
main = entity_registry.async_get(MAIN_ENTITY_ID) main = entity_registry.async_get(MAIN_ENTITY_ID)
assert hass.states.get(MAIN_ENTITY_ID) assert hass.states.get(MAIN_ENTITY_ID)
@ -117,7 +118,7 @@ async def test_tv_setup(
unique_id=TV_SERIAL, unique_id=TV_SERIAL,
) )
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
tv = entity_registry.async_get(TV_ENTITY_ID) tv = entity_registry.async_get(TV_ENTITY_ID)
assert hass.states.get(TV_ENTITY_ID) assert hass.states.get(TV_ENTITY_ID)
@ -321,7 +322,7 @@ async def test_tv_device_registry(
unique_id=TV_SERIAL, unique_id=TV_SERIAL,
) )
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device(identifiers={(DOMAIN, TV_SERIAL)}) reg_device = device_registry.async_get_device(identifiers={(DOMAIN, TV_SERIAL)})
assert reg_device.model == TV_MODEL assert reg_device.model == TV_MODEL

View file

@ -7,6 +7,7 @@ from homeassistant.components.remote import (
SERVICE_SEND_COMMAND, SERVICE_SEND_COMMAND,
) )
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from tests.components.roku import UPNP_SERIAL, setup_integration from tests.components.roku import UPNP_SERIAL, setup_integration
@ -31,7 +32,7 @@ async def test_unique_id(
"""Test unique id.""" """Test unique id."""
await setup_integration(hass, aioclient_mock) await setup_integration(hass, aioclient_mock)
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
main = entity_registry.async_get(MAIN_ENTITY_ID) main = entity_registry.async_get(MAIN_ENTITY_ID)
assert main.unique_id == UPNP_SERIAL assert main.unique_id == UPNP_SERIAL

View file

@ -5,7 +5,7 @@ from unittest.mock import patch
from homeassistant.components.ruckus_unleashed import API_MAC, DOMAIN from homeassistant.components.ruckus_unleashed import API_MAC, DOMAIN
from homeassistant.components.ruckus_unleashed.const import API_AP, API_ID, API_NAME from homeassistant.components.ruckus_unleashed.const import API_AP, API_ID, API_NAME
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNAVAILABLE from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNAVAILABLE
from homeassistant.helpers import entity_registry from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.util import utcnow from homeassistant.util import utcnow
@ -80,7 +80,7 @@ async def test_restoring_clients(hass):
entry = mock_config_entry() entry = mock_config_entry()
entry.add_to_hass(hass) entry.add_to_hass(hass)
registry = await entity_registry.async_get_registry(hass) registry = er.async_get(hass)
registry.async_get_or_create( registry.async_get_or_create(
"device_tracker", "device_tracker",
DOMAIN, DOMAIN,
@ -120,7 +120,7 @@ async def test_client_device_setup(hass):
router_info = DEFAULT_AP_INFO[API_AP][API_ID]["1"] router_info = DEFAULT_AP_INFO[API_AP][API_ID]["1"]
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
client_device = device_registry.async_get_device( client_device = device_registry.async_get_device(
identifiers={}, identifiers={},
connections={(CONNECTION_NETWORK_MAC, TEST_CLIENT[API_MAC])}, connections={(CONNECTION_NETWORK_MAC, TEST_CLIENT[API_MAC])},

View file

@ -19,6 +19,7 @@ from homeassistant.config_entries import (
ENTRY_STATE_NOT_LOADED, ENTRY_STATE_NOT_LOADED,
ENTRY_STATE_SETUP_RETRY, ENTRY_STATE_SETUP_RETRY,
) )
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from tests.components.ruckus_unleashed import ( from tests.components.ruckus_unleashed import (
@ -64,7 +65,7 @@ async def test_router_device_setup(hass):
device_info = DEFAULT_AP_INFO[API_AP][API_ID]["1"] device_info = DEFAULT_AP_INFO[API_AP][API_ID]["1"]
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
device = device_registry.async_get_device( device = device_registry.async_get_device(
identifiers={(CONNECTION_NETWORK_MAC, device_info[API_MAC])}, identifiers={(CONNECTION_NETWORK_MAC, device_info[API_MAC])},
connections={(CONNECTION_NETWORK_MAC, device_info[API_MAC])}, connections={(CONNECTION_NETWORK_MAC, device_info[API_MAC])},

View file

@ -1,5 +1,10 @@
"""Tests for Search integration.""" """Tests for Search integration."""
from homeassistant.components import search from homeassistant.components import search
from homeassistant.helpers import (
area_registry as ar,
device_registry as dr,
entity_registry as er,
)
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -8,9 +13,9 @@ from tests.components.blueprint.conftest import stub_blueprint_populate # noqa:
async def test_search(hass): async def test_search(hass):
"""Test that search works.""" """Test that search works."""
area_reg = await hass.helpers.area_registry.async_get_registry() area_reg = ar.async_get(hass)
device_reg = await hass.helpers.device_registry.async_get_registry() device_reg = dr.async_get(hass)
entity_reg = await hass.helpers.entity_registry.async_get_registry() entity_reg = er.async_get(hass)
living_room_area = area_reg.async_create("Living Room") living_room_area = area_reg.async_create("Living Room")
@ -275,8 +280,8 @@ async def test_ws_api(hass, hass_ws_client):
"""Test WS API.""" """Test WS API."""
assert await async_setup_component(hass, "search", {}) assert await async_setup_component(hass, "search", {})
area_reg = await hass.helpers.area_registry.async_get_registry() area_reg = ar.async_get(hass)
device_reg = await hass.helpers.device_registry.async_get_registry() device_reg = dr.async_get(hass)
kitchen_area = area_reg.async_create("Kitchen") kitchen_area = area_reg.async_create("Kitchen")

View file

@ -46,6 +46,7 @@ from homeassistant.const import (
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .const import ( from .const import (
@ -128,7 +129,7 @@ async def setup_integration(hass):
async def test_simple_properties(hass: HomeAssistant): async def test_simple_properties(hass: HomeAssistant):
"""Test that simple properties work as intended.""" """Test that simple properties work as intended."""
state = hass.states.get(VAC_ENTITY_ID) state = hass.states.get(VAC_ENTITY_ID)
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
entity = registry.async_get(VAC_ENTITY_ID) entity = registry.async_get(VAC_ENTITY_ID)
assert entity assert entity
@ -199,7 +200,7 @@ async def test_device_properties(
hass: HomeAssistant, device_property: str, target_value: str hass: HomeAssistant, device_property: str, target_value: str
): ):
"""Test device properties.""" """Test device properties."""
registry = await hass.helpers.device_registry.async_get_registry() registry = dr.async_get(hass)
device = registry.async_get_device({(DOMAIN, "AC000Wxxxxxxxxx")}) device = registry.async_get_device({(DOMAIN, "AC000Wxxxxxxxxx")})
assert getattr(device, device_property) == target_value assert getattr(device, device_property) == target_value

View file

@ -13,6 +13,7 @@ from homeassistant.components.binary_sensor import (
from homeassistant.components.smartthings import binary_sensor from homeassistant.components.smartthings import binary_sensor
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_UNAVAILABLE from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
@ -49,8 +50,8 @@ async def test_entity_and_device_attributes(hass, device_factory):
device = device_factory( device = device_factory(
"Motion Sensor 1", [Capability.motion_sensor], {Attribute.motion: "inactive"} "Motion Sensor 1", [Capability.motion_sensor], {Attribute.motion: "inactive"}
) )
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
# Act # Act
await setup_platform(hass, BINARY_SENSOR_DOMAIN, devices=[device]) await setup_platform(hass, BINARY_SENSOR_DOMAIN, devices=[device])
# Assert # Assert

View file

@ -44,6 +44,7 @@ from homeassistant.const import (
SERVICE_TURN_ON, SERVICE_TURN_ON,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.helpers import device_registry as dr, entity_registry as er
from .conftest import setup_platform from .conftest import setup_platform
@ -569,8 +570,8 @@ async def test_set_turn_on(hass, air_conditioner):
async def test_entity_and_device_attributes(hass, thermostat): async def test_entity_and_device_attributes(hass, thermostat):
"""Test the attributes of the entries are correct.""" """Test the attributes of the entries are correct."""
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat]) await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
entry = entity_registry.async_get("climate.thermostat") entry = entity_registry.async_get("climate.thermostat")
assert entry assert entry

View file

@ -20,6 +20,7 @@ from homeassistant.components.cover import (
) )
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_ENTITY_ID, STATE_UNAVAILABLE from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_ENTITY_ID, STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
@ -31,8 +32,8 @@ async def test_entity_and_device_attributes(hass, device_factory):
device = device_factory( device = device_factory(
"Garage", [Capability.garage_door_control], {Attribute.door: "open"} "Garage", [Capability.garage_door_control], {Attribute.door: "open"}
) )
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
# Act # Act
await setup_platform(hass, COVER_DOMAIN, devices=[device]) await setup_platform(hass, COVER_DOMAIN, devices=[device])
# Assert # Assert

View file

@ -22,6 +22,7 @@ from homeassistant.const import (
ATTR_SUPPORTED_FEATURES, ATTR_SUPPORTED_FEATURES,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
@ -59,8 +60,8 @@ async def test_entity_and_device_attributes(hass, device_factory):
) )
# Act # Act
await setup_platform(hass, FAN_DOMAIN, devices=[device]) await setup_platform(hass, FAN_DOMAIN, devices=[device])
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
# Assert # Assert
entry = entity_registry.async_get("fan.fan_1") entry = entity_registry.async_get("fan.fan_1")
assert entry assert entry

View file

@ -24,6 +24,7 @@ from homeassistant.const import (
ATTR_SUPPORTED_FEATURES, ATTR_SUPPORTED_FEATURES,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
@ -110,8 +111,8 @@ async def test_entity_and_device_attributes(hass, device_factory):
"""Test the attributes of the entity are correct.""" """Test the attributes of the entity are correct."""
# Arrange # Arrange
device = device_factory("Light 1", [Capability.switch, Capability.switch_level]) device = device_factory("Light 1", [Capability.switch, Capability.switch_level])
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
# Act # Act
await setup_platform(hass, LIGHT_DOMAIN, devices=[device]) await setup_platform(hass, LIGHT_DOMAIN, devices=[device])
# Assert # Assert

View file

@ -10,6 +10,7 @@ from pysmartthings.device import Status
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.const import STATE_UNAVAILABLE from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
@ -19,8 +20,8 @@ async def test_entity_and_device_attributes(hass, device_factory):
"""Test the attributes of the entity are correct.""" """Test the attributes of the entity are correct."""
# Arrange # Arrange
device = device_factory("Lock_1", [Capability.lock], {Attribute.lock: "unlocked"}) device = device_factory("Lock_1", [Capability.lock], {Attribute.lock: "unlocked"})
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
# Act # Act
await setup_platform(hass, LOCK_DOMAIN, devices=[device]) await setup_platform(hass, LOCK_DOMAIN, devices=[device])
# Assert # Assert

View file

@ -6,6 +6,7 @@ real HTTP calls are not initiated during testing.
""" """
from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNAVAILABLE from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNAVAILABLE
from homeassistant.helpers import entity_registry as er
from .conftest import setup_platform from .conftest import setup_platform
@ -13,7 +14,7 @@ from .conftest import setup_platform
async def test_entity_and_device_attributes(hass, scene): async def test_entity_and_device_attributes(hass, scene):
"""Test the attributes of the entity are correct.""" """Test the attributes of the entity are correct."""
# Arrange # Arrange
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
# Act # Act
await setup_platform(hass, SCENE_DOMAIN, scenes=[scene]) await setup_platform(hass, SCENE_DOMAIN, scenes=[scene])
# Assert # Assert

View file

@ -16,6 +16,7 @@ from homeassistant.const import (
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
@ -78,8 +79,8 @@ async def test_entity_and_device_attributes(hass, device_factory):
"""Test the attributes of the entity are correct.""" """Test the attributes of the entity are correct."""
# Arrange # Arrange
device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100}) device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100})
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
# Act # Act
await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) await setup_platform(hass, SENSOR_DOMAIN, devices=[device])
# Assert # Assert

View file

@ -13,6 +13,7 @@ from homeassistant.components.switch import (
DOMAIN as SWITCH_DOMAIN, DOMAIN as SWITCH_DOMAIN,
) )
from homeassistant.const import STATE_UNAVAILABLE from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
@ -22,8 +23,8 @@ async def test_entity_and_device_attributes(hass, device_factory):
"""Test the attributes of the entity are correct.""" """Test the attributes of the entity are correct."""
# Arrange # Arrange
device = device_factory("Switch_1", [Capability.switch], {Attribute.switch: "on"}) device = device_factory("Switch_1", [Capability.switch], {Attribute.switch: "on"})
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
# Act # Act
await setup_platform(hass, SWITCH_DOMAIN, devices=[device]) await setup_platform(hass, SWITCH_DOMAIN, devices=[device])
# Assert # Assert

View file

@ -12,6 +12,7 @@ from homeassistant.const import (
DATA_GIGABYTES, DATA_GIGABYTES,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
@ -27,7 +28,7 @@ async def test_sensors(
) -> None: ) -> None:
"""Test the creation and values of the sensors.""" """Test the creation and values of the sensors."""
entry = await setup_integration(hass, aioclient_mock, skip_entry_setup=True) entry = await setup_integration(hass, aioclient_mock, skip_entry_setup=True)
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
# Pre-create registry entries for disabled by default sensors # Pre-create registry entries for disabled by default sensors
sensors = { sensors = {
@ -107,7 +108,7 @@ async def test_disabled_by_default_sensors(
) -> None: ) -> None:
"""Test the disabled by default sensors.""" """Test the disabled by default sensors."""
await setup_integration(hass, aioclient_mock) await setup_integration(hass, aioclient_mock)
registry = await hass.helpers.entity_registry.async_get_registry() registry = er.async_get(hass)
print(registry.entities) print(registry.entities)
state = hass.states.get(entity_id) state = hass.states.get(entity_id)

View file

@ -113,7 +113,7 @@ async def test_state(hass):
assert attributes["source"] == "title2" assert attributes["source"] == "title2"
assert attributes["supported_features"] == SUPPORT_SONGPAL assert attributes["supported_features"] == SUPPORT_SONGPAL
device_registry = await dr.async_get_registry(hass) device_registry = dr.async_get(hass)
device = device_registry.async_get_device(identifiers={(songpal.DOMAIN, MAC)}) device = device_registry.async_get_device(identifiers={(songpal.DOMAIN, MAC)})
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, MAC)} assert device.connections == {(dr.CONNECTION_NETWORK_MAC, MAC)}
assert device.manufacturer == "Sony Corporation" assert device.manufacturer == "Sony Corporation"
@ -121,7 +121,7 @@ async def test_state(hass):
assert device.sw_version == SW_VERSION assert device.sw_version == SW_VERSION
assert device.model == MODEL assert device.model == MODEL
entity_registry = await er.async_get_registry(hass) entity_registry = er.async_get(hass)
entity = entity_registry.async_get(ENTITY_ID) entity = entity_registry.async_get(ENTITY_ID)
assert entity.unique_id == MAC assert entity.unique_id == MAC

View file

@ -4,6 +4,7 @@ import pytest
from homeassistant.components.sonos import DOMAIN, media_player from homeassistant.components.sonos import DOMAIN, media_player
from homeassistant.core import Context from homeassistant.core import Context
from homeassistant.exceptions import Unauthorized from homeassistant.exceptions import Unauthorized
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -48,7 +49,7 @@ async def test_device_registry(hass, config_entry, config, soco):
"""Test sonos device registered in the device registry.""" """Test sonos device registered in the device registry."""
await setup_platform(hass, config_entry, config) await setup_platform(hass, config_entry, config)
device_registry = await hass.helpers.device_registry.async_get_registry() device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device( reg_device = device_registry.async_get_device(
identifiers={("sonos", "RINCON_test")} identifiers={("sonos", "RINCON_test")}
) )

View file

@ -2,6 +2,7 @@
from surepy import MESTART_RESOURCE from surepy import MESTART_RESOURCE
from homeassistant.components.surepetcare.const import DOMAIN from homeassistant.components.surepetcare.const import DOMAIN
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import MOCK_API_DATA, MOCK_CONFIG, _patch_sensor_setup from . import MOCK_API_DATA, MOCK_CONFIG, _patch_sensor_setup
@ -24,7 +25,7 @@ async def test_binary_sensors(hass, surepetcare) -> None:
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG) assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done() await hass.async_block_till_done()
entity_registry = await hass.helpers.entity_registry.async_get_registry() entity_registry = er.async_get(hass)
state_entity_ids = hass.states.async_entity_ids() state_entity_ids = hass.states.async_entity_ids()
for entity_id, unique_id in EXPECTED_ENTITY_IDS.items(): for entity_id, unique_id in EXPECTED_ENTITY_IDS.items():