From 25f4f2d86eb0eee8e456dd6311a90bcb6d76634d Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Wed, 20 Oct 2021 11:16:28 +0200 Subject: [PATCH] Don't use deprecated methods of retrieving registries in deCONZ (#58081) --- homeassistant/components/deconz/deconz_event.py | 5 ++--- homeassistant/components/deconz/device_trigger.py | 7 ++++--- homeassistant/components/deconz/gateway.py | 10 +++++++--- homeassistant/components/deconz/services.py | 14 +++++++------- homeassistant/components/deconz/switch.py | 3 ++- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/deconz/deconz_event.py b/homeassistant/components/deconz/deconz_event.py index b04e393103f..a0470c8ac32 100644 --- a/homeassistant/components/deconz/deconz_event.py +++ b/homeassistant/components/deconz/deconz_event.py @@ -17,6 +17,7 @@ from homeassistant.const import ( CONF_XY, ) from homeassistant.core import callback +from homeassistant.helpers import device_registry as dr from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.util import slugify @@ -142,9 +143,7 @@ class DeconzEvent(DeconzBase): if not self.device_info: return - device_registry = ( - await self.gateway.hass.helpers.device_registry.async_get_registry() - ) + device_registry = dr.async_get(self.gateway.hass) entry = device_registry.async_get_or_create( config_entry_id=self.gateway.config_entry.entry_id, **self.device_info diff --git a/homeassistant/components/deconz/device_trigger.py b/homeassistant/components/deconz/device_trigger.py index 8234ed81aed..d1abbed0928 100644 --- a/homeassistant/components/deconz/device_trigger.py +++ b/homeassistant/components/deconz/device_trigger.py @@ -14,6 +14,7 @@ from homeassistant.const import ( CONF_TYPE, CONF_UNIQUE_ID, ) +from homeassistant.helpers import device_registry as dr from . import DOMAIN from .deconz_event import CONF_DECONZ_EVENT, CONF_GESTURE @@ -628,7 +629,7 @@ async def async_validate_trigger_config(hass, config): """Validate config.""" config = TRIGGER_SCHEMA(config) - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(config[CONF_DEVICE_ID]) trigger = (config[CONF_TYPE], config[CONF_SUBTYPE]) @@ -650,7 +651,7 @@ async def async_validate_trigger_config(hass, config): async def async_attach_trigger(hass, config, action, automation_info): """Listen for state changes based on configuration.""" - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(config[CONF_DEVICE_ID]) trigger = (config[CONF_TYPE], config[CONF_SUBTYPE]) @@ -684,7 +685,7 @@ async def async_get_triggers(hass, device_id): Retrieve the deconz event object matching device entry. Generate device trigger list. """ - device_registry = await hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(hass) device = device_registry.async_get(device_id) if device.model not in REMOTES: diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index 17c927b300e..6096edabb37 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -7,7 +7,11 @@ from pydeconz import DeconzSession, errors, group, light, sensor from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady -from homeassistant.helpers import aiohttp_client +from homeassistant.helpers import ( + aiohttp_client, + device_registry as dr, + entity_registry as er, +) from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -136,7 +140,7 @@ class DeconzGateway: async def async_update_device_registry(self) -> None: """Update device registry.""" - device_registry = await self.hass.helpers.device_registry.async_get_registry() + device_registry = dr.async_get(self.hass) # Host device device_registry.async_get_or_create( @@ -218,7 +222,7 @@ class DeconzGateway: else: deconz_ids += [group.deconz_id for group in self.api.groups.values()] - entity_registry = await self.hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(self.hass) for entity_id, deconz_id in self.deconz_ids.items(): if deconz_id in deconz_ids and entity_registry.async_is_registered( diff --git a/homeassistant/components/deconz/services.py b/homeassistant/components/deconz/services.py index 88006a851f2..535dd9807fb 100644 --- a/homeassistant/components/deconz/services.py +++ b/homeassistant/components/deconz/services.py @@ -1,12 +1,14 @@ """deCONZ services.""" -import asyncio - from pydeconz.utils import normalize_bridge_id import voluptuous as vol from homeassistant.core import callback -from homeassistant.helpers import config_validation as cv +from homeassistant.helpers import ( + config_validation as cv, + device_registry as dr, + entity_registry as er, +) from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.entity_registry import ( async_entries_for_config_entry, @@ -143,10 +145,8 @@ async def async_refresh_devices_service(gateway): async def async_remove_orphaned_entries_service(gateway): """Remove orphaned deCONZ entries from device and entity registries.""" - device_registry, entity_registry = await asyncio.gather( - gateway.hass.helpers.device_registry.async_get_registry(), - gateway.hass.helpers.entity_registry.async_get_registry(), - ) + device_registry = dr.async_get(gateway.hass) + entity_registry = er.async_get(gateway.hass) entity_entries = async_entries_for_config_entry( entity_registry, gateway.config_entry.entry_id diff --git a/homeassistant/components/deconz/switch.py b/homeassistant/components/deconz/switch.py index a00def33b72..39489fe1fc3 100644 --- a/homeassistant/components/deconz/switch.py +++ b/homeassistant/components/deconz/switch.py @@ -4,6 +4,7 @@ from pydeconz.light import Siren from homeassistant.components.switch import DOMAIN, SwitchEntity from homeassistant.core import callback +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_connect from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS @@ -19,7 +20,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): gateway = get_gateway_from_config_entry(hass, config_entry) gateway.entities[DOMAIN] = set() - entity_registry = await hass.helpers.entity_registry.async_get_registry() + entity_registry = er.async_get(hass) # Siren platform replacing sirens in switch platform added in 2021.10 for light in gateway.api.lights.values():