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