mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Don't use deprecated methods of retrieving registries in deCONZ (#58081)
This commit is contained in:
parent
b8cf6513d9
commit
25f4f2d86e
@ -17,6 +17,7 @@ from homeassistant.const import (
|
|||||||
CONF_XY,
|
CONF_XY,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
@ -142,9 +143,7 @@ class DeconzEvent(DeconzBase):
|
|||||||
if not self.device_info:
|
if not self.device_info:
|
||||||
return
|
return
|
||||||
|
|
||||||
device_registry = (
|
device_registry = dr.async_get(self.gateway.hass)
|
||||||
await self.gateway.hass.helpers.device_registry.async_get_registry()
|
|
||||||
)
|
|
||||||
|
|
||||||
entry = device_registry.async_get_or_create(
|
entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=self.gateway.config_entry.entry_id, **self.device_info
|
config_entry_id=self.gateway.config_entry.entry_id, **self.device_info
|
||||||
|
@ -14,6 +14,7 @@ from homeassistant.const import (
|
|||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
CONF_UNIQUE_ID,
|
CONF_UNIQUE_ID,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from . import DOMAIN
|
from . import DOMAIN
|
||||||
from .deconz_event import CONF_DECONZ_EVENT, CONF_GESTURE
|
from .deconz_event import CONF_DECONZ_EVENT, CONF_GESTURE
|
||||||
@ -628,7 +629,7 @@ async def async_validate_trigger_config(hass, config):
|
|||||||
"""Validate config."""
|
"""Validate config."""
|
||||||
config = TRIGGER_SCHEMA(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])
|
device = device_registry.async_get(config[CONF_DEVICE_ID])
|
||||||
|
|
||||||
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
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):
|
async def async_attach_trigger(hass, config, action, automation_info):
|
||||||
"""Listen for state changes based on configuration."""
|
"""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])
|
device = device_registry.async_get(config[CONF_DEVICE_ID])
|
||||||
|
|
||||||
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
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.
|
Retrieve the deconz event object matching device entry.
|
||||||
Generate device trigger list.
|
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)
|
device = device_registry.async_get(device_id)
|
||||||
|
|
||||||
if device.model not in REMOTES:
|
if device.model not in REMOTES:
|
||||||
|
@ -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.const import CONF_API_KEY, CONF_HOST, CONF_PORT
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
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.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
|
||||||
@ -136,7 +140,7 @@ class DeconzGateway:
|
|||||||
|
|
||||||
async def async_update_device_registry(self) -> None:
|
async def async_update_device_registry(self) -> None:
|
||||||
"""Update device registry."""
|
"""Update device registry."""
|
||||||
device_registry = await self.hass.helpers.device_registry.async_get_registry()
|
device_registry = dr.async_get(self.hass)
|
||||||
|
|
||||||
# Host device
|
# Host device
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
@ -218,7 +222,7 @@ class DeconzGateway:
|
|||||||
else:
|
else:
|
||||||
deconz_ids += [group.deconz_id for group in self.api.groups.values()]
|
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():
|
for entity_id, deconz_id in self.deconz_ids.items():
|
||||||
if deconz_id in deconz_ids and entity_registry.async_is_registered(
|
if deconz_id in deconz_ids and entity_registry.async_is_registered(
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
"""deCONZ services."""
|
"""deCONZ services."""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from pydeconz.utils import normalize_bridge_id
|
from pydeconz.utils import normalize_bridge_id
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.core import callback
|
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.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.entity_registry import (
|
from homeassistant.helpers.entity_registry import (
|
||||||
async_entries_for_config_entry,
|
async_entries_for_config_entry,
|
||||||
@ -143,10 +145,8 @@ async def async_refresh_devices_service(gateway):
|
|||||||
|
|
||||||
async def async_remove_orphaned_entries_service(gateway):
|
async def async_remove_orphaned_entries_service(gateway):
|
||||||
"""Remove orphaned deCONZ entries from device and entity registries."""
|
"""Remove orphaned deCONZ entries from device and entity registries."""
|
||||||
device_registry, entity_registry = await asyncio.gather(
|
device_registry = dr.async_get(gateway.hass)
|
||||||
gateway.hass.helpers.device_registry.async_get_registry(),
|
entity_registry = er.async_get(gateway.hass)
|
||||||
gateway.hass.helpers.entity_registry.async_get_registry(),
|
|
||||||
)
|
|
||||||
|
|
||||||
entity_entries = async_entries_for_config_entry(
|
entity_entries = async_entries_for_config_entry(
|
||||||
entity_registry, gateway.config_entry.entry_id
|
entity_registry, gateway.config_entry.entry_id
|
||||||
|
@ -4,6 +4,7 @@ from pydeconz.light import Siren
|
|||||||
|
|
||||||
from homeassistant.components.switch import DOMAIN, SwitchEntity
|
from homeassistant.components.switch import DOMAIN, SwitchEntity
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
|
||||||
from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS
|
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 = get_gateway_from_config_entry(hass, config_entry)
|
||||||
gateway.entities[DOMAIN] = set()
|
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
|
# Siren platform replacing sirens in switch platform added in 2021.10
|
||||||
for light in gateway.api.lights.values():
|
for light in gateway.api.lights.values():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user