Enforce namespace import in components (#118218)
This commit is contained in:
parent
33bdcb46cf
commit
e7ce01e649
27 changed files with 112 additions and 161 deletions
|
@ -23,16 +23,12 @@ from homeassistant.const import (
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
CONNECTION_BLUETOOTH,
|
from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo
|
||||||
DeviceInfo,
|
|
||||||
async_get as device_async_get,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity_registry import (
|
from homeassistant.helpers.entity_registry import (
|
||||||
RegistryEntry,
|
RegistryEntry,
|
||||||
async_entries_for_device,
|
async_entries_for_device,
|
||||||
async_get as entity_async_get,
|
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
@ -115,13 +111,13 @@ SENSORS_MAPPING_TEMPLATE: dict[str, SensorEntityDescription] = {
|
||||||
@callback
|
@callback
|
||||||
def async_migrate(hass: HomeAssistant, address: str, sensor_name: str) -> None:
|
def async_migrate(hass: HomeAssistant, address: str, sensor_name: str) -> None:
|
||||||
"""Migrate entities to new unique ids (with BLE Address)."""
|
"""Migrate entities to new unique ids (with BLE Address)."""
|
||||||
ent_reg = entity_async_get(hass)
|
ent_reg = er.async_get(hass)
|
||||||
unique_id_trailer = f"_{sensor_name}"
|
unique_id_trailer = f"_{sensor_name}"
|
||||||
new_unique_id = f"{address}{unique_id_trailer}"
|
new_unique_id = f"{address}{unique_id_trailer}"
|
||||||
if ent_reg.async_get_entity_id(DOMAIN, Platform.SENSOR, new_unique_id):
|
if ent_reg.async_get_entity_id(DOMAIN, Platform.SENSOR, new_unique_id):
|
||||||
# New unique id already exists
|
# New unique id already exists
|
||||||
return
|
return
|
||||||
dev_reg = device_async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
if not (
|
if not (
|
||||||
device := dev_reg.async_get_device(
|
device := dev_reg.async_get_device(
|
||||||
connections={(CONNECTION_BLUETOOTH, address)}
|
connections={(CONNECTION_BLUETOOTH, address)}
|
||||||
|
|
|
@ -5,7 +5,8 @@ from __future__ import annotations
|
||||||
from boschshcpy import SHCDevice, SHCIntrusionSystem
|
from boschshcpy import SHCDevice, SHCIntrusionSystem
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo, async_get as get_dev_reg
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
@ -15,7 +16,7 @@ async def async_remove_devices(
|
||||||
hass: HomeAssistant, entity: SHCBaseEntity, entry_id: str
|
hass: HomeAssistant, entity: SHCBaseEntity, entry_id: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Get item that is removed from session."""
|
"""Get item that is removed from session."""
|
||||||
dev_registry = get_dev_reg(hass)
|
dev_registry = dr.async_get(hass)
|
||||||
device = dev_registry.async_get_device(identifiers={(DOMAIN, entity.device_id)})
|
device = dev_registry.async_get_device(identifiers={(DOMAIN, entity.device_id)})
|
||||||
if device is not None:
|
if device is not None:
|
||||||
dev_registry.async_update_device(device.id, remove_config_entry_id=entry_id)
|
dev_registry.async_update_device(device.id, remove_config_entry_id=entry_id)
|
||||||
|
|
|
@ -15,11 +15,8 @@ from homeassistant.components.bluetooth import (
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers import device_registry as dr
|
||||||
CONNECTION_BLUETOOTH,
|
from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceRegistry
|
||||||
DeviceRegistry,
|
|
||||||
async_get,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.util.signal_type import SignalType
|
from homeassistant.util.signal_type import SignalType
|
||||||
|
|
||||||
|
@ -130,7 +127,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
kwargs[CONF_BINDKEY] = bytes.fromhex(bindkey)
|
kwargs[CONF_BINDKEY] = bytes.fromhex(bindkey)
|
||||||
data = BTHomeBluetoothDeviceData(**kwargs)
|
data = BTHomeBluetoothDeviceData(**kwargs)
|
||||||
|
|
||||||
device_registry = async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
|
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
|
||||||
BTHomePassiveBluetoothProcessorCoordinator(
|
BTHomePassiveBluetoothProcessorCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -6,7 +6,7 @@ from collections.abc import Callable
|
||||||
|
|
||||||
from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME
|
from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import async_get
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from .const import BTHOME_BLE_EVENT, DOMAIN, BTHomeBleEvent
|
from .const import BTHOME_BLE_EVENT, DOMAIN, BTHomeBleEvent
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ def async_describe_events(
|
||||||
],
|
],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Describe logbook events."""
|
"""Describe logbook events."""
|
||||||
dr = async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_describe_bthome_event(event: Event[BTHomeBleEvent]) -> dict[str, str]:
|
def async_describe_bthome_event(event: Event[BTHomeBleEvent]) -> dict[str, str]:
|
||||||
"""Describe bthome logbook event."""
|
"""Describe bthome logbook event."""
|
||||||
data = event.data
|
data = event.data
|
||||||
device = dr.async_get(data["device_id"])
|
device = dev_reg.async_get(data["device_id"])
|
||||||
name = device and device.name or f'BTHome {data["address"]}'
|
name = device and device.name or f'BTHome {data["address"]}'
|
||||||
if properties := data["event_properties"]:
|
if properties := data["event_properties"]:
|
||||||
message = f"{data['event_class']} {data['event_type']}: {properties}"
|
message = f"{data['event_class']} {data['event_type']}: {properties}"
|
||||||
|
|
|
@ -10,10 +10,6 @@ from homeassistant.helpers import (
|
||||||
entity_registry as er,
|
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 (
|
|
||||||
async_entries_for_config_entry,
|
|
||||||
async_entries_for_device,
|
|
||||||
)
|
|
||||||
from homeassistant.util.read_only_dict import ReadOnlyDict
|
from homeassistant.util.read_only_dict import ReadOnlyDict
|
||||||
|
|
||||||
from .config_flow import get_master_hub
|
from .config_flow import get_master_hub
|
||||||
|
@ -146,7 +142,7 @@ async def async_remove_orphaned_entries_service(hub: DeconzHub) -> None:
|
||||||
device_registry = dr.async_get(hub.hass)
|
device_registry = dr.async_get(hub.hass)
|
||||||
entity_registry = er.async_get(hub.hass)
|
entity_registry = er.async_get(hub.hass)
|
||||||
|
|
||||||
entity_entries = async_entries_for_config_entry(
|
entity_entries = er.async_entries_for_config_entry(
|
||||||
entity_registry, hub.config_entry.entry_id
|
entity_registry, hub.config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -196,7 +192,7 @@ async def async_remove_orphaned_entries_service(hub: DeconzHub) -> None:
|
||||||
for device_id in devices_to_be_removed:
|
for device_id in devices_to_be_removed:
|
||||||
if (
|
if (
|
||||||
len(
|
len(
|
||||||
async_entries_for_device(
|
er.async_entries_for_device(
|
||||||
entity_registry, device_id, include_disabled_entities=True
|
entity_registry, device_id, include_disabled_entities=True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,14 +36,14 @@ from homeassistant.components.media_player import (
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import (
|
||||||
import homeassistant.helpers.config_validation as cv
|
config_validation as cv,
|
||||||
from homeassistant.helpers.device_registry import (
|
device_registry as dr,
|
||||||
DeviceInfo,
|
entity_platform,
|
||||||
async_get as async_get_device_registry,
|
entity_registry as er,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
|
|
||||||
|
|
||||||
from .const import ATTR_CMODE, DOMAIN, SERVICE_SELECT_CMODE
|
from .const import ATTR_CMODE, DOMAIN, SERVICE_SELECT_CMODE
|
||||||
|
|
||||||
|
@ -110,13 +110,13 @@ class EpsonProjectorMediaPlayer(MediaPlayerEntity):
|
||||||
return False
|
return False
|
||||||
if uid := await self._projector.get_serial_number():
|
if uid := await self._projector.get_serial_number():
|
||||||
self.hass.config_entries.async_update_entry(self._entry, unique_id=uid)
|
self.hass.config_entries.async_update_entry(self._entry, unique_id=uid)
|
||||||
ent_reg = async_get_entity_registry(self.hass)
|
ent_reg = er.async_get(self.hass)
|
||||||
old_entity_id = ent_reg.async_get_entity_id(
|
old_entity_id = ent_reg.async_get_entity_id(
|
||||||
"media_player", DOMAIN, self._entry.entry_id
|
"media_player", DOMAIN, self._entry.entry_id
|
||||||
)
|
)
|
||||||
if old_entity_id is not None:
|
if old_entity_id is not None:
|
||||||
ent_reg.async_update_entity(old_entity_id, new_unique_id=uid)
|
ent_reg.async_update_entity(old_entity_id, new_unique_id=uid)
|
||||||
dev_reg = async_get_device_registry(self.hass)
|
dev_reg = dr.async_get(self.hass)
|
||||||
device = dev_reg.async_get_device({(DOMAIN, self._entry.entry_id)})
|
device = dev_reg.async_get_device({(DOMAIN, self._entry.entry_id)})
|
||||||
if device is not None:
|
if device is not None:
|
||||||
dev_reg.async_update_device(device.id, new_identifiers={(DOMAIN, uid)})
|
dev_reg.async_update_device(device.id, new_identifiers={(DOMAIN, uid)})
|
||||||
|
|
|
@ -19,12 +19,8 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_HALVES, UnitOfTemperature
|
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_HALVES, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ServiceValidationError
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers import device_registry as dr
|
||||||
CONNECTION_BLUETOOTH,
|
from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo
|
||||||
DeviceInfo,
|
|
||||||
async_get,
|
|
||||||
format_mac,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
@ -88,7 +84,7 @@ class Eq3Climate(Eq3Entity, ClimateEntity):
|
||||||
"""Initialize the climate entity."""
|
"""Initialize the climate entity."""
|
||||||
|
|
||||||
super().__init__(eq3_config, thermostat)
|
super().__init__(eq3_config, thermostat)
|
||||||
self._attr_unique_id = format_mac(eq3_config.mac_address)
|
self._attr_unique_id = dr.format_mac(eq3_config.mac_address)
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
name=slugify(self._eq3_config.mac_address),
|
name=slugify(self._eq3_config.mac_address),
|
||||||
manufacturer=MANUFACTURER,
|
manufacturer=MANUFACTURER,
|
||||||
|
@ -158,7 +154,7 @@ class Eq3Climate(Eq3Entity, ClimateEntity):
|
||||||
def _async_on_device_updated(self) -> None:
|
def _async_on_device_updated(self) -> None:
|
||||||
"""Handle updated device data from the thermostat."""
|
"""Handle updated device data from the thermostat."""
|
||||||
|
|
||||||
device_registry = async_get(self.hass)
|
device_registry = dr.async_get(self.hass)
|
||||||
if device := device_registry.async_get_device(
|
if device := device_registry.async_get_device(
|
||||||
connections={(CONNECTION_BLUETOOTH, self._eq3_config.mac_address)},
|
connections={(CONNECTION_BLUETOOTH, self._eq3_config.mac_address)},
|
||||||
):
|
):
|
||||||
|
|
|
@ -7,10 +7,7 @@ import logging
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_registry import (
|
from homeassistant.helpers import entity_registry as er
|
||||||
async_entries_for_config_entry,
|
|
||||||
async_get,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORMS
|
from .const import DOMAIN, PLATFORMS
|
||||||
from .manager import GeoJsonFeedEntityManager
|
from .manager import GeoJsonFeedEntityManager
|
||||||
|
@ -40,8 +37,8 @@ async def remove_orphaned_entities(hass: HomeAssistant, entry_id: str) -> None:
|
||||||
has no previous data to compare against, and thus all entities managed by this
|
has no previous data to compare against, and thus all entities managed by this
|
||||||
integration are removed after startup.
|
integration are removed after startup.
|
||||||
"""
|
"""
|
||||||
entity_registry = async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
orphaned_entries = async_entries_for_config_entry(entity_registry, entry_id)
|
orphaned_entries = er.async_entries_for_config_entry(entity_registry, entry_id)
|
||||||
if orphaned_entries is not None:
|
if orphaned_entries is not None:
|
||||||
for entry in orphaned_entries:
|
for entry in orphaned_entries:
|
||||||
if entry.domain == Platform.GEO_LOCATION:
|
if entry.domain == Platform.GEO_LOCATION:
|
||||||
|
|
|
@ -6,9 +6,11 @@ from homeassistant import config_entries
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import (
|
||||||
import homeassistant.helpers.config_validation as cv
|
config_validation as cv,
|
||||||
from homeassistant.helpers.entity_registry import async_entries_for_config_entry
|
device_registry as dr,
|
||||||
|
entity_registry as er,
|
||||||
|
)
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -129,7 +131,7 @@ def _async_remove_obsolete_entities(
|
||||||
return
|
return
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
er_entries = async_entries_for_config_entry(entity_registry, entry.entry_id)
|
er_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
||||||
for er_entry in er_entries:
|
for er_entry in er_entries:
|
||||||
if er_entry.unique_id.startswith("HomematicipAccesspointStatus"):
|
if er_entry.unique_id.startswith("HomematicipAccesspointStatus"):
|
||||||
entity_registry.async_remove(er_entry.entity_id)
|
entity_registry.async_remove(er_entry.entity_id)
|
||||||
|
|
|
@ -12,15 +12,10 @@ from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||||
from homeassistant.components.sensor import SensorDeviceClass
|
from homeassistant.components.sensor import SensorDeviceClass
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_API_VERSION, CONF_HOST, CONF_USERNAME
|
from homeassistant.const import CONF_API_KEY, CONF_API_VERSION, CONF_HOST, CONF_USERNAME
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import (
|
||||||
from homeassistant.helpers.device_registry import (
|
aiohttp_client,
|
||||||
async_entries_for_config_entry as devices_for_config_entries,
|
device_registry as dr,
|
||||||
async_get as async_get_device_registry,
|
entity_registry as er,
|
||||||
)
|
|
||||||
from homeassistant.helpers.entity_registry import (
|
|
||||||
async_entries_for_config_entry as entities_for_config_entry,
|
|
||||||
async_entries_for_device,
|
|
||||||
async_get as async_get_entity_registry,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
@ -75,15 +70,15 @@ async def handle_v2_migration(hass: core.HomeAssistant, entry: ConfigEntry) -> N
|
||||||
"""Perform migration of devices and entities to V2 Id's."""
|
"""Perform migration of devices and entities to V2 Id's."""
|
||||||
host = entry.data[CONF_HOST]
|
host = entry.data[CONF_HOST]
|
||||||
api_key = entry.data[CONF_API_KEY]
|
api_key = entry.data[CONF_API_KEY]
|
||||||
dev_reg = async_get_device_registry(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
ent_reg = async_get_entity_registry(hass)
|
ent_reg = er.async_get(hass)
|
||||||
LOGGER.info("Start of migration of devices and entities to support API schema 2")
|
LOGGER.info("Start of migration of devices and entities to support API schema 2")
|
||||||
|
|
||||||
# Create mapping of mac address to HA device id's.
|
# Create mapping of mac address to HA device id's.
|
||||||
# Identifier in dev reg should be mac-address,
|
# Identifier in dev reg should be mac-address,
|
||||||
# but in some cases it has a postfix like `-0b` or `-01`.
|
# but in some cases it has a postfix like `-0b` or `-01`.
|
||||||
dev_ids = {}
|
dev_ids = {}
|
||||||
for hass_dev in devices_for_config_entries(dev_reg, entry.entry_id):
|
for hass_dev in dr.async_entries_for_config_entry(dev_reg, entry.entry_id):
|
||||||
for domain, mac in hass_dev.identifiers:
|
for domain, mac in hass_dev.identifiers:
|
||||||
if domain != DOMAIN:
|
if domain != DOMAIN:
|
||||||
continue
|
continue
|
||||||
|
@ -128,7 +123,7 @@ async def handle_v2_migration(hass: core.HomeAssistant, entry: ConfigEntry) -> N
|
||||||
LOGGER.info("Migrated device %s (%s)", hue_dev.metadata.name, hass_dev_id)
|
LOGGER.info("Migrated device %s (%s)", hue_dev.metadata.name, hass_dev_id)
|
||||||
|
|
||||||
# loop through all entities for device and find match
|
# loop through all entities for device and find match
|
||||||
for ent in async_entries_for_device(ent_reg, hass_dev_id, True):
|
for ent in er.async_entries_for_device(ent_reg, hass_dev_id, True):
|
||||||
if ent.entity_id.startswith("light"):
|
if ent.entity_id.startswith("light"):
|
||||||
# migrate light
|
# migrate light
|
||||||
# should always return one lightid here
|
# should always return one lightid here
|
||||||
|
@ -179,7 +174,7 @@ async def handle_v2_migration(hass: core.HomeAssistant, entry: ConfigEntry) -> N
|
||||||
)
|
)
|
||||||
|
|
||||||
# migrate entities that are not connected to a device (groups)
|
# migrate entities that are not connected to a device (groups)
|
||||||
for ent in entities_for_config_entry(ent_reg, entry.entry_id):
|
for ent in er.async_entries_for_config_entry(ent_reg, entry.entry_id):
|
||||||
if ent.device_id is not None:
|
if ent.device_id is not None:
|
||||||
continue
|
continue
|
||||||
if "-" in ent.unique_id:
|
if "-" in ent.unique_id:
|
||||||
|
|
|
@ -10,9 +10,9 @@ from aiohue.v2.models.resource import ResourceTypes
|
||||||
from aiohue.v2.models.zigbee_connectivity import ConnectivityServiceStatus
|
from aiohue.v2.models.zigbee_connectivity import ConnectivityServiceStatus
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
|
|
||||||
|
|
||||||
from ..bridge import HueBridge
|
from ..bridge import HueBridge
|
||||||
from ..const import CONF_IGNORE_AVAILABILITY, DOMAIN
|
from ..const import CONF_IGNORE_AVAILABILITY, DOMAIN
|
||||||
|
@ -128,7 +128,7 @@ class HueBaseEntity(Entity):
|
||||||
if event_type == EventType.RESOURCE_DELETED:
|
if event_type == EventType.RESOURCE_DELETED:
|
||||||
# cleanup entities that are not strictly device-bound and have the bridge as parent
|
# cleanup entities that are not strictly device-bound and have the bridge as parent
|
||||||
if self.device is None and resource.id == self.resource.id:
|
if self.device is None and resource.id == self.resource.id:
|
||||||
ent_reg = async_get_entity_registry(self.hass)
|
ent_reg = er.async_get(self.hass)
|
||||||
ent_reg.async_remove(self.entity_id)
|
ent_reg.async_remove(self.entity_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry, async_get
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORMS
|
from .const import DOMAIN, PLATFORMS
|
||||||
from .coordinator import IBeaconCoordinator
|
from .coordinator import IBeaconCoordinator
|
||||||
|
@ -14,7 +15,9 @@ type IBeaconConfigEntry = ConfigEntry[IBeaconCoordinator]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: IBeaconConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: IBeaconConfigEntry) -> bool:
|
||||||
"""Set up Bluetooth LE Tracker from a config entry."""
|
"""Set up Bluetooth LE Tracker from a config entry."""
|
||||||
entry.runtime_data = coordinator = IBeaconCoordinator(hass, entry, async_get(hass))
|
entry.runtime_data = coordinator = IBeaconCoordinator(
|
||||||
|
hass, entry, dr.async_get(hass)
|
||||||
|
)
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
await coordinator.async_start()
|
await coordinator.async_start()
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -33,10 +33,7 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
DeviceInfo,
|
|
||||||
async_entries_for_config_entry,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect,
|
async_dispatcher_connect,
|
||||||
async_dispatcher_send,
|
async_dispatcher_send,
|
||||||
|
@ -459,7 +456,7 @@ async def async_setup_entry(
|
||||||
"""Retrieve Netatmo public weather entities."""
|
"""Retrieve Netatmo public weather entities."""
|
||||||
entities = {
|
entities = {
|
||||||
device.name: device.id
|
device.name: device.id
|
||||||
for device in async_entries_for_config_entry(
|
for device in dr.async_entries_for_config_entry(
|
||||||
device_registry, entry.entry_id
|
device_registry, entry.entry_id
|
||||||
)
|
)
|
||||||
if device.model == "Public Weather station"
|
if device.model == "Public Weather station"
|
||||||
|
|
|
@ -14,12 +14,9 @@ from homeassistant.config_entries import (
|
||||||
OptionsFlow,
|
OptionsFlow,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_registry import (
|
|
||||||
async_entries_for_config_entry,
|
|
||||||
async_get,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
@ -213,9 +210,9 @@ class OptionsFlowHandler(OptionsFlow):
|
||||||
user_input, self._all_region_codes_sorted
|
user_input, self._all_region_codes_sorted
|
||||||
)
|
)
|
||||||
|
|
||||||
entity_registry = async_get(self.hass)
|
entity_registry = er.async_get(self.hass)
|
||||||
|
|
||||||
entries = async_entries_for_config_entry(
|
entries = er.async_entries_for_config_entry(
|
||||||
entity_registry, self.config_entry.entry_id
|
entity_registry, self.config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
||||||
import homeassistant.helpers.config_validation as cv
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||||
from homeassistant.helpers.device_registry import async_get
|
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntry, async_migrate_entries
|
from homeassistant.helpers.entity_registry import RegistryEntry, async_migrate_entries
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
|
@ -121,7 +120,7 @@ def async_get_entry_id_for_service_call(hass: HomeAssistant, call: ServiceCall)
|
||||||
|
|
||||||
def update_device_identifiers(hass: HomeAssistant, entry: ConfigEntry):
|
def update_device_identifiers(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Update device identifiers to new identifiers."""
|
"""Update device identifiers to new identifiers."""
|
||||||
device_registry = async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device_entry = device_registry.async_get_device(identifiers={(DOMAIN, DOMAIN)})
|
device_entry = device_registry.async_get_device(identifiers={(DOMAIN, DOMAIN)})
|
||||||
if device_entry and entry.entry_id in device_entry.config_entries:
|
if device_entry and entry.entry_id in device_entry.config_entries:
|
||||||
new_identifiers = {(DOMAIN, entry.entry_id)}
|
new_identifiers = {(DOMAIN, entry.entry_id)}
|
||||||
|
|
|
@ -19,14 +19,13 @@ import voluptuous as vol
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import (
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
config_validation as cv,
|
||||||
import homeassistant.helpers.config_validation as cv
|
device_registry as dr,
|
||||||
from homeassistant.helpers.device_registry import (
|
issue_registry as ir,
|
||||||
CONNECTION_NETWORK_MAC,
|
|
||||||
async_get as dr_async_get,
|
|
||||||
format_mac,
|
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -151,11 +150,11 @@ async def _async_setup_block_entry(
|
||||||
options,
|
options,
|
||||||
)
|
)
|
||||||
|
|
||||||
dev_reg = dr_async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
device_entry = None
|
device_entry = None
|
||||||
if entry.unique_id is not None:
|
if entry.unique_id is not None:
|
||||||
device_entry = dev_reg.async_get_device(
|
device_entry = dev_reg.async_get_device(
|
||||||
connections={(CONNECTION_NETWORK_MAC, format_mac(entry.unique_id))},
|
connections={(CONNECTION_NETWORK_MAC, dr.format_mac(entry.unique_id))},
|
||||||
)
|
)
|
||||||
# https://github.com/home-assistant/core/pull/48076
|
# https://github.com/home-assistant/core/pull/48076
|
||||||
if device_entry and entry.entry_id not in device_entry.config_entries:
|
if device_entry and entry.entry_id not in device_entry.config_entries:
|
||||||
|
@ -237,11 +236,11 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ShellyConfigEntry)
|
||||||
options,
|
options,
|
||||||
)
|
)
|
||||||
|
|
||||||
dev_reg = dr_async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
device_entry = None
|
device_entry = None
|
||||||
if entry.unique_id is not None:
|
if entry.unique_id is not None:
|
||||||
device_entry = dev_reg.async_get_device(
|
device_entry = dev_reg.async_get_device(
|
||||||
connections={(CONNECTION_NETWORK_MAC, format_mac(entry.unique_id))},
|
connections={(CONNECTION_NETWORK_MAC, dr.format_mac(entry.unique_id))},
|
||||||
)
|
)
|
||||||
# https://github.com/home-assistant/core/pull/48076
|
# https://github.com/home-assistant/core/pull/48076
|
||||||
if device_entry and entry.entry_id not in device_entry.config_entries:
|
if device_entry and entry.entry_id not in device_entry.config_entries:
|
||||||
|
|
|
@ -21,14 +21,10 @@ from homeassistant.components.climate import (
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, State, callback
|
from homeassistant.core import HomeAssistant, State, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity_registry import (
|
from homeassistant.helpers.entity_registry import RegistryEntry
|
||||||
RegistryEntry,
|
|
||||||
async_entries_for_config_entry,
|
|
||||||
async_get as er_async_get,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
|
from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||||
|
@ -104,8 +100,8 @@ def async_restore_climate_entities(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Restore sleeping climate devices."""
|
"""Restore sleeping climate devices."""
|
||||||
|
|
||||||
ent_reg = er_async_get(hass)
|
ent_reg = er.async_get(hass)
|
||||||
entries = async_entries_for_config_entry(ent_reg, config_entry.entry_id)
|
entries = er.async_entries_for_config_entry(ent_reg, config_entry.entry_id)
|
||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if entry.domain != CLIMATE_DOMAIN:
|
if entry.domain != CLIMATE_DOMAIN:
|
||||||
|
|
|
@ -22,12 +22,9 @@ from homeassistant.const import (
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
CONNECTION_NETWORK_MAC,
|
|
||||||
async_get as dr_async_get,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .bluetooth import async_connect_scanner
|
from .bluetooth import async_connect_scanner
|
||||||
|
@ -141,7 +138,7 @@ class ShellyCoordinatorBase[_DeviceT: BlockDevice | RpcDevice](
|
||||||
def async_setup(self, pending_platforms: list[Platform] | None = None) -> None:
|
def async_setup(self, pending_platforms: list[Platform] | None = None) -> None:
|
||||||
"""Set up the coordinator."""
|
"""Set up the coordinator."""
|
||||||
self._pending_platforms = pending_platforms
|
self._pending_platforms = pending_platforms
|
||||||
dev_reg = dr_async_get(self.hass)
|
dev_reg = dr.async_get(self.hass)
|
||||||
device_entry = dev_reg.async_get_or_create(
|
device_entry = dev_reg.async_get_or_create(
|
||||||
config_entry_id=self.entry.entry_id,
|
config_entry_id=self.entry.entry_id,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
|
@ -734,7 +731,7 @@ def get_block_coordinator_by_device_id(
|
||||||
hass: HomeAssistant, device_id: str
|
hass: HomeAssistant, device_id: str
|
||||||
) -> ShellyBlockCoordinator | None:
|
) -> ShellyBlockCoordinator | None:
|
||||||
"""Get a Shelly block device coordinator for the given device id."""
|
"""Get a Shelly block device coordinator for the given device id."""
|
||||||
dev_reg = dr_async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
if device := dev_reg.async_get(device_id):
|
if device := dev_reg.async_get(device_id):
|
||||||
for config_entry in device.config_entries:
|
for config_entry in device.config_entries:
|
||||||
entry = hass.config_entries.async_get_entry(config_entry)
|
entry = hass.config_entries.async_get_entry(config_entry)
|
||||||
|
@ -753,7 +750,7 @@ def get_rpc_coordinator_by_device_id(
|
||||||
hass: HomeAssistant, device_id: str
|
hass: HomeAssistant, device_id: str
|
||||||
) -> ShellyRpcCoordinator | None:
|
) -> ShellyRpcCoordinator | None:
|
||||||
"""Get a Shelly RPC device coordinator for the given device id."""
|
"""Get a Shelly RPC device coordinator for the given device id."""
|
||||||
dev_reg = dr_async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
if device := dev_reg.async_get(device_id):
|
if device := dev_reg.async_get(device_id):
|
||||||
for config_entry in device.config_entries:
|
for config_entry in device.config_entries:
|
||||||
entry = hass.config_entries.async_get_entry(config_entry)
|
entry = hass.config_entries.async_get_entry(config_entry)
|
||||||
|
|
|
@ -11,14 +11,11 @@ from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCal
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant, State, callback
|
from homeassistant.core import HomeAssistant, State, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity_registry import (
|
from homeassistant.helpers.entity_registry import RegistryEntry
|
||||||
RegistryEntry,
|
|
||||||
async_entries_for_config_entry,
|
|
||||||
async_get as er_async_get,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
@ -112,8 +109,8 @@ def async_restore_block_attribute_entities(
|
||||||
"""Restore block attributes entities."""
|
"""Restore block attributes entities."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
ent_reg = er_async_get(hass)
|
ent_reg = er.async_get(hass)
|
||||||
entries = async_entries_for_config_entry(ent_reg, config_entry.entry_id)
|
entries = er.async_entries_for_config_entry(ent_reg, config_entry.entry_id)
|
||||||
|
|
||||||
domain = sensor_class.__module__.split(".")[-1]
|
domain = sensor_class.__module__.split(".")[-1]
|
||||||
|
|
||||||
|
@ -221,8 +218,8 @@ def async_restore_rpc_attribute_entities(
|
||||||
"""Restore block attributes entities."""
|
"""Restore block attributes entities."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
ent_reg = er_async_get(hass)
|
ent_reg = er.async_get(hass)
|
||||||
entries = async_entries_for_config_entry(ent_reg, config_entry.entry_id)
|
entries = er.async_entries_for_config_entry(ent_reg, config_entry.entry_id)
|
||||||
|
|
||||||
domain = sensor_class.__module__.split(".")[-1]
|
domain = sensor_class.__module__.split(".")[-1]
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,13 @@ from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_PORT, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import CONF_PORT, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.helpers import issue_registry as ir, singleton
|
from homeassistant.helpers import (
|
||||||
from homeassistant.helpers.device_registry import (
|
device_registry as dr,
|
||||||
CONNECTION_NETWORK_MAC,
|
entity_registry as er,
|
||||||
async_get as dr_async_get,
|
issue_registry as ir,
|
||||||
format_mac,
|
singleton,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity_registry import async_get as er_async_get
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -60,7 +60,7 @@ def async_remove_shelly_entity(
|
||||||
hass: HomeAssistant, domain: str, unique_id: str
|
hass: HomeAssistant, domain: str, unique_id: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Remove a Shelly entity."""
|
"""Remove a Shelly entity."""
|
||||||
entity_reg = er_async_get(hass)
|
entity_reg = er.async_get(hass)
|
||||||
entity_id = entity_reg.async_get_entity_id(domain, DOMAIN, unique_id)
|
entity_id = entity_reg.async_get_entity_id(domain, DOMAIN, unique_id)
|
||||||
if entity_id:
|
if entity_id:
|
||||||
LOGGER.debug("Removing entity: %s", entity_id)
|
LOGGER.debug("Removing entity: %s", entity_id)
|
||||||
|
@ -410,10 +410,10 @@ def update_device_fw_info(
|
||||||
"""Update the firmware version information in the device registry."""
|
"""Update the firmware version information in the device registry."""
|
||||||
assert entry.unique_id
|
assert entry.unique_id
|
||||||
|
|
||||||
dev_reg = dr_async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
if device := dev_reg.async_get_device(
|
if device := dev_reg.async_get_device(
|
||||||
identifiers={(DOMAIN, entry.entry_id)},
|
identifiers={(DOMAIN, entry.entry_id)},
|
||||||
connections={(CONNECTION_NETWORK_MAC, format_mac(entry.unique_id))},
|
connections={(CONNECTION_NETWORK_MAC, dr.format_mac(entry.unique_id))},
|
||||||
):
|
):
|
||||||
if device.sw_version == shellydevice.firmware_version:
|
if device.sw_version == shellydevice.firmware_version:
|
||||||
return
|
return
|
||||||
|
@ -487,7 +487,7 @@ def async_remove_shelly_rpc_entities(
|
||||||
hass: HomeAssistant, domain: str, mac: str, keys: list[str]
|
hass: HomeAssistant, domain: str, mac: str, keys: list[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Remove RPC based Shelly entity."""
|
"""Remove RPC based Shelly entity."""
|
||||||
entity_reg = er_async_get(hass)
|
entity_reg = er.async_get(hass)
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if entity_id := entity_reg.async_get_entity_id(domain, DOMAIN, f"{mac}-{key}"):
|
if entity_id := entity_reg.async_get_entity_id(domain, DOMAIN, f"{mac}-{key}"):
|
||||||
LOGGER.debug("Removing entity: %s", entity_id)
|
LOGGER.debug("Removing entity: %s", entity_id)
|
||||||
|
|
|
@ -13,9 +13,9 @@ from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||||
from homeassistant.data_entry_flow import AbortFlow
|
from homeassistant.data_entry_flow import AbortFlow
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
from homeassistant.helpers.entity_registry import async_get
|
|
||||||
|
|
||||||
from .const import CONF_HTTPS, DEFAULT_PORT, DOMAIN
|
from .const import CONF_HTTPS, DEFAULT_PORT, DOMAIN
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ class SqueezeboxConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
_LOGGER.debug("Configuring dhcp player with unique id: %s", self.unique_id)
|
_LOGGER.debug("Configuring dhcp player with unique id: %s", self.unique_id)
|
||||||
|
|
||||||
registry = async_get(self.hass)
|
registry = er.async_get(self.hass)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert self.unique_id
|
assert self.unique_id
|
||||||
|
|
|
@ -24,11 +24,7 @@ from homeassistant.components.mqtt import (
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceRegistry
|
||||||
CONNECTION_NETWORK_MAC,
|
|
||||||
DeviceRegistry,
|
|
||||||
async_entries_for_config_entry,
|
|
||||||
)
|
|
||||||
|
|
||||||
from . import device_automation, discovery
|
from . import device_automation, discovery
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -105,7 +101,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
# detach device triggers
|
# detach device triggers
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
devices = async_entries_for_config_entry(device_registry, entry.entry_id)
|
devices = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
|
||||||
for device in devices:
|
for device in devices:
|
||||||
await device_automation.async_remove_automations(hass, device.id)
|
await device_automation.async_remove_automations(hass, device.id)
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,9 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
DeviceInfo,
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
async_get as async_get_dev_reg,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_reg
|
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
|
@ -269,8 +266,8 @@ async def async_setup_entry(
|
||||||
|
|
||||||
tibber_connection = hass.data[TIBBER_DOMAIN]
|
tibber_connection = hass.data[TIBBER_DOMAIN]
|
||||||
|
|
||||||
entity_registry = async_get_entity_reg(hass)
|
entity_registry = er.async_get(hass)
|
||||||
device_registry = async_get_dev_reg(hass)
|
device_registry = dr.async_get(hass)
|
||||||
|
|
||||||
coordinator: TibberDataCoordinator | None = None
|
coordinator: TibberDataCoordinator | None = None
|
||||||
entities: list[TibberSensor] = []
|
entities: list[TibberSensor] = []
|
||||||
|
@ -548,7 +545,7 @@ class TibberRtDataCoordinator(DataUpdateCoordinator): # pylint: disable=hass-en
|
||||||
self._async_remove_device_updates_handler = self.async_add_listener(
|
self._async_remove_device_updates_handler = self.async_add_listener(
|
||||||
self._add_sensors
|
self._add_sensors
|
||||||
)
|
)
|
||||||
self.entity_registry = async_get_entity_reg(hass)
|
self.entity_registry = er.async_get(hass)
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -18,7 +18,6 @@ from homeassistant.core import callback
|
||||||
from homeassistant.helpers import entity_registry as er
|
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 homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity_registry import async_entries_for_config_entry
|
|
||||||
|
|
||||||
from ..const import LOGGER, UNIFI_WIRELESS_CLIENTS
|
from ..const import LOGGER, UNIFI_WIRELESS_CLIENTS
|
||||||
from ..entity import UnifiEntity, UnifiEntityDescription
|
from ..entity import UnifiEntity, UnifiEntityDescription
|
||||||
|
@ -86,7 +85,7 @@ class UnifiEntityLoader:
|
||||||
entity_registry = er.async_get(self.hub.hass)
|
entity_registry = er.async_get(self.hub.hass)
|
||||||
macs: list[str] = [
|
macs: list[str] = [
|
||||||
entry.unique_id.split("-", 1)[1]
|
entry.unique_id.split("-", 1)[1]
|
||||||
for entry in async_entries_for_config_entry(
|
for entry in er.async_entries_for_config_entry(
|
||||||
entity_registry, config.entry.entry_id
|
entity_registry, config.entry.entry_id
|
||||||
)
|
)
|
||||||
if entry.domain == Platform.DEVICE_TRACKER and "-" in entry.unique_id
|
if entry.domain == Platform.DEVICE_TRACKER and "-" in entry.unique_id
|
||||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow
|
from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.issue_registry import async_get as async_get_issue_registry
|
from homeassistant.helpers import issue_registry as ir
|
||||||
|
|
||||||
from .const import CONF_ALLOW_EA
|
from .const import CONF_ALLOW_EA
|
||||||
from .utils import async_create_api_client
|
from .utils import async_create_api_client
|
||||||
|
@ -34,7 +34,7 @@ class ProtectRepair(RepairsFlow):
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_get_placeholders(self) -> dict[str, str]:
|
def _async_get_placeholders(self) -> dict[str, str]:
|
||||||
issue_registry = async_get_issue_registry(self.hass)
|
issue_registry = ir.async_get(self.hass)
|
||||||
description_placeholders = {}
|
description_placeholders = {}
|
||||||
if issue := issue_registry.async_get_issue(self.handler, self.issue_id):
|
if issue := issue_registry.async_get_issue(self.handler, self.issue_id):
|
||||||
description_placeholders = issue.translation_placeholders or {}
|
description_placeholders = issue.translation_placeholders or {}
|
||||||
|
|
|
@ -24,11 +24,8 @@ from homeassistant.const import (
|
||||||
CONF_UNIQUE_ID,
|
CONF_UNIQUE_ID,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers import device_registry as dr
|
||||||
CONNECTION_UPNP,
|
from homeassistant.helpers.device_registry import CONNECTION_UPNP, DeviceInfo
|
||||||
DeviceInfo,
|
|
||||||
async_get as async_get_device_registry,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DOMAIN, WEMO_SUBSCRIPTION_EVENT
|
from .const import DOMAIN, WEMO_SUBSCRIPTION_EVENT
|
||||||
|
@ -291,7 +288,7 @@ async def async_register_device(
|
||||||
await device.async_refresh()
|
await device.async_refresh()
|
||||||
if not device.last_update_success and device.last_exception:
|
if not device.last_update_success and device.last_exception:
|
||||||
raise device.last_exception
|
raise device.last_exception
|
||||||
device_registry = async_get_device_registry(hass)
|
device_registry = dr.async_get(hass)
|
||||||
entry = device_registry.async_get_or_create(
|
entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id, **_create_device_info(wemo)
|
config_entry_id=config_entry.entry_id, **_create_device_info(wemo)
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,11 +17,8 @@ from homeassistant.components.bluetooth import (
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import CoreState, HomeAssistant
|
from homeassistant.core import CoreState, HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers import device_registry as dr
|
||||||
CONNECTION_BLUETOOTH,
|
from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceRegistry
|
||||||
DeviceRegistry,
|
|
||||||
async_get,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -167,7 +164,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
)
|
)
|
||||||
return await data.async_poll(connectable_device)
|
return await data.async_poll(connectable_device)
|
||||||
|
|
||||||
device_registry = async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
|
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
|
||||||
XiaomiActiveBluetoothProcessorCoordinator(
|
XiaomiActiveBluetoothProcessorCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
|
Loading…
Add table
Reference in a new issue