From 87e7cebd36ce6be6d79d3ff35b60d1ebf33edcd1 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 9 Mar 2021 14:31:17 +0100 Subject: [PATCH] Update tests c-h to use registry async_get (#47652) --- tests/components/cast/test_media_player.py | 21 ++++++++++--------- tests/components/config/test_automation.py | 3 ++- tests/components/config/test_scene.py | 3 ++- tests/components/coronavirus/test_init.py | 8 +++---- tests/components/counter/test_init.py | 8 +++---- tests/components/deconz/test_binary_sensor.py | 4 ++-- tests/components/deconz/test_init.py | 6 +++--- tests/components/deconz/test_services.py | 6 +++--- tests/components/directv/test_media_player.py | 3 ++- tests/components/directv/test_remote.py | 3 ++- tests/components/dsmr/test_sensor.py | 5 +++-- tests/components/dynalite/common.py | 4 ++-- tests/components/dyson/test_climate.py | 6 +++--- tests/components/dyson/test_fan.py | 10 ++++----- tests/components/dyson/test_sensor.py | 6 +++--- tests/components/dyson/test_vacuum.py | 6 +++--- tests/components/elgato/test_light.py | 3 ++- tests/components/gdacs/test_geo_location.py | 4 ++-- .../generic_thermostat/test_climate.py | 3 ++- tests/components/geofency/test_init.py | 5 +++-- .../geonetnz_quakes/test_geo_location.py | 4 ++-- tests/components/gios/test_air_quality.py | 5 +++-- tests/components/gpslogger/test_init.py | 5 +++-- tests/components/harmony/test_init.py | 12 +++++------ tests/components/heos/test_media_player.py | 5 +++-- tests/components/homekit/test_type_covers.py | 6 +++--- tests/components/homekit/test_type_fans.py | 4 ++-- tests/components/homekit/test_type_lights.py | 4 ++-- .../homekit/test_type_media_players.py | 4 ++-- tests/components/homekit/test_type_sensors.py | 4 ++-- .../homekit/test_type_thermostats.py | 6 +++--- .../specific_devices/test_anker_eufycam.py | 5 +++-- .../specific_devices/test_aqara_gateway.py | 5 +++-- .../specific_devices/test_aqara_switch.py | 4 +++- .../specific_devices/test_ecobee3.py | 11 +++++----- .../specific_devices/test_ecobee_occupancy.py | 6 ++++-- .../test_homeassistant_bridge.py | 5 +++-- .../specific_devices/test_hue_bridge.py | 6 ++++-- .../specific_devices/test_koogeek_ls1.py | 5 +++-- .../specific_devices/test_koogeek_p1eu.py | 6 ++++-- .../specific_devices/test_lennox_e30.py | 5 +++-- .../specific_devices/test_lg_tv.py | 5 +++-- .../test_rainmachine_pro_8.py | 6 ++++-- .../test_simpleconnect_fan.py | 5 +++-- .../specific_devices/test_velux_gateway.py | 5 +++-- .../homekit_controller/test_device_trigger.py | 17 ++++++++------- .../homematicip_cloud/test_device.py | 16 +++++++------- tests/components/hue/test_light.py | 11 +++------- tests/components/hyperion/test_light.py | 4 ++-- 49 files changed, 165 insertions(+), 138 deletions(-) diff --git a/tests/components/cast/test_media_player.py b/tests/components/cast/test_media_player.py index 27f817b6771..a3d5676a878 100644 --- a/tests/components/cast/test_media_player.py +++ b/tests/components/cast/test_media_player.py @@ -28,6 +28,7 @@ from homeassistant.components.media_player.const import ( from homeassistant.config import async_process_ha_core_config from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.exceptions import PlatformNotReady +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.typing import HomeAssistantType from homeassistant.setup import async_setup_component @@ -489,7 +490,7 @@ async def test_discover_dynamic_group(hass, dial_mock, pycast_mock, caplog): zconf_1 = get_fake_zconf(host="host_1", port=23456) zconf_2 = get_fake_zconf(host="host_2", port=34567) - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) # Fake dynamic group info tmp1 = MagicMock() @@ -613,7 +614,7 @@ async def test_entity_availability(hass: HomeAssistantType): async def test_entity_cast_status(hass: HomeAssistantType): """Test handling of cast status.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -682,7 +683,7 @@ async def test_entity_cast_status(hass: HomeAssistantType): async def test_entity_play_media(hass: HomeAssistantType): """Test playing media.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -711,7 +712,7 @@ async def test_entity_play_media(hass: HomeAssistantType): async def test_entity_play_media_cast(hass: HomeAssistantType, quick_play_mock): """Test playing media with cast special features.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -744,7 +745,7 @@ async def test_entity_play_media_cast(hass: HomeAssistantType, quick_play_mock): async def test_entity_play_media_cast_invalid(hass, caplog, quick_play_mock): """Test playing media.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -817,7 +818,7 @@ async def test_entity_play_media_sign_URL(hass: HomeAssistantType): async def test_entity_media_content_type(hass: HomeAssistantType): """Test various content types.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -871,7 +872,7 @@ async def test_entity_media_content_type(hass: HomeAssistantType): async def test_entity_control(hass: HomeAssistantType): """Test various device and media controls.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -980,7 +981,7 @@ async def test_entity_control(hass: HomeAssistantType): async def test_entity_media_states(hass: HomeAssistantType): """Test various entity media states.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -1039,7 +1040,7 @@ async def test_entity_media_states(hass: HomeAssistantType): async def test_group_media_states(hass, mz_mock): """Test media states are read from group if entity has no state.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( @@ -1092,7 +1093,7 @@ async def test_group_media_states(hass, mz_mock): async def test_group_media_control(hass, mz_mock): """Test media controls are handled by group if entity has no state.""" entity_id = "media_player.speaker" - reg = await hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(hass) info = get_fake_chromecast_info() full_info = attr.evolve( diff --git a/tests/components/config/test_automation.py b/tests/components/config/test_automation.py index aaf97e22ccd..d52295c75f7 100644 --- a/tests/components/config/test_automation.py +++ b/tests/components/config/test_automation.py @@ -4,6 +4,7 @@ from unittest.mock import patch from homeassistant.bootstrap import async_setup_component from homeassistant.components import automation, config +from homeassistant.helpers import entity_registry as er from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 @@ -110,7 +111,7 @@ async def test_bad_formatted_automations(hass, hass_client): async def test_delete_automation(hass, hass_client): """Test deleting an automation.""" - ent_reg = await hass.helpers.entity_registry.async_get_registry() + ent_reg = er.async_get(hass) assert await async_setup_component( hass, diff --git a/tests/components/config/test_scene.py b/tests/components/config/test_scene.py index bdb2a2e3f10..8e4276cc9fd 100644 --- a/tests/components/config/test_scene.py +++ b/tests/components/config/test_scene.py @@ -4,6 +4,7 @@ from unittest.mock import patch from homeassistant.bootstrap import async_setup_component from homeassistant.components import config +from homeassistant.helpers import entity_registry as er from homeassistant.util.yaml import dump @@ -114,7 +115,7 @@ async def test_bad_formatted_scene(hass, hass_client): async def test_delete_scene(hass, hass_client): """Test deleting a scene.""" - ent_reg = await hass.helpers.entity_registry.async_get_registry() + ent_reg = er.async_get(hass) assert await async_setup_component( hass, diff --git a/tests/components/coronavirus/test_init.py b/tests/components/coronavirus/test_init.py index 483fabab9f9..cc49bf7d4b6 100644 --- a/tests/components/coronavirus/test_init.py +++ b/tests/components/coronavirus/test_init.py @@ -1,6 +1,6 @@ """Test init of Coronavirus integration.""" from homeassistant.components.coronavirus.const import DOMAIN, OPTION_WORLDWIDE -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, mock_registry @@ -17,13 +17,13 @@ async def test_migration(hass): mock_registry( hass, { - "sensor.netherlands_confirmed": entity_registry.RegistryEntry( + "sensor.netherlands_confirmed": er.RegistryEntry( entity_id="sensor.netherlands_confirmed", unique_id="34-confirmed", platform="coronavirus", config_entry_id=nl_entry.entry_id, ), - "sensor.worldwide_confirmed": entity_registry.RegistryEntry( + "sensor.worldwide_confirmed": er.RegistryEntry( entity_id="sensor.worldwide_confirmed", unique_id="__worldwide-confirmed", platform="coronavirus", @@ -34,7 +34,7 @@ async def test_migration(hass): assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - ent_reg = await entity_registry.async_get_registry(hass) + ent_reg = er.async_get(hass) sensor_nl = ent_reg.async_get("sensor.netherlands_confirmed") assert sensor_nl.unique_id == "Netherlands-confirmed" diff --git a/tests/components/counter/test_init.py b/tests/components/counter/test_init.py index d6a41af6deb..7e5859497c5 100644 --- a/tests/components/counter/test_init.py +++ b/tests/components/counter/test_init.py @@ -21,7 +21,7 @@ from homeassistant.components.counter import ( ) from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_ICON, ATTR_NAME from homeassistant.core import Context, CoreState, State -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from tests.common import mock_restore_cache @@ -569,7 +569,7 @@ async def test_ws_delete(hass, hass_ws_client, storage_setup): input_id = "from_storage" input_entity_id = f"{DOMAIN}.{input_id}" - ent_reg = await entity_registry.async_get_registry(hass) + ent_reg = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is not None @@ -606,7 +606,7 @@ async def test_update_min_max(hass, hass_ws_client, storage_setup): input_id = "from_storage" input_entity_id = f"{DOMAIN}.{input_id}" - ent_reg = await entity_registry.async_get_registry(hass) + ent_reg = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is not None @@ -683,7 +683,7 @@ async def test_create(hass, hass_ws_client, storage_setup): counter_id = "new_counter" input_entity_id = f"{DOMAIN}.{counter_id}" - ent_reg = await entity_registry.async_get_registry(hass) + ent_reg = er.async_get(hass) state = hass.states.get(input_entity_id) assert state is None diff --git a/tests/components/deconz/test_binary_sensor.py b/tests/components/deconz/test_binary_sensor.py index 70d3db4149b..39809ecc231 100644 --- a/tests/components/deconz/test_binary_sensor.py +++ b/tests/components/deconz/test_binary_sensor.py @@ -1,5 +1,4 @@ """deCONZ binary sensor platform tests.""" - from copy import deepcopy from homeassistant.components.binary_sensor import ( @@ -15,6 +14,7 @@ from homeassistant.components.deconz.const import ( from homeassistant.components.deconz.gateway import get_gateway_from_config_entry from homeassistant.components.deconz.services import SERVICE_DEVICE_REFRESH from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_registry import async_entries_for_config_entry from .test_gateway import ( @@ -191,7 +191,7 @@ async def test_add_new_binary_sensor_ignored(hass, aioclient_mock): assert len(hass.states.async_all()) == 0 assert not hass.states.get("binary_sensor.presence_sensor") - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) assert ( len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0 ) diff --git a/tests/components/deconz/test_init.py b/tests/components/deconz/test_init.py index ed7655bf620..46b563ca007 100644 --- a/tests/components/deconz/test_init.py +++ b/tests/components/deconz/test_init.py @@ -16,7 +16,7 @@ from homeassistant.components.deconz.const import ( ) from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration @@ -133,7 +133,7 @@ async def test_update_group_unique_id(hass): }, ) - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) # Create entity entry to migrate to new unique ID registry.async_get_or_create( LIGHT_DOMAIN, @@ -172,7 +172,7 @@ async def test_update_group_unique_id_no_legacy_group_id(hass): data={}, ) - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) # Create entity entry to migrate to new unique ID registry.async_get_or_create( LIGHT_DOMAIN, diff --git a/tests/components/deconz/test_services.py b/tests/components/deconz/test_services.py index 41eefa95785..35279572113 100644 --- a/tests/components/deconz/test_services.py +++ b/tests/components/deconz/test_services.py @@ -1,5 +1,4 @@ """deCONZ service tests.""" - from copy import deepcopy from unittest.mock import Mock, patch @@ -23,6 +22,7 @@ from homeassistant.components.deconz.services import ( async_unload_services, ) from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.entity_registry import async_entries_for_config_entry from .test_gateway import ( @@ -245,7 +245,7 @@ async def test_remove_orphaned_entries_service(hass, aioclient_mock): data = {CONF_BRIDGE_ID: BRIDGEID} - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={("mac", "123")} ) @@ -261,7 +261,7 @@ async def test_remove_orphaned_entries_service(hass, aioclient_mock): == 5 # Host, gateway, light, switch and orphan ) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entity_registry.async_get_or_create( SENSOR_DOMAIN, DECONZ_DOMAIN, diff --git a/tests/components/directv/test_media_player.py b/tests/components/directv/test_media_player.py index 506cf62a44d..aeaa245161d 100644 --- a/tests/components/directv/test_media_player.py +++ b/tests/components/directv/test_media_player.py @@ -53,6 +53,7 @@ from homeassistant.const import ( STATE_PLAYING, STATE_UNAVAILABLE, ) +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util import dt as dt_util @@ -167,7 +168,7 @@ async def test_unique_id( """Test unique id.""" 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) assert main.device_class == DEVICE_CLASS_RECEIVER diff --git a/tests/components/directv/test_remote.py b/tests/components/directv/test_remote.py index 33521958747..92bcd6af014 100644 --- a/tests/components/directv/test_remote.py +++ b/tests/components/directv/test_remote.py @@ -7,6 +7,7 @@ from homeassistant.components.remote import ( SERVICE_SEND_COMMAND, ) 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 tests.components.directv import setup_integration @@ -36,7 +37,7 @@ async def test_unique_id( """Test unique id.""" 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) assert main.unique_id == "028877455858" diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index 31c4f2be8db..9aaa558e92e 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -19,6 +19,7 @@ from homeassistant.const import ( VOLUME_CUBIC_METERS, VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR, ) +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, patch @@ -107,7 +108,7 @@ async def test_default_setup(hass, dsmr_connection_fixture): await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) entry = registry.async_get("sensor.power_consumption") assert entry @@ -167,7 +168,7 @@ async def test_setup_only_energy(hass, dsmr_connection_fixture): await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) entry = registry.async_get("sensor.power_consumption") assert entry diff --git a/tests/components/dynalite/common.py b/tests/components/dynalite/common.py index 072e222c194..446cdc74c0b 100644 --- a/tests/components/dynalite/common.py +++ b/tests/components/dynalite/common.py @@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, Mock, call, patch from homeassistant.components import dynalite from homeassistant.const import ATTR_SERVICE -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from tests.common import MockConfigEntry @@ -23,7 +23,7 @@ def create_mock_device(platform, spec): async def get_entry_id_from_hass(hass): """Get the config entry id from hass.""" - ent_reg = await entity_registry.async_get_registry(hass) + ent_reg = er.async_get(hass) assert ent_reg conf_entries = hass.config_entries.async_entries(dynalite.DOMAIN) assert len(conf_entries) == 1 diff --git a/tests/components/dyson/test_climate.py b/tests/components/dyson/test_climate.py index 0e389000c29..90d91092dca 100644 --- a/tests/components/dyson/test_climate.py +++ b/tests/components/dyson/test_climate.py @@ -60,7 +60,7 @@ from homeassistant.const import ( ATTR_TEMPERATURE, ) from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from .common import ( ENTITY_NAME, @@ -99,8 +99,8 @@ def async_get_device(spec: Type[DysonDevice]) -> DysonDevice: ) async def test_state_common(hass: HomeAssistant, device: DysonDevice) -> None: """Test common state and attributes of two types of climate entities.""" - er = await entity_registry.async_get_registry(hass) - assert er.async_get(ENTITY_ID).unique_id == SERIAL + entity_registry = er.async_get(hass) + assert entity_registry.async_get(ENTITY_ID).unique_id == SERIAL state = hass.states.get(ENTITY_ID) assert state.name == NAME diff --git a/tests/components/dyson/test_fan.py b/tests/components/dyson/test_fan.py index dacde12c569..eb83f319c1f 100644 --- a/tests/components/dyson/test_fan.py +++ b/tests/components/dyson/test_fan.py @@ -52,7 +52,7 @@ from homeassistant.const import ( STATE_ON, ) from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from .common import ( ENTITY_NAME, @@ -79,8 +79,8 @@ async def test_state_purecoollink( hass: HomeAssistant, device: DysonPureCoolLink ) -> None: """Test the state of a PureCoolLink fan.""" - er = await entity_registry.async_get_registry(hass) - assert er.async_get(ENTITY_ID).unique_id == SERIAL + entity_registry = er.async_get(hass) + assert entity_registry.async_get(ENTITY_ID).unique_id == SERIAL state = hass.states.get(ENTITY_ID) assert state.state == STATE_ON @@ -128,8 +128,8 @@ async def test_state_purecoollink( @pytest.mark.parametrize("device", [DysonPureCool], indirect=True) async def test_state_purecool(hass: HomeAssistant, device: DysonPureCool) -> None: """Test the state of a PureCool fan.""" - er = await entity_registry.async_get_registry(hass) - assert er.async_get(ENTITY_ID).unique_id == SERIAL + entity_registry = er.async_get(hass) + assert entity_registry.async_get(ENTITY_ID).unique_id == SERIAL state = hass.states.get(ENTITY_ID) assert state.state == STATE_ON diff --git a/tests/components/dyson/test_sensor.py b/tests/components/dyson/test_sensor.py index 4541ef2190a..a27aeeb99e1 100644 --- a/tests/components/dyson/test_sensor.py +++ b/tests/components/dyson/test_sensor.py @@ -16,7 +16,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem from .common import ( @@ -120,12 +120,12 @@ async def test_sensors( # Make sure no other sensors are set up assert len(hass.states.async_all()) == len(sensors) - er = await entity_registry.async_get_registry(hass) + entity_registry = er.async_get(hass) for sensor in sensors: entity_id = _async_get_entity_id(sensor) # Test unique id - assert er.async_get(entity_id).unique_id == f"{SERIAL}-{sensor}" + assert entity_registry.async_get(entity_id).unique_id == f"{SERIAL}-{sensor}" # Test state state = hass.states.get(entity_id) diff --git a/tests/components/dyson/test_vacuum.py b/tests/components/dyson/test_vacuum.py index 03a3b076b02..b77dee3270f 100644 --- a/tests/components/dyson/test_vacuum.py +++ b/tests/components/dyson/test_vacuum.py @@ -24,7 +24,7 @@ from homeassistant.const import ( STATE_ON, ) from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from .common import ( ENTITY_NAME, @@ -45,8 +45,8 @@ def async_get_device(state=Dyson360EyeMode.FULL_CLEAN_RUNNING) -> Dyson360Eye: async def test_state(hass: HomeAssistant, device: Dyson360Eye) -> None: """Test the state of the vacuum.""" - er = await entity_registry.async_get_registry(hass) - assert er.async_get(ENTITY_ID).unique_id == SERIAL + entity_registry = er.async_get(hass) + assert entity_registry.async_get(ENTITY_ID).unique_id == SERIAL state = hass.states.get(ENTITY_ID) assert state.name == NAME diff --git a/tests/components/elgato/test_light.py b/tests/components/elgato/test_light.py index aed569c18fe..48e6bd24625 100644 --- a/tests/components/elgato/test_light.py +++ b/tests/components/elgato/test_light.py @@ -16,6 +16,7 @@ from homeassistant.const import ( STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from tests.common import mock_coro from tests.components.elgato import init_integration @@ -28,7 +29,7 @@ async def test_light_state( """Test the creation and values of the Elgato Key Lights.""" await init_integration(hass, aioclient_mock) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # First segment of the strip state = hass.states.get("light.frenck") diff --git a/tests/components/gdacs/test_geo_location.py b/tests/components/gdacs/test_geo_location.py index 7dc23eaa5d8..d93db73aa79 100644 --- a/tests/components/gdacs/test_geo_location.py +++ b/tests/components/gdacs/test_geo_location.py @@ -29,7 +29,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, LENGTH_KILOMETERS, ) -from homeassistant.helpers.entity_registry import async_get_registry +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from homeassistant.util.unit_system import IMPERIAL_SYSTEM @@ -99,7 +99,7 @@ async def test_setup(hass, legacy_patchable_time): all_states = hass.states.async_all() # 3 geolocation and 1 sensor entities assert len(all_states) == 4 - entity_registry = await async_get_registry(hass) + entity_registry = er.async_get(hass) assert len(entity_registry.entities) == 4 state = hass.states.get("geo_location.drought_name_1") diff --git a/tests/components/generic_thermostat/test_climate.py b/tests/components/generic_thermostat/test_climate.py index e6cdf962d24..b83828c86c7 100644 --- a/tests/components/generic_thermostat/test_climate.py +++ b/tests/components/generic_thermostat/test_climate.py @@ -35,6 +35,7 @@ from homeassistant.const import ( ) import homeassistant.core as ha from homeassistant.core import DOMAIN as HASS_DOMAIN, CoreState, State, callback +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util.unit_system import METRIC_SYSTEM @@ -179,7 +180,7 @@ async def test_unique_id(hass, setup_comp_1): ) await hass.async_block_till_done() - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get(ENTITY) assert entry diff --git a/tests/components/geofency/test_init.py b/tests/components/geofency/test_init.py index b87b201a144..92a2f5b19f2 100644 --- a/tests/components/geofency/test_init.py +++ b/tests/components/geofency/test_init.py @@ -16,6 +16,7 @@ from homeassistant.const import ( STATE_HOME, STATE_NOT_HOME, ) +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util import slugify @@ -223,10 +224,10 @@ async def test_gps_enter_and_exit_home(hass, geofency_client, webhook_id): ] assert NOT_HOME_LONGITUDE == current_longitude - dev_reg = await hass.helpers.device_registry.async_get_registry() + dev_reg = dr.async_get(hass) assert len(dev_reg.devices) == 1 - ent_reg = await hass.helpers.entity_registry.async_get_registry() + ent_reg = er.async_get(hass) assert len(ent_reg.entities) == 1 diff --git a/tests/components/geonetnz_quakes/test_geo_location.py b/tests/components/geonetnz_quakes/test_geo_location.py index b0e54e89929..9c700c2b38e 100644 --- a/tests/components/geonetnz_quakes/test_geo_location.py +++ b/tests/components/geonetnz_quakes/test_geo_location.py @@ -25,7 +25,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, LENGTH_KILOMETERS, ) -from homeassistant.helpers.entity_registry import async_get_registry +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from homeassistant.util.unit_system import IMPERIAL_SYSTEM @@ -75,7 +75,7 @@ async def test_setup(hass): all_states = hass.states.async_all() # 3 geolocation and 1 sensor entities assert len(all_states) == 4 - entity_registry = await async_get_registry(hass) + entity_registry = er.async_get(hass) assert len(entity_registry.entities) == 4 state = hass.states.get("geo_location.title_1") diff --git a/tests/components/gios/test_air_quality.py b/tests/components/gios/test_air_quality.py index 21a1abf637a..873e1e089a3 100644 --- a/tests/components/gios/test_air_quality.py +++ b/tests/components/gios/test_air_quality.py @@ -23,6 +23,7 @@ from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, STATE_UNAVAILABLE, ) +from homeassistant.helpers import entity_registry as er from homeassistant.util.dt import utcnow from tests.common import async_fire_time_changed, load_fixture @@ -32,7 +33,7 @@ from tests.components.gios import init_integration async def test_air_quality(hass): """Test states of the air_quality.""" await init_integration(hass) - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) state = hass.states.get("air_quality.home") assert state @@ -60,7 +61,7 @@ async def test_air_quality(hass): async def test_air_quality_with_incomplete_data(hass): """Test states of the air_quality with incomplete data from measuring station.""" await init_integration(hass, incomplete_data=True) - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) state = hass.states.get("air_quality.home") assert state diff --git a/tests/components/gpslogger/test_init.py b/tests/components/gpslogger/test_init.py index d30f57f0f33..8a4880c4878 100644 --- a/tests/components/gpslogger/test_init.py +++ b/tests/components/gpslogger/test_init.py @@ -14,6 +14,7 @@ from homeassistant.const import ( STATE_HOME, STATE_NOT_HOME, ) +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.dispatcher import DATA_DISPATCHER from homeassistant.setup import async_setup_component @@ -135,10 +136,10 @@ async def test_enter_and_exit(hass, gpslogger_client, webhook_id): state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state assert STATE_NOT_HOME == state_name - dev_reg = await hass.helpers.device_registry.async_get_registry() + dev_reg = dr.async_get(hass) assert len(dev_reg.devices) == 1 - ent_reg = await hass.helpers.entity_registry.async_get_registry() + ent_reg = er.async_get(hass) assert len(ent_reg.entities) == 1 diff --git a/tests/components/harmony/test_init.py b/tests/components/harmony/test_init.py index c63727f8738..29a1ff26b82 100644 --- a/tests/components/harmony/test_init.py +++ b/tests/components/harmony/test_init.py @@ -1,7 +1,7 @@ """Test init of Logitch Harmony Hub integration.""" from homeassistant.components.harmony.const import DOMAIN from homeassistant.const import CONF_HOST, CONF_NAME -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from .const import ( @@ -28,28 +28,28 @@ async def test_unique_id_migration(mock_hc, hass, mock_write_config): hass, { # old format - ENTITY_WATCH_TV: entity_registry.RegistryEntry( + ENTITY_WATCH_TV: er.RegistryEntry( entity_id=ENTITY_WATCH_TV, unique_id="123443-Watch TV", platform="harmony", config_entry_id=entry.entry_id, ), # old format, activity name with - - ENTITY_NILE_TV: entity_registry.RegistryEntry( + ENTITY_NILE_TV: er.RegistryEntry( entity_id=ENTITY_NILE_TV, unique_id="123443-Nile-TV", platform="harmony", config_entry_id=entry.entry_id, ), # new format - ENTITY_PLAY_MUSIC: entity_registry.RegistryEntry( + ENTITY_PLAY_MUSIC: er.RegistryEntry( entity_id=ENTITY_PLAY_MUSIC, unique_id=f"activity_{PLAY_MUSIC_ACTIVITY_ID}", platform="harmony", config_entry_id=entry.entry_id, ), # old entity which no longer has a matching activity on the hub. skipped. - "switch.some_other_activity": entity_registry.RegistryEntry( + "switch.some_other_activity": er.RegistryEntry( entity_id="switch.some_other_activity", unique_id="123443-Some Other Activity", platform="harmony", @@ -60,7 +60,7 @@ async def test_unique_id_migration(mock_hc, hass, mock_write_config): assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - ent_reg = await entity_registry.async_get_registry(hass) + ent_reg = er.async_get(hass) switch_tv = ent_reg.async_get(ENTITY_WATCH_TV) assert switch_tv.unique_id == f"activity_{WATCH_TV_ACTIVITY_ID}" diff --git a/tests/components/heos/test_media_player.py b/tests/components/heos/test_media_player.py index 4d979f8e556..8b87acfd9fd 100644 --- a/tests/components/heos/test_media_player.py +++ b/tests/components/heos/test_media_player.py @@ -53,6 +53,7 @@ from homeassistant.const import ( STATE_PLAYING, STATE_UNAVAILABLE, ) +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component @@ -237,8 +238,8 @@ async def test_updates_from_players_changed_new_ids( ): """Test player updates from changes to available players.""" await setup_platform(hass, config_entry, config) - device_registry = await hass.helpers.device_registry.async_get_registry() - entity_registry = await hass.helpers.entity_registry.async_get_registry() + device_registry = dr.async_get(hass) + entity_registry = er.async_get(hass) player = controller.players[1] event = asyncio.Event() diff --git a/tests/components/homekit/test_type_covers.py b/tests/components/homekit/test_type_covers.py index 1c0de6c3af2..8514801687c 100644 --- a/tests/components/homekit/test_type_covers.py +++ b/tests/components/homekit/test_type_covers.py @@ -40,7 +40,7 @@ from homeassistant.const import ( STATE_UNKNOWN, ) from homeassistant.core import CoreState -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from tests.common import async_mock_service @@ -446,7 +446,7 @@ async def test_windowcovering_basic_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create( "cover", @@ -484,7 +484,7 @@ async def test_windowcovering_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create( "cover", diff --git a/tests/components/homekit/test_type_fans.py b/tests/components/homekit/test_type_fans.py index ba660f2f12d..15e2366a883 100644 --- a/tests/components/homekit/test_type_fans.py +++ b/tests/components/homekit/test_type_fans.py @@ -28,7 +28,7 @@ from homeassistant.const import ( STATE_UNKNOWN, ) from homeassistant.core import CoreState -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from tests.common import async_mock_service @@ -526,7 +526,7 @@ async def test_fan_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create( "fan", diff --git a/tests/components/homekit/test_type_lights.py b/tests/components/homekit/test_type_lights.py index 0ab3ef8e45d..0c81de2efe7 100644 --- a/tests/components/homekit/test_type_lights.py +++ b/tests/components/homekit/test_type_lights.py @@ -24,7 +24,7 @@ from homeassistant.const import ( STATE_UNKNOWN, ) from homeassistant.core import CoreState -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from tests.common import async_mock_service @@ -354,7 +354,7 @@ async def test_light_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create("light", "hue", "1234", suggested_object_id="simple") registry.async_get_or_create( diff --git a/tests/components/homekit/test_type_media_players.py b/tests/components/homekit/test_type_media_players.py index 0b9d25ce3ec..b95903d3e3f 100644 --- a/tests/components/homekit/test_type_media_players.py +++ b/tests/components/homekit/test_type_media_players.py @@ -37,7 +37,7 @@ from homeassistant.const import ( STATE_STANDBY, ) from homeassistant.core import CoreState -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from tests.common import async_mock_service @@ -421,7 +421,7 @@ async def test_tv_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create( "media_player", diff --git a/tests/components/homekit/test_type_sensors.py b/tests/components/homekit/test_type_sensors.py index fe2ae7566d5..c7c06dcc90a 100644 --- a/tests/components/homekit/test_type_sensors.py +++ b/tests/components/homekit/test_type_sensors.py @@ -30,7 +30,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) from homeassistant.core import CoreState -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er async def test_temperature(hass, hk_driver): @@ -326,7 +326,7 @@ async def test_sensor_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create( "sensor", diff --git a/tests/components/homekit/test_type_thermostats.py b/tests/components/homekit/test_type_thermostats.py index 7d3d0d14c2f..d9c2a6bf0ed 100644 --- a/tests/components/homekit/test_type_thermostats.py +++ b/tests/components/homekit/test_type_thermostats.py @@ -61,7 +61,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) from homeassistant.core import CoreState -from homeassistant.helpers import entity_registry +from homeassistant.helpers import entity_registry as er from tests.common import async_mock_service @@ -889,7 +889,7 @@ async def test_thermostat_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create( "climate", "generic", "1234", suggested_object_id="simple" @@ -1705,7 +1705,7 @@ async def test_water_heater_restore(hass, hk_driver, events): """Test setting up an entity from state in the event registry.""" hass.state = CoreState.not_running - registry = await entity_registry.async_get_registry(hass) + registry = er.async_get(hass) registry.async_get_or_create( "water_heater", "generic", "1234", suggested_object_id="simple" diff --git a/tests/components/homekit_controller/specific_devices/test_anker_eufycam.py b/tests/components/homekit_controller/specific_devices/test_anker_eufycam.py index 45e0466ceea..15ac6d2d3ab 100644 --- a/tests/components/homekit_controller/specific_devices/test_anker_eufycam.py +++ b/tests/components/homekit_controller/specific_devices/test_anker_eufycam.py @@ -1,4 +1,5 @@ """Test against characteristics captured from a eufycam.""" +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( Helper, @@ -12,7 +13,7 @@ async def test_eufycam_setup(hass): accessories = await setup_accessories_from_file(hass, "anker_eufycam.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Check that the camera is correctly found and set up camera_id = "camera.eufycam2_0000" @@ -32,7 +33,7 @@ async def test_eufycam_setup(hass): assert camera_state.state == "idle" assert camera_state.attributes["supported_features"] == 0 - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(camera.device_id) assert device.manufacturer == "Anker" diff --git a/tests/components/homekit_controller/specific_devices/test_aqara_gateway.py b/tests/components/homekit_controller/specific_devices/test_aqara_gateway.py index 8bee6e0591d..b4437a7a9b5 100644 --- a/tests/components/homekit_controller/specific_devices/test_aqara_gateway.py +++ b/tests/components/homekit_controller/specific_devices/test_aqara_gateway.py @@ -5,6 +5,7 @@ https://github.com/home-assistant/core/issues/20957 """ from homeassistant.components.light import SUPPORT_BRIGHTNESS, SUPPORT_COLOR +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( Helper, @@ -18,7 +19,7 @@ async def test_aqara_gateway_setup(hass): accessories = await setup_accessories_from_file(hass, "aqara_gateway.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Check that the light is correctly found and set up alarm_id = "alarm_control_panel.aqara_hub_1563" @@ -48,7 +49,7 @@ async def test_aqara_gateway_setup(hass): SUPPORT_BRIGHTNESS | SUPPORT_COLOR ) - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) # All the entities are services of the same accessory # So it looks at the protocol like a single physical device diff --git a/tests/components/homekit_controller/specific_devices/test_aqara_switch.py b/tests/components/homekit_controller/specific_devices/test_aqara_switch.py index a9744fb7bfc..6ed0d861193 100644 --- a/tests/components/homekit_controller/specific_devices/test_aqara_switch.py +++ b/tests/components/homekit_controller/specific_devices/test_aqara_switch.py @@ -7,6 +7,8 @@ service-label-index despite not being linked to a service-label. https://github.com/home-assistant/core/pull/39090 """ +from homeassistant.helpers import entity_registry as er + from tests.common import assert_lists_same, async_get_device_automations from tests.components.homekit_controller.common import ( setup_accessories_from_file, @@ -19,7 +21,7 @@ async def test_aqara_switch_setup(hass): accessories = await setup_accessories_from_file(hass, "aqara_switch.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) battery_id = "sensor.programmable_switch_battery" battery = entity_registry.async_get(battery_id) diff --git a/tests/components/homekit_controller/specific_devices/test_ecobee3.py b/tests/components/homekit_controller/specific_devices/test_ecobee3.py index d05e36ed0eb..ae050f67324 100644 --- a/tests/components/homekit_controller/specific_devices/test_ecobee3.py +++ b/tests/components/homekit_controller/specific_devices/test_ecobee3.py @@ -15,6 +15,7 @@ from homeassistant.components.climate.const import ( SUPPORT_TARGET_TEMPERATURE_RANGE, ) from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( Helper, @@ -30,7 +31,7 @@ async def test_ecobee3_setup(hass): accessories = await setup_accessories_from_file(hass, "ecobee3.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) climate = entity_registry.async_get("climate.homew") assert climate.unique_id == "homekit-123456789012-16" @@ -73,7 +74,7 @@ async def test_ecobee3_setup(hass): occ3 = entity_registry.async_get("binary_sensor.basement") assert occ3.unique_id == "homekit-AB3C-56" - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) climate_device = device_registry.async_get(climate.device_id) assert climate_device.manufacturer == "ecobee Inc." @@ -112,7 +113,7 @@ async def test_ecobee3_setup_from_cache(hass, hass_storage): await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) climate = entity_registry.async_get("climate.homew") assert climate.unique_id == "homekit-123456789012-16" @@ -131,7 +132,7 @@ async def test_ecobee3_setup_connection_failure(hass): """Test that Ecbobee can be correctly setup from its cached entity map.""" accessories = await setup_accessories_from_file(hass, "ecobee3.json") - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Test that the connection fails during initial setup. # No entities should be created. @@ -170,7 +171,7 @@ async def test_ecobee3_setup_connection_failure(hass): async def test_ecobee3_add_sensors_at_runtime(hass): """Test that new sensors are automatically added.""" - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Set up a base Ecobee 3 with no additional sensors. # There shouldn't be any entities but climate visible. diff --git a/tests/components/homekit_controller/specific_devices/test_ecobee_occupancy.py b/tests/components/homekit_controller/specific_devices/test_ecobee_occupancy.py index 6823cdc16ea..63f5d22e04b 100644 --- a/tests/components/homekit_controller/specific_devices/test_ecobee_occupancy.py +++ b/tests/components/homekit_controller/specific_devices/test_ecobee_occupancy.py @@ -4,6 +4,8 @@ Regression tests for Ecobee occupancy. https://github.com/home-assistant/core/issues/31827 """ +from homeassistant.helpers import device_registry as dr, entity_registry as er + from tests.components.homekit_controller.common import ( Helper, setup_accessories_from_file, @@ -16,7 +18,7 @@ async def test_ecobee_occupancy_setup(hass): accessories = await setup_accessories_from_file(hass, "ecobee_occupancy.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) sensor = entity_registry.async_get("binary_sensor.master_fan") assert sensor.unique_id == "homekit-111111111111-56" @@ -27,7 +29,7 @@ async def test_ecobee_occupancy_setup(hass): sensor_state = await sensor_helper.poll_and_get_state() assert sensor_state.attributes["friendly_name"] == "Master Fan" - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(sensor.device_id) assert device.manufacturer == "ecobee Inc." diff --git a/tests/components/homekit_controller/specific_devices/test_homeassistant_bridge.py b/tests/components/homekit_controller/specific_devices/test_homeassistant_bridge.py index fbdf00698f7..1cbfa23b64c 100644 --- a/tests/components/homekit_controller/specific_devices/test_homeassistant_bridge.py +++ b/tests/components/homekit_controller/specific_devices/test_homeassistant_bridge.py @@ -5,6 +5,7 @@ from homeassistant.components.fan import ( SUPPORT_OSCILLATE, SUPPORT_SET_SPEED, ) +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( Helper, @@ -20,7 +21,7 @@ async def test_homeassistant_bridge_fan_setup(hass): ) config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Check that the fan is correctly found and set up fan_id = "fan.living_room_fan" @@ -42,7 +43,7 @@ async def test_homeassistant_bridge_fan_setup(hass): SUPPORT_DIRECTION | SUPPORT_SET_SPEED | SUPPORT_OSCILLATE ) - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(fan.device_id) assert device.manufacturer == "Home Assistant" diff --git a/tests/components/homekit_controller/specific_devices/test_hue_bridge.py b/tests/components/homekit_controller/specific_devices/test_hue_bridge.py index 168ae85b228..0452407bfb8 100644 --- a/tests/components/homekit_controller/specific_devices/test_hue_bridge.py +++ b/tests/components/homekit_controller/specific_devices/test_hue_bridge.py @@ -1,5 +1,7 @@ """Tests for handling accessories on a Hue bridge via HomeKit.""" +from homeassistant.helpers import device_registry as dr, entity_registry as er + from tests.common import assert_lists_same, async_get_device_automations from tests.components.homekit_controller.common import ( Helper, @@ -13,7 +15,7 @@ async def test_hue_bridge_setup(hass): accessories = await setup_accessories_from_file(hass, "hue_bridge.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Check that the battery is correctly found and set up battery_id = "sensor.hue_dimmer_switch_battery" @@ -28,7 +30,7 @@ async def test_hue_bridge_setup(hass): assert battery_state.attributes["icon"] == "mdi:battery" assert battery_state.state == "100" - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(battery.device_id) assert device.manufacturer == "Philips" diff --git a/tests/components/homekit_controller/specific_devices/test_koogeek_ls1.py b/tests/components/homekit_controller/specific_devices/test_koogeek_ls1.py index 4682d4b2bcc..505ff2aacc7 100644 --- a/tests/components/homekit_controller/specific_devices/test_koogeek_ls1.py +++ b/tests/components/homekit_controller/specific_devices/test_koogeek_ls1.py @@ -8,6 +8,7 @@ from aiohomekit.testing import FakePairing import pytest from homeassistant.components.light import SUPPORT_BRIGHTNESS, SUPPORT_COLOR +from homeassistant.helpers import device_registry as dr, entity_registry as er import homeassistant.util.dt as dt_util from tests.common import async_fire_time_changed @@ -25,7 +26,7 @@ async def test_koogeek_ls1_setup(hass): accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get("light.koogeek_ls1_20833f") @@ -44,7 +45,7 @@ async def test_koogeek_ls1_setup(hass): SUPPORT_BRIGHTNESS | SUPPORT_COLOR ) - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.manufacturer == "Koogeek" diff --git a/tests/components/homekit_controller/specific_devices/test_koogeek_p1eu.py b/tests/components/homekit_controller/specific_devices/test_koogeek_p1eu.py index f97821ef111..db72aad7541 100644 --- a/tests/components/homekit_controller/specific_devices/test_koogeek_p1eu.py +++ b/tests/components/homekit_controller/specific_devices/test_koogeek_p1eu.py @@ -1,5 +1,7 @@ """Make sure that existing Koogeek P1EU support isn't broken.""" +from homeassistant.helpers import device_registry as dr, entity_registry as er + from tests.components.homekit_controller.common import ( Helper, setup_accessories_from_file, @@ -12,8 +14,8 @@ async def test_koogeek_p1eu_setup(hass): accessories = await setup_accessories_from_file(hass, "koogeek_p1eu.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() - device_registry = await hass.helpers.device_registry.async_get_registry() + entity_registry = er.async_get(hass) + device_registry = dr.async_get(hass) # Check that the switch entity is handled correctly diff --git a/tests/components/homekit_controller/specific_devices/test_lennox_e30.py b/tests/components/homekit_controller/specific_devices/test_lennox_e30.py index a49effdb75d..cdab08039e1 100644 --- a/tests/components/homekit_controller/specific_devices/test_lennox_e30.py +++ b/tests/components/homekit_controller/specific_devices/test_lennox_e30.py @@ -8,6 +8,7 @@ from homeassistant.components.climate.const import ( SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, ) +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( Helper, @@ -21,7 +22,7 @@ async def test_lennox_e30_setup(hass): accessories = await setup_accessories_from_file(hass, "lennox_e30.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) climate = entity_registry.async_get("climate.lennox") assert climate.unique_id == "homekit-XXXXXXXX-100" @@ -35,7 +36,7 @@ async def test_lennox_e30_setup(hass): SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_TEMPERATURE_RANGE ) - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(climate.device_id) assert device.manufacturer == "Lennox" diff --git a/tests/components/homekit_controller/specific_devices/test_lg_tv.py b/tests/components/homekit_controller/specific_devices/test_lg_tv.py index ebc50fda8bc..7f7ada4ac1f 100644 --- a/tests/components/homekit_controller/specific_devices/test_lg_tv.py +++ b/tests/components/homekit_controller/specific_devices/test_lg_tv.py @@ -5,6 +5,7 @@ from homeassistant.components.media_player.const import ( SUPPORT_PLAY, SUPPORT_SELECT_SOURCE, ) +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.common import async_get_device_automations from tests.components.homekit_controller.common import ( @@ -19,7 +20,7 @@ async def test_lg_tv(hass): accessories = await setup_accessories_from_file(hass, "lg_tv.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get("media_player.lg_webos_tv_af80") @@ -54,7 +55,7 @@ async def test_lg_tv(hass): # CURRENT_MEDIA_STATE. Therefore "ok" is the best we can say. assert state.state == "ok" - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.manufacturer == "LG Electronics" diff --git a/tests/components/homekit_controller/specific_devices/test_rainmachine_pro_8.py b/tests/components/homekit_controller/specific_devices/test_rainmachine_pro_8.py index fd95ef98c09..81e31918c91 100644 --- a/tests/components/homekit_controller/specific_devices/test_rainmachine_pro_8.py +++ b/tests/components/homekit_controller/specific_devices/test_rainmachine_pro_8.py @@ -4,6 +4,8 @@ Make sure that existing RainMachine support isn't broken. https://github.com/home-assistant/core/issues/31745 """ +from homeassistant.helpers import device_registry as dr, entity_registry as er + from tests.components.homekit_controller.common import ( Helper, setup_accessories_from_file, @@ -16,7 +18,7 @@ async def test_rainmachine_pro_8_setup(hass): accessories = await setup_accessories_from_file(hass, "rainmachine-pro-8.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Assert that the entity is correctly added to the entity registry entry = entity_registry.async_get("switch.rainmachine_00ce4a") @@ -30,7 +32,7 @@ async def test_rainmachine_pro_8_setup(hass): # Assert that the friendly name is detected correctly assert state.attributes["friendly_name"] == "RainMachine-00ce4a" - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert device.manufacturer == "Green Electronics LLC" diff --git a/tests/components/homekit_controller/specific_devices/test_simpleconnect_fan.py b/tests/components/homekit_controller/specific_devices/test_simpleconnect_fan.py index b30dd1e9c89..a2195320293 100644 --- a/tests/components/homekit_controller/specific_devices/test_simpleconnect_fan.py +++ b/tests/components/homekit_controller/specific_devices/test_simpleconnect_fan.py @@ -5,6 +5,7 @@ https://github.com/home-assistant/core/issues/26180 """ from homeassistant.components.fan import SUPPORT_DIRECTION, SUPPORT_SET_SPEED +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( Helper, @@ -18,7 +19,7 @@ async def test_simpleconnect_fan_setup(hass): accessories = await setup_accessories_from_file(hass, "simpleconnect_fan.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Check that the fan is correctly found and set up fan_id = "fan.simpleconnect_fan_06f674" @@ -40,7 +41,7 @@ async def test_simpleconnect_fan_setup(hass): SUPPORT_DIRECTION | SUPPORT_SET_SPEED ) - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(fan.device_id) assert device.manufacturer == "Hunter Fan" diff --git a/tests/components/homekit_controller/specific_devices/test_velux_gateway.py b/tests/components/homekit_controller/specific_devices/test_velux_gateway.py index 033b4aa7b4d..b93afdfbfa4 100644 --- a/tests/components/homekit_controller/specific_devices/test_velux_gateway.py +++ b/tests/components/homekit_controller/specific_devices/test_velux_gateway.py @@ -9,6 +9,7 @@ from homeassistant.components.cover import ( SUPPORT_OPEN, SUPPORT_SET_POSITION, ) +from homeassistant.helpers import device_registry as dr, entity_registry as er from tests.components.homekit_controller.common import ( Helper, @@ -22,7 +23,7 @@ async def test_simpleconnect_cover_setup(hass): accessories = await setup_accessories_from_file(hass, "velux_gateway.json") config_entry, pairing = await setup_test_accessories(hass, accessories) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Check that the cover is correctly found and set up cover_id = "cover.velux_window" @@ -64,7 +65,7 @@ async def test_simpleconnect_cover_setup(hass): # The cover and sensor are different devices (accessories) attached to the same bridge assert cover.device_id != sensor.device_id - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(cover.device_id) assert device.manufacturer == "VELUX" diff --git a/tests/components/homekit_controller/test_device_trigger.py b/tests/components/homekit_controller/test_device_trigger.py index ce771eac768..cbb8da36bc2 100644 --- a/tests/components/homekit_controller/test_device_trigger.py +++ b/tests/components/homekit_controller/test_device_trigger.py @@ -5,6 +5,7 @@ import pytest import homeassistant.components.automation as automation from homeassistant.components.homekit_controller.const import DOMAIN +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component from tests.common import ( @@ -82,10 +83,10 @@ async def test_enumerate_remote(hass, utcnow): """Test that remote is correctly enumerated.""" await setup_test_component(hass, create_remote) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) expected = [ @@ -118,10 +119,10 @@ async def test_enumerate_button(hass, utcnow): """Test that a button is correctly enumerated.""" await setup_test_component(hass, create_button) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) expected = [ @@ -153,10 +154,10 @@ async def test_enumerate_doorbell(hass, utcnow): """Test that a button is correctly enumerated.""" await setup_test_component(hass, create_doorbell) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) expected = [ @@ -188,10 +189,10 @@ async def test_handle_events(hass, utcnow, calls): """Test that events are handled.""" helper = await setup_test_component(hass, create_remote) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.testdevice_battery") - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(entry.device_id) assert await async_setup_component( diff --git a/tests/components/homematicip_cloud/test_device.py b/tests/components/homematicip_cloud/test_device.py index 264d93c4145..6f1d3071714 100644 --- a/tests/components/homematicip_cloud/test_device.py +++ b/tests/components/homematicip_cloud/test_device.py @@ -41,8 +41,8 @@ async def test_hmip_remove_device(hass, default_mock_hap_factory): assert ha_state.state == STATE_ON assert hmip_device - device_registry = await dr.async_get_registry(hass) - entity_registry = await er.async_get_registry(hass) + device_registry = dr.async_get(hass) + entity_registry = er.async_get(hass) pre_device_count = len(device_registry.devices) pre_entity_count = len(entity_registry.entities) @@ -73,8 +73,8 @@ async def test_hmip_add_device(hass, default_mock_hap_factory, hmip_config_entry assert ha_state.state == STATE_ON assert hmip_device - device_registry = await dr.async_get_registry(hass) - entity_registry = await er.async_get_registry(hass) + device_registry = dr.async_get(hass) + entity_registry = er.async_get(hass) pre_device_count = len(device_registry.devices) pre_entity_count = len(entity_registry.entities) @@ -119,8 +119,8 @@ async def test_hmip_remove_group(hass, default_mock_hap_factory): assert ha_state.state == STATE_ON assert hmip_device - device_registry = await dr.async_get_registry(hass) - entity_registry = await er.async_get_registry(hass) + device_registry = dr.async_get(hass) + entity_registry = er.async_get(hass) pre_device_count = len(device_registry.devices) pre_entity_count = len(entity_registry.entities) @@ -257,12 +257,12 @@ async def test_hmip_multi_area_device(hass, default_mock_hap_factory): assert ha_state # get the entity - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) entity = entity_registry.async_get(ha_state.entity_id) assert entity # get the device - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device = device_registry.async_get(entity.device_id) assert device.name == "Wired Eingangsmodul – 32-fach" diff --git a/tests/components/hue/test_light.py b/tests/components/hue/test_light.py index 39b9a5a23fc..df873536ce2 100644 --- a/tests/components/hue/test_light.py +++ b/tests/components/hue/test_light.py @@ -7,12 +7,7 @@ import aiohue from homeassistant import config_entries from homeassistant.components import hue from homeassistant.components.hue import light as hue_light -from homeassistant.helpers.device_registry import ( - async_get_registry as async_get_device_registry, -) -from homeassistant.helpers.entity_registry import ( - async_get_registry as async_get_entity_registry, -) +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.util import color HUE_LIGHT_NS = "homeassistant.components.light.hue." @@ -937,8 +932,8 @@ async def test_group_features(hass, mock_bridge): group_3 = hass.states.get("light.dining_room") assert group_3.attributes["supported_features"] == extended_color_feature - entity_registry = await async_get_entity_registry(hass) - device_registry = await async_get_device_registry(hass) + entity_registry = er.async_get(hass) + device_registry = dr.async_get(hass) entry = entity_registry.async_get("light.hue_lamp_1") device_entry = device_registry.async_get(entry.device_id) diff --git a/tests/components/hyperion/test_light.py b/tests/components/hyperion/test_light.py index fe4279ed731..94f41aa4fd0 100644 --- a/tests/components/hyperion/test_light.py +++ b/tests/components/hyperion/test_light.py @@ -26,7 +26,7 @@ from homeassistant.const import ( SERVICE_TURN_OFF, SERVICE_TURN_ON, ) -from homeassistant.helpers.entity_registry import async_get_registry +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.typing import HomeAssistantType import homeassistant.util.color as color_util @@ -109,7 +109,7 @@ async def test_setup_config_entry_not_ready_load_state_fail( async def test_setup_config_entry_dynamic_instances(hass: HomeAssistantType) -> None: """Test dynamic changes in the instance configuration.""" - registry = await async_get_registry(hass) + registry = er.async_get(hass) config_entry = add_test_config_entry(hass)