diff --git a/homeassistant/auth/auth_store.py b/homeassistant/auth/auth_store.py index 398a4ec839a..d2c3db79726 100644 --- a/homeassistant/auth/auth_store.py +++ b/homeassistant/auth/auth_store.py @@ -9,6 +9,7 @@ from logging import getLogger from typing import Any from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.util import dt as dt_util from . import models @@ -303,11 +304,9 @@ class AuthStore: async def _async_load_task(self) -> None: """Load the users.""" - [ent_reg, dev_reg, data] = await asyncio.gather( - self.hass.helpers.entity_registry.async_get_registry(), - self.hass.helpers.device_registry.async_get_registry(), - self._store.async_load(), - ) + dev_reg = dr.async_get(self.hass) + ent_reg = er.async_get(self.hass) + data = await self._store.async_load() # Make sure that we're not overriding data if 2 loads happened at the # same time diff --git a/homeassistant/components/binary_sensor/device_trigger.py b/homeassistant/components/binary_sensor/device_trigger.py index 9989e415242..5b20b991403 100644 --- a/homeassistant/components/binary_sensor/device_trigger.py +++ b/homeassistant/components/binary_sensor/device_trigger.py @@ -8,9 +8,8 @@ from homeassistant.components.device_automation.const import ( ) from homeassistant.components.homeassistant.triggers import state as state_trigger from homeassistant.const import CONF_ENTITY_ID, CONF_FOR, CONF_TYPE -from homeassistant.helpers import config_validation as cv +from homeassistant.helpers import config_validation as cv, entity_registry as er from homeassistant.helpers.entity import get_device_class -from homeassistant.helpers.entity_registry import async_entries_for_device from . import DOMAIN, BinarySensorDeviceClass @@ -280,11 +279,11 @@ async def async_attach_trigger(hass, config, action, automation_info): async def async_get_triggers(hass, device_id): """List device triggers.""" triggers = [] - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entries = [ entry - for entry in async_entries_for_device(entity_registry, device_id) + for entry in er.async_entries_for_device(entity_registry, device_id) if entry.domain == DOMAIN ] diff --git a/homeassistant/components/device_automation/entity.py b/homeassistant/components/device_automation/entity.py index b27a8c67561..9fa878ea038 100644 --- a/homeassistant/components/device_automation/entity.py +++ b/homeassistant/components/device_automation/entity.py @@ -12,8 +12,7 @@ from homeassistant.components.automation import ( from homeassistant.components.homeassistant.triggers import state as state_trigger from homeassistant.const import CONF_ENTITY_ID, CONF_FOR, CONF_PLATFORM, CONF_TYPE from homeassistant.core import CALLBACK_TYPE, HomeAssistant -from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.entity_registry import async_entries_for_device +from homeassistant.helpers import config_validation as cv, entity_registry as er from homeassistant.helpers.typing import ConfigType from . import DEVICE_TRIGGER_BASE_SCHEMA @@ -68,11 +67,11 @@ async def _async_get_automations( ) -> list[dict[str, str]]: """List device automations.""" automations: list[dict[str, str]] = [] - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entries = [ entry - for entry in async_entries_for_device(entity_registry, device_id) + for entry in er.async_entries_for_device(entity_registry, device_id) if entry.domain == domain ] diff --git a/homeassistant/components/device_automation/toggle_entity.py b/homeassistant/components/device_automation/toggle_entity.py index 4559e88f9d3..4ae32927bf4 100644 --- a/homeassistant/components/device_automation/toggle_entity.py +++ b/homeassistant/components/device_automation/toggle_entity.py @@ -20,8 +20,11 @@ from homeassistant.const import ( CONF_TYPE, ) from homeassistant.core import CALLBACK_TYPE, Context, HomeAssistant, callback -from homeassistant.helpers import condition, config_validation as cv -from homeassistant.helpers.entity_registry import async_entries_for_device +from homeassistant.helpers import ( + condition, + config_validation as cv, + entity_registry as er, +) from homeassistant.helpers.typing import ConfigType, TemplateVarsType from . import DEVICE_TRIGGER_BASE_SCHEMA, entity @@ -187,11 +190,11 @@ async def _async_get_automations( ) -> list[dict[str, str]]: """List device automations.""" automations: list[dict[str, str]] = [] - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entries = [ entry - for entry in async_entries_for_device(entity_registry, device_id) + for entry in er.async_entries_for_device(entity_registry, device_id) if entry.domain == domain ] diff --git a/homeassistant/components/emulated_kasa/__init__.py b/homeassistant/components/emulated_kasa/__init__.py index 9643962ecb4..41198f922cf 100644 --- a/homeassistant/components/emulated_kasa/__init__.py +++ b/homeassistant/components/emulated_kasa/__init__.py @@ -14,8 +14,8 @@ from homeassistant.const import ( STATE_ON, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity_registry import RegistryEntry from homeassistant.helpers.template import Template, is_template_string from homeassistant.helpers.typing import ConfigType @@ -79,7 +79,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def validate_configs(hass, entity_configs): """Validate that entities exist and ensure templates are ready to use.""" - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) for entity_id, entity_config in entity_configs.items(): if (state := hass.states.get(entity_id)) is None: _LOGGER.debug("Entity not found: %s", entity_id) @@ -108,7 +108,7 @@ async def validate_configs(hass, entity_configs): _LOGGER.debug("No power value defined for: %s", entity_id) -def get_system_unique_id(entity: RegistryEntry): +def get_system_unique_id(entity: er.RegistryEntry): """Determine the system wide unique_id for an entity.""" return f"{entity.platform}.{entity.domain}.{entity.unique_id}" diff --git a/homeassistant/components/evohome/__init__.py b/homeassistant/components/evohome/__init__.py index 5f83caa8648..0085eb701d0 100644 --- a/homeassistant/components/evohome/__init__.py +++ b/homeassistant/components/evohome/__init__.py @@ -24,6 +24,7 @@ from homeassistant.const import ( Platform, ) from homeassistant.core import HomeAssistant, ServiceCall, callback +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import async_load_platform @@ -297,7 +298,7 @@ def setup_service_functions(hass: HomeAssistant, broker): """Set the zone override (setpoint).""" entity_id = call.data[ATTR_ENTITY_ID] - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) registry_entry = registry.async_get(entity_id) if registry_entry is None or registry_entry.platform != DOMAIN: diff --git a/homeassistant/components/geniushub/__init__.py b/homeassistant/components/geniushub/__init__.py index 947dd325064..3c5cc22af81 100644 --- a/homeassistant/components/geniushub/__init__.py +++ b/homeassistant/components/geniushub/__init__.py @@ -21,7 +21,7 @@ from homeassistant.const import ( Platform, ) from homeassistant.core import HomeAssistant, ServiceCall, callback -from homeassistant.helpers import config_validation as cv +from homeassistant.helpers import config_validation as cv, entity_registry as er from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.dispatcher import ( @@ -146,7 +146,7 @@ def setup_service_functions(hass: HomeAssistant, broker): """Set the system mode.""" entity_id = call.data[ATTR_ENTITY_ID] - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) registry_entry = registry.async_get(entity_id) if registry_entry is None or registry_entry.platform != DOMAIN: diff --git a/homeassistant/components/heos/__init__.py b/homeassistant/components/heos/__init__.py index dbd66e28307..a7f56e91368 100644 --- a/homeassistant/components/heos/__init__.py +++ b/homeassistant/components/heos/__init__.py @@ -12,6 +12,7 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import CONF_HOST, EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError +from homeassistant.helpers import device_registry as dr, entity_registry as er import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, @@ -167,10 +168,9 @@ class ControllerManager: async def connect_listeners(self): """Subscribe to events of interest.""" - self._device_registry, self._entity_registry = await asyncio.gather( - self._hass.helpers.device_registry.async_get_registry(), - self._hass.helpers.entity_registry.async_get_registry(), - ) + self._device_registry = dr.async_get(self._hass) + self._entity_registry = er.async_get(self._hass) + # Handle controller events self._signals.append( self.controller.dispatcher.connect( diff --git a/homeassistant/components/homekit/aidmanager.py b/homeassistant/components/homekit/aidmanager.py index ddba9d02bcd..27bd6234d46 100644 --- a/homeassistant/components/homekit/aidmanager.py +++ b/homeassistant/components/homekit/aidmanager.py @@ -17,7 +17,7 @@ import random from fnvhash import fnv1a_32 from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers.entity_registry import EntityRegistry, RegistryEntry +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.storage import Store from .util import get_aid_storage_filename_for_entry_id @@ -34,7 +34,7 @@ AID_MIN = 2 AID_MAX = 18446744073709551615 -def get_system_unique_id(entity: RegistryEntry) -> str: +def get_system_unique_id(entity: er.RegistryEntry) -> str: """Determine the system wide unique_id for an entity.""" return f"{entity.platform}.{entity.domain}.{entity.unique_id}" @@ -74,13 +74,11 @@ class AccessoryAidStorage: self.allocated_aids: set[int] = set() self._entry_id = entry_id self.store: Store | None = None - self._entity_registry: EntityRegistry | None = None + self._entity_registry: er.EntityRegistry | None = None async def async_initialize(self) -> None: """Load the latest AID data.""" - self._entity_registry = ( - await self.hass.helpers.entity_registry.async_get_registry() - ) + self._entity_registry = er.async_get(self.hass) aidstore = get_aid_storage_filename_for_entry_id(self._entry_id) self.store = Store(self.hass, AID_MANAGER_STORAGE_VERSION, aidstore) diff --git a/homeassistant/components/nest/__init__.py b/homeassistant/components/nest/__init__.py index 076b9a58814..5a34df1d74b 100644 --- a/homeassistant/components/nest/__init__.py +++ b/homeassistant/components/nest/__init__.py @@ -42,7 +42,7 @@ from homeassistant.exceptions import ( HomeAssistantError, Unauthorized, ) -from homeassistant.helpers import config_validation as cv +from homeassistant.helpers import config_validation as cv, entity_registry as er from homeassistant.helpers.entity_registry import async_entries_for_device from homeassistant.helpers.typing import ConfigType @@ -266,7 +266,7 @@ class NestEventViewBase(HomeAssistantView, ABC): ) -> web.StreamResponse: """Start a GET request.""" user = request[KEY_HASS_USER] - entity_registry = await self.hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(self.hass) for entry in async_entries_for_device(entity_registry, device_id): if not user.permissions.check_entity(entry.entity_id, POLICY_READ): raise Unauthorized(entity_id=entry.entity_id) diff --git a/homeassistant/components/risco/sensor.py b/homeassistant/components/risco/sensor.py index 3f3dc221fac..6038c2911c9 100644 --- a/homeassistant/components/risco/sensor.py +++ b/homeassistant/components/risco/sensor.py @@ -3,6 +3,7 @@ from homeassistant.components.binary_sensor import DOMAIN as BS_DOMAIN from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.util import dt as dt_util @@ -75,9 +76,7 @@ class RiscoSensor(CoordinatorEntity, SensorEntity): async def async_added_to_hass(self): """When entity is added to hass.""" - self._entity_registry = ( - await self.hass.helpers.entity_registry.async_get_registry() - ) + self._entity_registry = er.async_get(self.hass) self.async_on_remove( self.coordinator.async_add_listener(self._refresh_from_coordinator) ) diff --git a/homeassistant/components/samsungtv/__init__.py b/homeassistant/components/samsungtv/__init__.py index 49963734e83..b870aab62d4 100644 --- a/homeassistant/components/samsungtv/__init__.py +++ b/homeassistant/components/samsungtv/__init__.py @@ -26,6 +26,7 @@ from homeassistant.const import ( ) from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady +from homeassistant.helpers import device_registry as dr, entity_registry as er import homeassistant.helpers.config_validation as cv from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.typing import ConfigType @@ -313,10 +314,10 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> # 1 -> 2: Unique ID format changed, so delete and re-import: if version == 1: - dev_reg = await hass.helpers.device_registry.async_get_registry() + dev_reg = dr.async_get(hass) dev_reg.async_clear_config_entry(config_entry.entry_id) - en_reg = await hass.helpers.entity_registry.async_get_registry() + en_reg = er.async_get(hass) en_reg.async_clear_config_entry(config_entry.entry_id) version = config_entry.version = 2 diff --git a/homeassistant/components/sensor/device_trigger.py b/homeassistant/components/sensor/device_trigger.py index f90022cf5f3..d760b92b31c 100644 --- a/homeassistant/components/sensor/device_trigger.py +++ b/homeassistant/components/sensor/device_trigger.py @@ -16,13 +16,12 @@ from homeassistant.const import ( CONF_TYPE, ) from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import config_validation as cv +from homeassistant.helpers import config_validation as cv, entity_registry as er from homeassistant.helpers.entity import ( get_capability, get_device_class, get_unit_of_measurement, ) -from homeassistant.helpers.entity_registry import async_entries_for_device from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass @@ -159,11 +158,11 @@ async def async_attach_trigger(hass, config, action, automation_info): async def async_get_triggers(hass, device_id): """List device triggers.""" triggers = [] - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entries = [ entry - for entry in async_entries_for_device(entity_registry, device_id) + for entry in er.async_entries_for_device(entity_registry, device_id) if entry.domain == DOMAIN ] diff --git a/homeassistant/components/seventeentrack/sensor.py b/homeassistant/components/seventeentrack/sensor.py index 36fabaa7337..12cdcc0680c 100644 --- a/homeassistant/components/seventeentrack/sensor.py +++ b/homeassistant/components/seventeentrack/sensor.py @@ -19,7 +19,11 @@ from homeassistant.const import ( CONF_USERNAME, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers import aiohttp_client, config_validation as cv +from homeassistant.helpers import ( + aiohttp_client, + config_validation as cv, + entity_registry as er, +) from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_call_later from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -234,7 +238,7 @@ class SeventeenTrackPackageSensor(SensorEntity): """Remove entity itself.""" await self.async_remove(force_remove=True) - reg = await self.hass.helpers.entity_registry.async_get_registry() + reg = er.async_get(self.hass) entity_id = reg.async_get_entity_id( "sensor", "seventeentrack", diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 77c09283fbf..0398250df71 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -11,7 +11,7 @@ from aioshelly.rpc_device import RpcDevice from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import device_registry, singleton +from homeassistant.helpers import device_registry, entity_registry, singleton from homeassistant.helpers.typing import EventType from homeassistant.util.dt import utcnow @@ -34,7 +34,7 @@ async def async_remove_shelly_entity( hass: HomeAssistant, domain: str, unique_id: str ) -> None: """Remove a Shelly entity.""" - entity_reg = await hass.helpers.entity_registry.async_get_registry() + entity_reg = entity_registry.async_get(hass) entity_id = entity_reg.async_get_entity_id(domain, DOMAIN, unique_id) if entity_id: LOGGER.debug("Removing entity: %s", entity_id) diff --git a/homeassistant/components/unifi/switch.py b/homeassistant/components/unifi/switch.py index 9151c81543a..67c4d5c4544 100644 --- a/homeassistant/components/unifi/switch.py +++ b/homeassistant/components/unifi/switch.py @@ -20,6 +20,7 @@ from homeassistant.components.switch import DOMAIN, SwitchDeviceClass, SwitchEnt from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_NAME from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.device_registry import ( CONNECTION_NETWORK_MAC, DeviceEntryType, @@ -27,7 +28,6 @@ from homeassistant.helpers.device_registry import ( from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.entity_registry import async_entries_for_config_entry from homeassistant.helpers.restore_state import RestoreEntity from .const import ATTR_MANUFACTURER, DOMAIN as UNIFI_DOMAIN @@ -65,8 +65,10 @@ async def async_setup_entry( # Store previously known POE control entities in case their POE are turned off. known_poe_clients = [] - entity_registry = await hass.helpers.entity_registry.async_get_registry() - for entry in async_entries_for_config_entry(entity_registry, config_entry.entry_id): + entity_registry = er.async_get(hass) + for entry in er.async_entries_for_config_entry( + entity_registry, config_entry.entry_id + ): if not entry.unique_id.startswith(POE_SWITCH): continue diff --git a/homeassistant/components/vera/config_flow.py b/homeassistant/components/vera/config_flow.py index b2c4fe5e5db..319dcd031d0 100644 --- a/homeassistant/components/vera/config_flow.py +++ b/homeassistant/components/vera/config_flow.py @@ -14,7 +14,7 @@ from homeassistant import config_entries from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE from homeassistant.core import callback -from homeassistant.helpers.entity_registry import EntityRegistry +from homeassistant.helpers import entity_registry as er from .const import CONF_CONTROLLER, CONF_LEGACY_UNIQUE_ID, DOMAIN @@ -119,9 +119,7 @@ class VeraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # If there are entities with the legacy unique_id, then this imported config # should also use the legacy unique_id for entity creation. - entity_registry: EntityRegistry = ( - await self.hass.helpers.entity_registry.async_get_registry() - ) + entity_registry = er.async_get(self.hass) use_legacy_unique_id = ( len( [ diff --git a/homeassistant/components/withings/common.py b/homeassistant/components/withings/common.py index c0dadb47924..78ae375b4bc 100644 --- a/homeassistant/components/withings/common.py +++ b/homeassistant/components/withings/common.py @@ -41,7 +41,7 @@ from homeassistant.const import ( ) from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import config_entry_oauth2_flow +from homeassistant.helpers import config_entry_oauth2_flow, entity_registry as er from homeassistant.helpers.config_entry_oauth2_flow import ( AUTH_CALLBACK_PATH, AbstractOAuth2Implementation, @@ -49,7 +49,6 @@ from homeassistant.helpers.config_entry_oauth2_flow import ( OAuth2Session, ) from homeassistant.helpers.entity import Entity -from homeassistant.helpers.entity_registry import EntityRegistry from homeassistant.helpers.network import get_url from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.util import dt @@ -918,9 +917,7 @@ async def async_get_entity_id( hass: HomeAssistant, attribute: WithingsAttribute, user_id: int ) -> str | None: """Get an entity id for a user's attribute.""" - entity_registry: EntityRegistry = ( - await hass.helpers.entity_registry.async_get_registry() - ) + entity_registry = er.async_get(hass) unique_id = get_attribute_unique_id(attribute, user_id) entity_id = entity_registry.async_get_entity_id( diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 975b05067b2..9a1e6caa27e 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -791,7 +791,7 @@ def verify_domain_control( user_id=call.context.user_id, ) - reg = await hass.helpers.entity_registry.async_get_registry() + reg = entity_registry.async_get(hass) authorized = False diff --git a/tests/auth/test_auth_store.py b/tests/auth/test_auth_store.py index 0c650adba3c..e52a0dc88f5 100644 --- a/tests/auth/test_auth_store.py +++ b/tests/auth/test_auth_store.py @@ -236,9 +236,9 @@ async def test_loading_race_condition(hass): """Test only one storage load called when concurrent loading occurred .""" store = auth_store.AuthStore(hass) with patch( - "homeassistant.helpers.entity_registry.async_get_registry" + "homeassistant.helpers.entity_registry.async_get" ) as mock_ent_registry, patch( - "homeassistant.helpers.device_registry.async_get_registry" + "homeassistant.helpers.device_registry.async_get" ) as mock_dev_registry, patch( "homeassistant.helpers.storage.Store.async_load", return_value=None ) as mock_load: diff --git a/tests/components/kraken/test_sensor.py b/tests/components/kraken/test_sensor.py index bc37b67e676..cbfda938f99 100644 --- a/tests/components/kraken/test_sensor.py +++ b/tests/components/kraken/test_sensor.py @@ -11,6 +11,7 @@ from homeassistant.components.kraken.const import ( DOMAIN, ) from homeassistant.const import CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_START +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.device_registry import DeviceEntryType import homeassistant.util.dt as dt_util @@ -52,7 +53,7 @@ async def test_sensor(hass): ) entry.add_to_hass(hass) - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) # Pre-create registry entries for disabled by default sensors registry.async_get_or_create( diff --git a/tests/components/lcn/test_cover.py b/tests/components/lcn/test_cover.py index f89cfa41071..8c6b814e525 100644 --- a/tests/components/lcn/test_cover.py +++ b/tests/components/lcn/test_cover.py @@ -18,6 +18,7 @@ from homeassistant.const import ( STATE_OPENING, STATE_UNAVAILABLE, ) +from homeassistant.helpers import entity_registry as er from .conftest import MockModuleConnection @@ -35,7 +36,7 @@ async def test_setup_lcn_cover(hass, entry, lcn_connection): async def test_entity_attributes(hass, entry, lcn_connection): """Test the attributes of an entity.""" - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entity_outputs = entity_registry.async_get("cover.cover_outputs") diff --git a/tests/components/lcn/test_light.py b/tests/components/lcn/test_light.py index c74ecd2beb9..efde0daa68f 100644 --- a/tests/components/lcn/test_light.py +++ b/tests/components/lcn/test_light.py @@ -23,6 +23,7 @@ from homeassistant.const import ( STATE_ON, STATE_UNAVAILABLE, ) +from homeassistant.helpers import entity_registry as er from .conftest import MockModuleConnection @@ -54,7 +55,7 @@ async def test_entity_state(hass, lcn_connection): async def test_entity_attributes(hass, entry, lcn_connection): """Test the attributes of an entity.""" - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entity_output = entity_registry.async_get("light.light_output1") diff --git a/tests/components/lcn/test_switch.py b/tests/components/lcn/test_switch.py index aee063f310d..8c4fb1ff0a8 100644 --- a/tests/components/lcn/test_switch.py +++ b/tests/components/lcn/test_switch.py @@ -15,6 +15,7 @@ from homeassistant.const import ( STATE_ON, STATE_UNAVAILABLE, ) +from homeassistant.helpers import entity_registry as er from .conftest import MockModuleConnection @@ -34,7 +35,7 @@ async def test_setup_lcn_switch(hass, lcn_connection): async def test_entity_attributes(hass, entry, lcn_connection): """Test the attributes of an entity.""" - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entity_output = entity_registry.async_get("switch.switch_output1") diff --git a/tests/components/nws/test_sensor.py b/tests/components/nws/test_sensor.py index aa5ca3bf66c..5a55907e53b 100644 --- a/tests/components/nws/test_sensor.py +++ b/tests/components/nws/test_sensor.py @@ -4,6 +4,7 @@ import pytest from homeassistant.components.nws.const import ATTRIBUTION, DOMAIN, SENSOR_TYPES from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.const import ATTR_ATTRIBUTION, STATE_UNKNOWN +from homeassistant.helpers import entity_registry as er from homeassistant.util import slugify from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM @@ -33,7 +34,7 @@ async def test_imperial_metric( hass, units, result_observation, result_forecast, mock_simple_nws, no_weather ): """Test with imperial and metric units.""" - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) for description in SENSOR_TYPES: registry.async_get_or_create( @@ -66,7 +67,7 @@ async def test_none_values(hass, mock_simple_nws, no_weather): instance = mock_simple_nws.return_value instance.observation = NONE_OBSERVATION - registry = await hass.helpers.entity_registry.async_get_registry() + registry = er.async_get(hass) for description in SENSOR_TYPES: registry.async_get_or_create( diff --git a/tests/components/octoprint/test_binary_sensor.py b/tests/components/octoprint/test_binary_sensor.py index 55e240eb282..e4a028f346a 100644 --- a/tests/components/octoprint/test_binary_sensor.py +++ b/tests/components/octoprint/test_binary_sensor.py @@ -1,6 +1,7 @@ """The tests for Octoptint binary sensor module.""" from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE +from homeassistant.helpers import entity_registry as er from . import init_integration @@ -16,7 +17,7 @@ async def test_sensors(hass): } await init_integration(hass, "binary_sensor", printer=printer) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) state = hass.states.get("binary_sensor.octoprint_printing") assert state is not None @@ -37,7 +38,7 @@ async def test_sensors_printer_offline(hass): """Test the underlying sensors when the printer is offline.""" await init_integration(hass, "binary_sensor", printer=None) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) state = hass.states.get("binary_sensor.octoprint_printing") assert state is not None diff --git a/tests/components/picnic/test_sensor.py b/tests/components/picnic/test_sensor.py index 7b1bdeb1d12..808f1ce6f41 100644 --- a/tests/components/picnic/test_sensor.py +++ b/tests/components/picnic/test_sensor.py @@ -17,6 +17,7 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.util import dt @@ -97,9 +98,7 @@ class TestPicnicSensor(unittest.IsolatedAsyncioTestCase): async def asyncSetUp(self): """Set up things to be run when tests are started.""" self.hass = await async_test_home_assistant(None) - self.entity_registry = ( - await self.hass.helpers.entity_registry.async_get_registry() - ) + self.entity_registry = er.async_get(self.hass) # Patch the api client self.picnic_patcher = patch("homeassistant.components.picnic.PicnicAPI") diff --git a/tests/components/plex/test_device_handling.py b/tests/components/plex/test_device_handling.py index 2c23ee7cb09..6d2b7524d34 100644 --- a/tests/components/plex/test_device_handling.py +++ b/tests/components/plex/test_device_handling.py @@ -2,14 +2,15 @@ from homeassistant.components.plex.const import DOMAIN from homeassistant.const import Platform +from homeassistant.helpers import device_registry as dr, entity_registry as er async def test_cleanup_orphaned_devices(hass, entry, setup_plex_server): """Test cleaning up orphaned devices on startup.""" test_device_id = {(DOMAIN, "temporary_device_123")} - 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) test_device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, @@ -44,8 +45,8 @@ async def test_migrate_transient_devices( non_plexweb_device_id = {(DOMAIN, "1234567890123456-com-plexapp-android")} plex_client_service_device_id = {(DOMAIN, "plex.tv-clients")} - 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) # Pre-create devices and entities to test device migration plexweb_device = device_registry.async_get_or_create( diff --git a/tests/components/prosegur/test_alarm_control_panel.py b/tests/components/prosegur/test_alarm_control_panel.py index 9ab0c0d37de..8a50319047e 100644 --- a/tests/components/prosegur/test_alarm_control_panel.py +++ b/tests/components/prosegur/test_alarm_control_panel.py @@ -18,7 +18,7 @@ from homeassistant.const import ( STATE_ALARM_DISARMED, STATE_UNAVAILABLE, ) -from homeassistant.helpers import entity_component +from homeassistant.helpers import entity_component, entity_registry as er from .common import CONTRACT, setup_platform @@ -49,7 +49,7 @@ def mock_status(request): async def test_entity_registry(hass, mock_auth, mock_status): """Tests that the devices are registered in the entity registry.""" await setup_platform(hass) - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get(PROSEGUR_ALARM_ENTITY) # Prosegur alarm device unique_id is the contract id associated to the alarm account diff --git a/tests/components/subaru/test_lock.py b/tests/components/subaru/test_lock.py index 19918ba205c..7ccc1e5fdf5 100644 --- a/tests/components/subaru/test_lock.py +++ b/tests/components/subaru/test_lock.py @@ -13,6 +13,7 @@ from homeassistant.components.subaru.const import ( ) from homeassistant.const import ATTR_ENTITY_ID, SERVICE_LOCK, SERVICE_UNLOCK from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers import entity_registry as er from .conftest import MOCK_API @@ -23,7 +24,7 @@ DEVICE_ID = "lock.test_vehicle_2_door_locks" async def test_device_exists(hass, ev_entry): """Test subaru lock entity exists.""" - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get(DEVICE_ID) assert entry diff --git a/tests/components/totalconnect/test_alarm_control_panel.py b/tests/components/totalconnect/test_alarm_control_panel.py index 3066dfff172..07cb5f3d40a 100644 --- a/tests/components/totalconnect/test_alarm_control_panel.py +++ b/tests/components/totalconnect/test_alarm_control_panel.py @@ -30,6 +30,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers import entity_registry as er from homeassistant.util import dt from .common import ( @@ -76,7 +77,7 @@ async def test_attributes(hass: HomeAssistant) -> None: mock_request.assert_called_once() assert state.attributes.get(ATTR_FRIENDLY_NAME) == "test" - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) entry = entity_registry.async_get(ENTITY_ID) # TotalConnect partition #1 alarm device unique_id is the location_id assert entry.unique_id == LOCATION_ID