From e1e864d2b6576da8493dad0ddc794fd0cf226065 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 27 Oct 2021 15:58:14 -0700 Subject: [PATCH] Get the registry using the callback method (#58542) --- homeassistant/components/agent_dvr/__init__.py | 2 +- homeassistant/components/apple_tv/__init__.py | 7 ++++--- homeassistant/components/bond/__init__.py | 2 +- homeassistant/components/broadlink/device.py | 2 +- homeassistant/components/control4/__init__.py | 2 +- homeassistant/components/denonavr/__init__.py | 2 +- homeassistant/components/esphome/__init__.py | 7 ++++--- homeassistant/components/firmata/__init__.py | 2 +- .../components/homematicip_cloud/__init__.py | 11 ++++++----- .../components/homematicip_cloud/generic_entity.py | 10 +++++----- homeassistant/components/huawei_lte/__init__.py | 2 +- homeassistant/components/hue/__init__.py | 2 +- homeassistant/components/isy994/__init__.py | 7 ++++--- homeassistant/components/isy994/services.py | 5 +++-- homeassistant/components/konnected/panel.py | 2 +- homeassistant/components/lutron_caseta/__init__.py | 14 ++++++++------ homeassistant/components/mobile_app/__init__.py | 2 +- .../components/mobile_app/binary_sensor.py | 2 +- homeassistant/components/mobile_app/config_flow.py | 2 +- homeassistant/components/mobile_app/sensor.py | 2 +- homeassistant/components/mobile_app/webhook.py | 6 +++--- homeassistant/components/motion_blinds/__init__.py | 2 +- homeassistant/components/motioneye/__init__.py | 2 +- homeassistant/components/netgear/__init__.py | 2 +- homeassistant/components/nightscout/__init__.py | 2 +- homeassistant/components/notion/__init__.py | 14 ++++++++------ homeassistant/components/plugwise/gateway.py | 2 +- homeassistant/components/roon/__init__.py | 2 +- homeassistant/components/sia/__init__.py | 2 +- homeassistant/components/sia/hub.py | 7 ++++--- homeassistant/components/simplisafe/__init__.py | 9 ++++----- homeassistant/components/smarttub/controller.py | 8 +++++--- homeassistant/components/somfy/__init__.py | 2 +- homeassistant/components/syncthru/__init__.py | 2 +- homeassistant/components/toon/__init__.py | 2 +- homeassistant/components/upnp/__init__.py | 2 +- homeassistant/components/xiaomi_aqara/__init__.py | 2 +- homeassistant/components/xiaomi_miio/__init__.py | 2 +- 38 files changed, 84 insertions(+), 73 deletions(-) diff --git a/homeassistant/components/agent_dvr/__init__.py b/homeassistant/components/agent_dvr/__init__.py index 5b765da7f8e..bb464d09723 100644 --- a/homeassistant/components/agent_dvr/__init__.py +++ b/homeassistant/components/agent_dvr/__init__.py @@ -35,7 +35,7 @@ async def async_setup_entry(hass, config_entry): hass.data[AGENT_DOMAIN][config_entry.entry_id] = {CONNECTION: agent_client} - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, diff --git a/homeassistant/components/apple_tv/__init__.py b/homeassistant/components/apple_tv/__init__.py index fbf02fcfdff..b710a753da9 100644 --- a/homeassistant/components/apple_tv/__init__.py +++ b/homeassistant/components/apple_tv/__init__.py @@ -317,7 +317,7 @@ class AppleTVManager: self._dispatch_send(SIGNAL_CONNECTED, self.atv) self._address_updated(str(conf.address)) - await self._async_setup_device_registry() + self._async_setup_device_registry() self._connection_attempts = 0 if self._connection_was_lost: @@ -327,7 +327,8 @@ class AppleTVManager: ) self._connection_was_lost = False - async def _async_setup_device_registry(self): + @callback + def _async_setup_device_registry(self): attrs = { ATTR_IDENTIFIERS: {(DOMAIN, self.config_entry.unique_id)}, ATTR_MANUFACTURER: "Apple", @@ -351,7 +352,7 @@ class AppleTVManager: if dev_info.mac: attrs[ATTR_CONNECTIONS] = {(dr.CONNECTION_NETWORK_MAC, dev_info.mac)} - device_registry = await dr.async_get_registry(self.hass) + device_registry = dr.async_get(self.hass) device_registry.async_get_or_create( config_entry_id=self.config_entry.entry_id, **attrs ) diff --git a/homeassistant/components/bond/__init__.py b/homeassistant/components/bond/__init__.py index 20b6b0a2ea5..bf40d4c6066 100644 --- a/homeassistant/components/bond/__init__.py +++ b/homeassistant/components/bond/__init__.py @@ -69,7 +69,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: assert hub.bond_id is not None hub_name = hub.name or hub.bond_id - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=config_entry_id, identifiers={(DOMAIN, hub.bond_id)}, diff --git a/homeassistant/components/broadlink/device.py b/homeassistant/components/broadlink/device.py index 2686b3dd9ed..aada9ace84a 100644 --- a/homeassistant/components/broadlink/device.py +++ b/homeassistant/components/broadlink/device.py @@ -62,7 +62,7 @@ class BroadlinkDevice: Triggered when the device is renamed on the frontend. """ - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_entry = device_registry.async_get_device({(DOMAIN, entry.unique_id)}) device_registry.async_update_device(device_entry.id, name=entry.title) await hass.config_entries.async_reload(entry.entry_id) diff --git a/homeassistant/components/control4/__init__.py b/homeassistant/components/control4/__init__.py index e57abfa3b73..d593f759eb3 100644 --- a/homeassistant/components/control4/__init__.py +++ b/homeassistant/components/control4/__init__.py @@ -86,7 +86,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _, model, mac_address = controller_unique_id.split("_", 3) entry_data[CONF_DIRECTOR_MODEL] = model.upper() - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, controller_unique_id)}, diff --git a/homeassistant/components/denonavr/__init__.py b/homeassistant/components/denonavr/__init__.py index 818c005b1cd..75bd69cf2e3 100644 --- a/homeassistant/components/denonavr/__init__.py +++ b/homeassistant/components/denonavr/__init__.py @@ -72,7 +72,7 @@ async def async_unload_entry( hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]() # Remove zone2 and zone3 entities if needed - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) entries = er.async_entries_for_config_entry(entity_registry, config_entry.entry_id) unique_id = config_entry.unique_id or config_entry.entry_id zone2_id = f"{unique_id}-Zone2" diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index 97b459ae0cd..f985394c8e9 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -267,7 +267,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: assert cli.api_version is not None entry_data.api_version = cli.api_version entry_data.available = True - device_id = await _async_setup_device_registry( + device_id = _async_setup_device_registry( hass, entry, entry_data.device_info ) entry_data.async_update_device_state(hass) @@ -320,14 +320,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True -async def _async_setup_device_registry( +@callback +def _async_setup_device_registry( hass: HomeAssistant, entry: ConfigEntry, device_info: EsphomeDeviceInfo ) -> str: """Set up device registry feature for a particular config entry.""" sw_version = device_info.esphome_version if device_info.compilation_time: sw_version += f" ({device_info.compilation_time})" - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_entry = device_registry.async_get_or_create( config_entry_id=entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)}, diff --git a/homeassistant/components/firmata/__init__.py b/homeassistant/components/firmata/__init__.py index d98866f900b..d147d84b341 100644 --- a/homeassistant/components/firmata/__init__.py +++ b/homeassistant/components/firmata/__init__.py @@ -189,7 +189,7 @@ async def async_setup_entry( hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, handle_shutdown) ) - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, connections={}, diff --git a/homeassistant/components/homematicip_cloud/__init__.py b/homeassistant/components/homematicip_cloud/__init__.py index 14c80f56b1a..2f7d8d86012 100644 --- a/homeassistant/components/homematicip_cloud/__init__.py +++ b/homeassistant/components/homematicip_cloud/__init__.py @@ -4,7 +4,7 @@ import voluptuous as vol from homeassistant import config_entries from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry as dr, entity_registry as er import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_registry import async_entries_for_config_entry @@ -85,7 +85,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return False await async_setup_services(hass) - await async_remove_obsolete_entities(hass, entry, hap) + _async_remove_obsolete_entities(hass, entry, hap) # Register on HA stop event to gracefully shutdown HomematicIP Cloud connection hap.reset_connection_listener = hass.bus.async_listen_once( @@ -93,7 +93,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) # Register hap as device in registry. - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) home = hap.home hapname = home.label if home.label != entry.unique_id else f"Home-{home.label}" @@ -118,7 +118,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return await hap.async_reset() -async def async_remove_obsolete_entities( +@callback +def _async_remove_obsolete_entities( hass: HomeAssistant, entry: ConfigEntry, hap: HomematicipHAP ): """Remove obsolete entities from entity registry.""" @@ -126,7 +127,7 @@ async def async_remove_obsolete_entities( if hap.home.currentAPVersion < "2.2.12": return - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) er_entries = async_entries_for_config_entry(entity_registry, entry.entry_id) for er_entry in er_entries: if er_entry.unique_id.startswith("HomematicipAccesspointStatus"): diff --git a/homeassistant/components/homematicip_cloud/generic_entity.py b/homeassistant/components/homematicip_cloud/generic_entity.py index ecf0549d8b8..d3a3b1e34a4 100644 --- a/homeassistant/components/homematicip_cloud/generic_entity.py +++ b/homeassistant/components/homematicip_cloud/generic_entity.py @@ -139,13 +139,13 @@ class HomematicipGenericEntity(Entity): if self.hmip_device_removed: try: del self._hap.hmip_device_by_entity_id[self.entity_id] - await self.async_remove_from_registries() + self.async_remove_from_registries() except KeyError as err: _LOGGER.debug("Error removing HMIP device from registry: %s", err) - async def async_remove_from_registries(self) -> None: + @callback + def async_remove_from_registries(self) -> None: """Remove entity/device from registry.""" - # Remove callback from device. self._device.remove_callback(self._async_device_changed) self._device.remove_callback(self._async_device_removed) @@ -155,7 +155,7 @@ class HomematicipGenericEntity(Entity): if device_id := self.registry_entry.device_id: # Remove from device registry. - device_registry = await dr.async_get_registry(self.hass) + device_registry = dr.async_get(self.hass) if device_id in device_registry.devices: # This will also remove associated entities from entity registry. device_registry.async_remove_device(device_id) @@ -163,7 +163,7 @@ class HomematicipGenericEntity(Entity): # Remove from entity registry. # Only relevant for entities that do not belong to a device. if entity_id := self.registry_entry.entity_id: - entity_registry = await er.async_get_registry(self.hass) + entity_registry = er.async_get(self.hass) if entity_id in entity_registry.entities: entity_registry.async_remove(entity_id) diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index 1314344f48f..c159b6530fb 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -447,7 +447,7 @@ async def async_setup_entry( # noqa: C901 ) if sw_version: device_info[ATTR_SW_VERSION] = sw_version - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, **device_info, diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index 71b62e22d33..8e0f194e904 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -100,7 +100,7 @@ async def async_setup_entry( hass.async_create_task(hass.config_entries.async_remove(entry.entry_id)) return False - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, config.mac)}, diff --git a/homeassistant/components/isy994/__init__.py b/homeassistant/components/isy994/__init__.py index 65be6a74c19..9250b567d1b 100644 --- a/homeassistant/components/isy994/__init__.py +++ b/homeassistant/components/isy994/__init__.py @@ -200,7 +200,7 @@ async def async_setup_entry( _LOGGER.info(repr(isy.clock)) hass_isy_data[ISY994_ISY] = isy - await _async_get_or_create_isy_device_in_registry(hass, entry, isy) + _async_get_or_create_isy_device_in_registry(hass, entry, isy) # Load platforms for the devices in the ISY controller that we support. hass.config_entries.async_setup_platforms(entry, PLATFORMS) @@ -259,10 +259,11 @@ def _async_isy_to_configuration_url(isy: ISY) -> str: return f"{proto}://{connection_info['addr']}:{connection_info['port']}" -async def _async_get_or_create_isy_device_in_registry( +@callback +def _async_get_or_create_isy_device_in_registry( hass: HomeAssistant, entry: config_entries.ConfigEntry, isy ) -> None: - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) url = _async_isy_to_configuration_url(isy) device_registry.async_get_or_create( config_entry_id=entry.entry_id, diff --git a/homeassistant/components/isy994/services.py b/homeassistant/components/isy994/services.py index c34e8a1c67b..5b18d6cd33a 100644 --- a/homeassistant/components/isy994/services.py +++ b/homeassistant/components/isy994/services.py @@ -274,9 +274,10 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 return _LOGGER.error("Could not set variable value; not found or enabled on the ISY") - async def async_cleanup_registry_entries(service) -> None: + @callback + def async_cleanup_registry_entries(service) -> None: """Remove extra entities that are no longer part of the integration.""" - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) config_ids = [] current_unique_ids = [] diff --git a/homeassistant/components/konnected/panel.py b/homeassistant/components/konnected/panel.py index 137fdada8c5..a9999df3bc0 100644 --- a/homeassistant/components/konnected/panel.py +++ b/homeassistant/components/konnected/panel.py @@ -151,7 +151,7 @@ class AlarmPanel: self.port, ) - device_registry = await dr.async_get_registry(self.hass) + device_registry = dr.async_get(self.hass) device_registry.async_get_or_create( config_entry_id=self.config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, self.status.get("mac"))}, diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index 786e21f2d0b..0d6c29047a9 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -123,7 +123,7 @@ async def async_setup_entry(hass, config_entry): devices = bridge.get_devices() bridge_device = devices[BRIDGE_DEVICE_ID] - await _async_register_bridge_device(hass, config_entry.entry_id, bridge_device) + _async_register_bridge_device(hass, config_entry.entry_id, bridge_device) # Store this bridge (keyed by entry_id) so it can be retrieved by the # platforms we're setting up. hass.data[DOMAIN][config_entry.entry_id] = { @@ -164,7 +164,7 @@ async def async_setup_lip(hass, config_entry, lip_devices): _LOGGER.debug("Connected to Lutron Caseta bridge via LIP at %s:23", host) button_devices_by_lip_id = _async_merge_lip_leap_data(lip_devices, bridge) - button_devices_by_dr_id = await _async_register_button_devices( + button_devices_by_dr_id = _async_register_button_devices( hass, config_entry_id, bridge_device, button_devices_by_lip_id ) _async_subscribe_pico_remote_events(hass, lip, button_devices_by_lip_id) @@ -200,9 +200,10 @@ def _async_merge_lip_leap_data(lip_devices, bridge): return button_devices_by_id -async def _async_register_bridge_device(hass, config_entry_id, bridge_device): +@callback +def _async_register_bridge_device(hass, config_entry_id, bridge_device): """Register the bridge device in the device registry.""" - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( name=bridge_device["name"], manufacturer=MANUFACTURER, @@ -212,11 +213,12 @@ async def _async_register_bridge_device(hass, config_entry_id, bridge_device): ) -async def _async_register_button_devices( +@callback +def _async_register_button_devices( hass, config_entry_id, bridge_device, button_devices_by_id ): """Register button devices (Pico Remotes) in the device registry.""" - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) button_devices_by_dr_id = {} for device in button_devices_by_id.values(): diff --git a/homeassistant/components/mobile_app/__init__.py b/homeassistant/components/mobile_app/__init__.py index 73775f23e6d..47e21d53515 100644 --- a/homeassistant/components/mobile_app/__init__.py +++ b/homeassistant/components/mobile_app/__init__.py @@ -77,7 +77,7 @@ async def async_setup_entry(hass, entry): hass.data[DOMAIN][DATA_CONFIG_ENTRIES][webhook_id] = entry - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device = device_registry.async_get_or_create( config_entry_id=entry.entry_id, diff --git a/homeassistant/components/mobile_app/binary_sensor.py b/homeassistant/components/mobile_app/binary_sensor.py index 616cd97a775..94bcd3b1c0d 100644 --- a/homeassistant/components/mobile_app/binary_sensor.py +++ b/homeassistant/components/mobile_app/binary_sensor.py @@ -27,7 +27,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): webhook_id = config_entry.data[CONF_WEBHOOK_ID] - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) entries = er.async_entries_for_config_entry(entity_registry, config_entry.entry_id) for entry in entries: if entry.domain != ENTITY_TYPE or entry.disabled_by: diff --git a/homeassistant/components/mobile_app/config_flow.py b/homeassistant/components/mobile_app/config_flow.py index e8efbd92898..246c433672b 100644 --- a/homeassistant/components/mobile_app/config_flow.py +++ b/homeassistant/components/mobile_app/config_flow.py @@ -35,7 +35,7 @@ class MobileAppFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): user_input[ATTR_DEVICE_ID] = str(uuid.uuid4()).replace("-", "") # Register device tracker entity and add to person registering app - entity_registry = await er.async_get_registry(self.hass) + entity_registry = er.async_get(self.hass) devt_entry = entity_registry.async_get_or_create( "device_tracker", DOMAIN, diff --git a/homeassistant/components/mobile_app/sensor.py b/homeassistant/components/mobile_app/sensor.py index 9d56e55a106..533e33e84bb 100644 --- a/homeassistant/components/mobile_app/sensor.py +++ b/homeassistant/components/mobile_app/sensor.py @@ -31,7 +31,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): webhook_id = config_entry.data[CONF_WEBHOOK_ID] - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) entries = er.async_entries_for_config_entry(entity_registry, config_entry.entry_id) for entry in entries: if entry.domain != ENTITY_TYPE or entry.disabled_by: diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py index 7d8b6ad4b53..9a0d391373c 100644 --- a/homeassistant/components/mobile_app/webhook.py +++ b/homeassistant/components/mobile_app/webhook.py @@ -344,7 +344,7 @@ async def webhook_update_registration(hass, config_entry, data): """Handle an update registration webhook.""" new_registration = {**config_entry.data, **data} - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -433,7 +433,7 @@ async def webhook_register_sensor(hass, config_entry, data): device_name = config_entry.data[ATTR_DEVICE_NAME] unique_store_key = f"{config_entry.data[CONF_WEBHOOK_ID]}_{unique_id}" - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) existing_sensor = entity_registry.async_get_entity_id( entity_type, DOMAIN, unique_store_key ) @@ -498,7 +498,7 @@ async def webhook_update_sensor_states(hass, config_entry, data): unique_store_key = f"{config_entry.data[CONF_WEBHOOK_ID]}_{unique_id}" - entity_registry = await er.async_get_registry(hass) + entity_registry = er.async_get(hass) if not entity_registry.async_get_entity_id( entity_type, DOMAIN, unique_store_key ): diff --git a/homeassistant/components/motion_blinds/__init__.py b/homeassistant/components/motion_blinds/__init__.py index 14bdeae817b..904e5cecbbe 100644 --- a/homeassistant/components/motion_blinds/__init__.py +++ b/homeassistant/components/motion_blinds/__init__.py @@ -157,7 +157,7 @@ async def async_setup_entry( else: version = f"Protocol: {motion_gateway.protocol}" - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, motion_gateway.mac)}, diff --git a/homeassistant/components/motioneye/__init__.py b/homeassistant/components/motioneye/__init__.py index ec501f9f112..56c95115cb9 100644 --- a/homeassistant/components/motioneye/__init__.py +++ b/homeassistant/components/motioneye/__init__.py @@ -325,7 +325,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: } current_cameras: set[tuple[str, str]] = set() - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) @callback def _async_process_motioneye_cameras() -> None: diff --git a/homeassistant/components/netgear/__init__.py b/homeassistant/components/netgear/__init__.py index 301fb780c1b..657e7e06880 100644 --- a/homeassistant/components/netgear/__init__.py +++ b/homeassistant/components/netgear/__init__.py @@ -23,7 +23,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool entry.async_on_unload(entry.add_update_listener(update_listener)) - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, entry.unique_id)}, diff --git a/homeassistant/components/nightscout/__init__.py b/homeassistant/components/nightscout/__init__.py index 69d79d1cecb..6bf1a7f1929 100644 --- a/homeassistant/components/nightscout/__init__.py +++ b/homeassistant/components/nightscout/__init__.py @@ -32,7 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = api - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, server_url)}, diff --git a/homeassistant/components/notion/__init__.py b/homeassistant/components/notion/__init__.py index 74fd2b90117..d06827ffd7d 100644 --- a/homeassistant/components/notion/__init__.py +++ b/homeassistant/components/notion/__init__.py @@ -85,7 +85,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: for item in result: if attr == "bridges" and item["id"] not in data["bridges"]: # If a new bridge is discovered, register it: - hass.async_create_task(async_register_new_bridge(hass, item, entry)) + _async_register_new_bridge(hass, item, entry) data[attr][item["id"]] = item return data @@ -115,11 +115,12 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return unload_ok -async def async_register_new_bridge( +@callback +def _async_register_new_bridge( hass: HomeAssistant, bridge: dict, entry: ConfigEntry ) -> None: """Register a new bridge.""" - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, bridge["hardware_id"])}, @@ -175,7 +176,8 @@ class NotionEntity(CoordinatorEntity): and self._task_id in self.coordinator.data["tasks"] ) - async def _async_update_bridge_id(self) -> None: + @callback + def _async_update_bridge_id(self) -> None: """Update the entity's bridge ID if it has changed. Sensors can move to other bridges based on signal strength, etc. @@ -193,7 +195,7 @@ class NotionEntity(CoordinatorEntity): self._bridge_id = sensor["bridge"]["id"] - device_registry = await dr.async_get_registry(self.hass) + device_registry = dr.async_get(self.hass) this_device = device_registry.async_get_device( {(DOMAIN, sensor["hardware_id"])} ) @@ -218,7 +220,7 @@ class NotionEntity(CoordinatorEntity): def _handle_coordinator_update(self) -> None: """Respond to a DataUpdateCoordinator update.""" if self._task_id in self.coordinator.data["tasks"]: - self.hass.async_create_task(self._async_update_bridge_id()) + self._async_update_bridge_id() self._async_update_from_latest_data() self.async_write_ha_state() diff --git a/homeassistant/components/plugwise/gateway.py b/homeassistant/components/plugwise/gateway.py index 05d8925aeb0..8cf007ca82c 100644 --- a/homeassistant/components/plugwise/gateway.py +++ b/homeassistant/components/plugwise/gateway.py @@ -123,7 +123,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool: UNDO_UPDATE_LISTENER: undo_listener, } - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, api.gateway_id)}, diff --git a/homeassistant/components/roon/__init__.py b/homeassistant/components/roon/__init__.py index c9dbe86ee4b..94c51abf705 100644 --- a/homeassistant/components/roon/__init__.py +++ b/homeassistant/components/roon/__init__.py @@ -16,7 +16,7 @@ async def async_setup_entry(hass, entry): return False hass.data[DOMAIN][entry.entry_id] = roonserver - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, entry.entry_id)}, diff --git a/homeassistant/components/sia/__init__.py b/homeassistant/components/sia/__init__.py index 9bca9a5f5b2..dbbb12f29ce 100644 --- a/homeassistant/components/sia/__init__.py +++ b/homeassistant/components/sia/__init__.py @@ -11,7 +11,7 @@ from .hub import SIAHub async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up sia from a config entry.""" hub: SIAHub = SIAHub(hass, entry) - await hub.async_setup_hub() + hub.async_setup_hub() hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = hub diff --git a/homeassistant/components/sia/hub.py b/homeassistant/components/sia/hub.py index 387c2273606..7db432256f9 100644 --- a/homeassistant/components/sia/hub.py +++ b/homeassistant/components/sia/hub.py @@ -9,7 +9,7 @@ from pysiaalarm.aio import CommunicationsProtocol, SIAAccount, SIAClient, SIAEve from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PORT, CONF_PROTOCOL, EVENT_HOMEASSISTANT_STOP -from homeassistant.core import Event, HomeAssistant +from homeassistant.core import Event, HomeAssistant, callback from homeassistant.helpers import device_registry as dr from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -50,10 +50,11 @@ class SIAHub: self.sia_accounts: list[SIAAccount] | None = None self.sia_client: SIAClient = None - async def async_setup_hub(self) -> None: + @callback + def async_setup_hub(self) -> None: """Add a device to the device_registry, register shutdown listener, load reactions.""" self.update_accounts() - device_registry = await dr.async_get_registry(self._hass) + device_registry = dr.async_get(self._hass) for acc in self._accounts: account = acc[CONF_ACCOUNT] device_registry.async_get_or_create( diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index ae5c3cd9527..ddaf70cc071 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -201,11 +201,12 @@ def _async_standardize_config_entry(hass: HomeAssistant, entry: ConfigEntry) -> hass.config_entries.async_update_entry(entry, **entry_updates) -async def async_register_base_station( +@callback +def _async_register_base_station( hass: HomeAssistant, entry: ConfigEntry, system: SystemV2 | SystemV3 ) -> None: """Register a new bridge.""" - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, system.system_id)}, @@ -473,9 +474,7 @@ class SimpliSafe: for system in self.systems.values(): self._system_notifications[system.system_id] = set() - self._hass.async_create_task( - async_register_base_station(self._hass, self.entry, system) - ) + _async_register_base_station(self._hass, self.entry, system) # Future events will come from the websocket, but since subscription to the # websocket doesn't provide the most recent event, we grab it from the REST diff --git a/homeassistant/components/smarttub/controller.py b/homeassistant/components/smarttub/controller.py index adb7f3bf720..e62819f122c 100644 --- a/homeassistant/components/smarttub/controller.py +++ b/homeassistant/components/smarttub/controller.py @@ -10,6 +10,7 @@ from smarttub import APIError, LoginFailed, SmartTub from smarttub.api import Account from homeassistant.const import CONF_EMAIL, CONF_PASSWORD +from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -75,7 +76,7 @@ class SmartTubController: await self.coordinator.async_refresh() - await self.async_register_devices(entry) + self.async_register_devices(entry) return True @@ -107,9 +108,10 @@ class SmartTubController: ATTR_ERRORS: errors, } - async def async_register_devices(self, entry): + @callback + def async_register_devices(self, entry): """Register devices with the device registry for all spas.""" - device_registry = await dr.async_get_registry(self._hass) + device_registry = dr.async_get(self._hass) for spa in self.spas: device_registry.async_get_or_create( config_entry_id=entry.entry_id, diff --git a/homeassistant/components/somfy/__init__.py b/homeassistant/components/somfy/__init__.py index 5efd4bfaa3a..a6bd320edd6 100644 --- a/homeassistant/components/somfy/__init__.py +++ b/homeassistant/components/somfy/__init__.py @@ -97,7 +97,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) coordinator.update_interval = SCAN_INTERVAL_ALL_ASSUMED_STATE - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) hubs = [ device diff --git a/homeassistant/components/syncthru/__init__.py b/homeassistant/components/syncthru/__init__.py index ef3e8c4419d..da45350836c 100644 --- a/homeassistant/components/syncthru/__init__.py +++ b/homeassistant/components/syncthru/__init__.py @@ -66,7 +66,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # and the config should simply be discarded return False - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, connections=device_connections(printer), diff --git a/homeassistant/components/toon/__init__.py b/homeassistant/components/toon/__init__.py index f05c480aede..372eeb47096 100644 --- a/homeassistant/components/toon/__init__.py +++ b/homeassistant/components/toon/__init__.py @@ -102,7 +102,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data[DOMAIN][entry.entry_id] = coordinator # Register device for the Meter Adapter, since it will have no entities. - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={ diff --git a/homeassistant/components/upnp/__init__.py b/homeassistant/components/upnp/__init__.py index 3982296b419..36b6278d968 100644 --- a/homeassistant/components/upnp/__init__.py +++ b/homeassistant/components/upnp/__init__.py @@ -153,7 +153,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) # Create device registry entry. - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, connections={(dr.CONNECTION_UPNP, device.udn)}, diff --git a/homeassistant/components/xiaomi_aqara/__init__.py b/homeassistant/components/xiaomi_aqara/__init__.py index b365dbb1bee..7aff6ece0e1 100644 --- a/homeassistant/components/xiaomi_aqara/__init__.py +++ b/homeassistant/components/xiaomi_aqara/__init__.py @@ -172,7 +172,7 @@ async def async_setup_entry( entry.data[CONF_HOST], ) - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, entry.unique_id)}, diff --git a/homeassistant/components/xiaomi_miio/__init__.py b/homeassistant/components/xiaomi_miio/__init__.py index de5baf69683..5513485f51e 100644 --- a/homeassistant/components/xiaomi_miio/__init__.py +++ b/homeassistant/components/xiaomi_miio/__init__.py @@ -377,7 +377,7 @@ async def async_setup_gateway_entry( gateway_model = f"{gateway_info.model}-{gateway_info.hardware_version}" - device_registry = await dr.async_get_registry(hass) + device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, gateway_info.mac_address)},