Cleanup deprecated async_get_registry in core (#72087)
This commit is contained in:
parent
bd78eec732
commit
50ca14538a
5 changed files with 40 additions and 36 deletions
|
@ -12,12 +12,12 @@ from homeassistant.const import (
|
|||
CONF_TYPE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import condition, config_validation as cv
|
||||
from homeassistant.helpers.entity import get_device_class
|
||||
from homeassistant.helpers.entity_registry import (
|
||||
async_entries_for_device,
|
||||
async_get_registry,
|
||||
from homeassistant.helpers import (
|
||||
condition,
|
||||
config_validation as cv,
|
||||
entity_registry as er,
|
||||
)
|
||||
from homeassistant.helpers.entity import get_device_class
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import DOMAIN, BinarySensorDeviceClass
|
||||
|
@ -268,10 +268,10 @@ async def async_get_conditions(
|
|||
) -> list[dict[str, str]]:
|
||||
"""List device conditions."""
|
||||
conditions: list[dict[str, str]] = []
|
||||
entity_registry = await async_get_registry(hass)
|
||||
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
|
||||
]
|
||||
|
||||
|
|
|
@ -30,9 +30,12 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_per_platform, discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_registry import async_get_registry
|
||||
from homeassistant.helpers import (
|
||||
config_per_platform,
|
||||
config_validation as cv,
|
||||
discovery,
|
||||
entity_registry as er,
|
||||
)
|
||||
from homeassistant.helpers.event import (
|
||||
async_track_time_interval,
|
||||
async_track_utc_time_change,
|
||||
|
@ -487,7 +490,7 @@ class DeviceTracker:
|
|||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
registry = await async_get_registry(self.hass)
|
||||
registry = er.async_get(self.hass)
|
||||
if mac is None and dev_id is None:
|
||||
raise HomeAssistantError("Neither mac or device id passed in")
|
||||
if mac is not None:
|
||||
|
|
|
@ -33,13 +33,12 @@ from homeassistant.core import (
|
|||
callback,
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv, recorder
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.device_registry import (
|
||||
DeviceEntryType,
|
||||
DeviceRegistry,
|
||||
async_get_registry,
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
device_registry as dr,
|
||||
recorder,
|
||||
)
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
from homeassistant.helpers.storage import Store
|
||||
|
@ -715,7 +714,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
dev_reg = await async_get_registry(hass)
|
||||
dev_reg = dr.async_get(hass)
|
||||
coordinator = HassioDataUpdateCoordinator(hass, entry, dev_reg)
|
||||
hass.data[ADDONS_COORDINATOR] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
@ -737,7 +736,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
@callback
|
||||
def async_register_addons_in_dev_reg(
|
||||
entry_id: str, dev_reg: DeviceRegistry, addons: list[dict[str, Any]]
|
||||
entry_id: str, dev_reg: dr.DeviceRegistry, addons: list[dict[str, Any]]
|
||||
) -> None:
|
||||
"""Register addons in the device registry."""
|
||||
for addon in addons:
|
||||
|
@ -746,7 +745,7 @@ def async_register_addons_in_dev_reg(
|
|||
model=SupervisorEntityModel.ADDON,
|
||||
sw_version=addon[ATTR_VERSION],
|
||||
name=addon[ATTR_NAME],
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
entry_type=dr.DeviceEntryType.SERVICE,
|
||||
configuration_url=f"homeassistant://hassio/addon/{addon[ATTR_SLUG]}",
|
||||
)
|
||||
if manufacturer := addon.get(ATTR_REPOSITORY) or addon.get(ATTR_URL):
|
||||
|
@ -756,7 +755,7 @@ def async_register_addons_in_dev_reg(
|
|||
|
||||
@callback
|
||||
def async_register_os_in_dev_reg(
|
||||
entry_id: str, dev_reg: DeviceRegistry, os_dict: dict[str, Any]
|
||||
entry_id: str, dev_reg: dr.DeviceRegistry, os_dict: dict[str, Any]
|
||||
) -> None:
|
||||
"""Register OS in the device registry."""
|
||||
params = DeviceInfo(
|
||||
|
@ -765,7 +764,7 @@ def async_register_os_in_dev_reg(
|
|||
model=SupervisorEntityModel.OS,
|
||||
sw_version=os_dict[ATTR_VERSION],
|
||||
name="Home Assistant Operating System",
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
entry_type=dr.DeviceEntryType.SERVICE,
|
||||
)
|
||||
dev_reg.async_get_or_create(config_entry_id=entry_id, **params)
|
||||
|
||||
|
@ -773,7 +772,7 @@ def async_register_os_in_dev_reg(
|
|||
@callback
|
||||
def async_register_core_in_dev_reg(
|
||||
entry_id: str,
|
||||
dev_reg: DeviceRegistry,
|
||||
dev_reg: dr.DeviceRegistry,
|
||||
core_dict: dict[str, Any],
|
||||
) -> None:
|
||||
"""Register OS in the device registry."""
|
||||
|
@ -783,7 +782,7 @@ def async_register_core_in_dev_reg(
|
|||
model=SupervisorEntityModel.CORE,
|
||||
sw_version=core_dict[ATTR_VERSION],
|
||||
name="Home Assistant Core",
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
entry_type=dr.DeviceEntryType.SERVICE,
|
||||
)
|
||||
dev_reg.async_get_or_create(config_entry_id=entry_id, **params)
|
||||
|
||||
|
@ -791,7 +790,7 @@ def async_register_core_in_dev_reg(
|
|||
@callback
|
||||
def async_register_supervisor_in_dev_reg(
|
||||
entry_id: str,
|
||||
dev_reg: DeviceRegistry,
|
||||
dev_reg: dr.DeviceRegistry,
|
||||
supervisor_dict: dict[str, Any],
|
||||
) -> None:
|
||||
"""Register OS in the device registry."""
|
||||
|
@ -801,13 +800,15 @@ def async_register_supervisor_in_dev_reg(
|
|||
model=SupervisorEntityModel.SUPERVIOSR,
|
||||
sw_version=supervisor_dict[ATTR_VERSION],
|
||||
name="Home Assistant Supervisor",
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
entry_type=dr.DeviceEntryType.SERVICE,
|
||||
)
|
||||
dev_reg.async_get_or_create(config_entry_id=entry_id, **params)
|
||||
|
||||
|
||||
@callback
|
||||
def async_remove_addons_from_dev_reg(dev_reg: DeviceRegistry, addons: set[str]) -> None:
|
||||
def async_remove_addons_from_dev_reg(
|
||||
dev_reg: dr.DeviceRegistry, addons: set[str]
|
||||
) -> None:
|
||||
"""Remove addons from the device registry."""
|
||||
for addon_slug in addons:
|
||||
if dev := dev_reg.async_get_device({(DOMAIN, addon_slug)}):
|
||||
|
@ -818,7 +819,7 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator):
|
|||
"""Class to retrieve Hass.io status."""
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry: ConfigEntry, dev_reg: DeviceRegistry
|
||||
self, hass: HomeAssistant, config_entry: ConfigEntry, dev_reg: dr.DeviceRegistry
|
||||
) -> None:
|
||||
"""Initialize coordinator."""
|
||||
super().__init__(
|
||||
|
|
|
@ -15,16 +15,16 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import condition, config_validation as cv
|
||||
from homeassistant.helpers import (
|
||||
condition,
|
||||
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,
|
||||
async_get_registry,
|
||||
)
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
|
||||
|
@ -141,10 +141,10 @@ async def async_get_conditions(
|
|||
) -> list[dict[str, str]]:
|
||||
"""List device conditions."""
|
||||
conditions: list[dict[str, str]] = []
|
||||
entity_registry = await async_get_registry(hass)
|
||||
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
|
||||
]
|
||||
|
||||
|
|
|
@ -995,7 +995,7 @@ async def async_migrate_entries(
|
|||
entry_callback: Callable[[RegistryEntry], dict[str, Any] | None],
|
||||
) -> None:
|
||||
"""Migrator of unique IDs."""
|
||||
ent_reg = await async_get_registry(hass)
|
||||
ent_reg = async_get(hass)
|
||||
|
||||
for entry in ent_reg.entities.values():
|
||||
if entry.config_entry_id != config_entry_id:
|
||||
|
|
Loading…
Add table
Reference in a new issue