mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Get the registry using the callback method (#58542)
This commit is contained in:
parent
b34eb53914
commit
e1e864d2b6
@ -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,
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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)},
|
||||
|
@ -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)
|
||||
|
@ -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)},
|
||||
|
@ -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"
|
||||
|
@ -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)},
|
||||
|
@ -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={},
|
||||
|
@ -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"):
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)},
|
||||
|
@ -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,
|
||||
|
@ -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 = []
|
||||
|
||||
|
@ -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"))},
|
||||
|
@ -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():
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
):
|
||||
|
@ -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)},
|
||||
|
@ -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:
|
||||
|
@ -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)},
|
||||
|
@ -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)},
|
||||
|
@ -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()
|
||||
|
@ -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)},
|
||||
|
@ -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)},
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
|
@ -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={
|
||||
|
@ -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)},
|
||||
|
@ -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)},
|
||||
|
@ -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)},
|
||||
|
Loading…
Reference in New Issue
Block a user