Don't require passing identifiers to DeviceRegistry.async_get_device (#96479)

* Require keyword arguments to DeviceRegistry.async_get_device

* Update tests

* Update tests

* Don't enforce keyword arguments
This commit is contained in:
Erik Montnemery 2023-07-13 19:39:25 +02:00 committed by GitHub
parent 5f46436057
commit 7539cf25be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
143 changed files with 654 additions and 494 deletions

View file

@ -90,7 +90,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
str(longitude),
),
):
device_entry = device_registry.async_get_device({old_ids}) # type: ignore[arg-type]
device_entry = device_registry.async_get_device(identifiers={old_ids}) # type: ignore[arg-type]
if device_entry and entry.entry_id in device_entry.config_entries:
new_ids = (DOMAIN, f"{latitude}-{longitude}")
device_registry.async_update_device(

View file

@ -15,9 +15,7 @@ async def async_remove_devices(
) -> None:
"""Get item that is removed from session."""
dev_registry = get_dev_reg(hass)
device = dev_registry.async_get_device(
identifiers={(DOMAIN, entity.device_id)}, connections=set()
)
device = dev_registry.async_get_device(identifiers={(DOMAIN, entity.device_id)})
if device is not None:
dev_registry.async_update_device(device.id, remove_config_entry_id=entry_id)

View file

@ -80,7 +80,9 @@ class BroadlinkDevice:
"""
device_registry = dr.async_get(hass)
assert entry.unique_id
device_entry = device_registry.async_get_device({(DOMAIN, entry.unique_id)})
device_entry = device_registry.async_get_device(
identifiers={(DOMAIN, entry.unique_id)}
)
assert device_entry
device_registry.async_update_device(device_entry.id, name=entry.title)
await hass.config_entries.async_reload(entry.entry_id)

View file

@ -168,14 +168,13 @@ async def async_remove_orphaned_entries_service(gateway: DeconzGateway) -> None:
if gateway.api.config.mac:
gateway_host = device_registry.async_get_device(
connections={(CONNECTION_NETWORK_MAC, gateway.api.config.mac)},
identifiers=set(),
)
if gateway_host and gateway_host.id in devices_to_be_removed:
devices_to_be_removed.remove(gateway_host.id)
# Don't remove the Gateway service entry
gateway_service = device_registry.async_get_device(
identifiers={(DOMAIN, gateway.api.config.bridge_id)}, connections=set()
identifiers={(DOMAIN, gateway.api.config.bridge_id)}
)
if gateway_service and gateway_service.id in devices_to_be_removed:
devices_to_be_removed.remove(gateway_service.id)

View file

@ -365,7 +365,7 @@ class ScannerEntity(BaseTrackerEntity):
assert self.mac_address is not None
return dr.async_get(self.hass).async_get_device(
set(), {(dr.CONNECTION_NETWORK_MAC, self.mac_address)}
connections={(dr.CONNECTION_NETWORK_MAC, self.mac_address)}
)
async def async_internal_added_to_hass(self) -> None:

View file

@ -196,7 +196,7 @@ class WatcherBase(ABC):
dev_reg: DeviceRegistry = async_get(self.hass)
if device := dev_reg.async_get_device(
identifiers=set(), connections={(CONNECTION_NETWORK_MAC, uppercase_mac)}
connections={(CONNECTION_NETWORK_MAC, uppercase_mac)}
):
for entry_id in device.config_entries:
if entry := self.hass.config_entries.async_get_entry(entry_id):

View file

@ -37,7 +37,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# We used to use int in device_entry identifiers, convert this to str.
device_registry = dr.async_get(hass)
old_ids = (DOMAIN, station_id)
device_entry = device_registry.async_get_device({old_ids}) # type: ignore[arg-type]
device_entry = device_registry.async_get_device(identifiers={old_ids}) # type: ignore[arg-type]
if device_entry and entry.entry_id in device_entry.config_entries:
new_ids = (DOMAIN, str(station_id))
device_registry.async_update_device(device_entry.id, new_identifiers={new_ids})

View file

@ -758,7 +758,7 @@ def async_remove_addons_from_dev_reg(
) -> None:
"""Remove addons from the device registry."""
for addon_slug in addons:
if dev := dev_reg.async_get_device({(DOMAIN, addon_slug)}):
if dev := dev_reg.async_get_device(identifiers={(DOMAIN, addon_slug)}):
dev_reg.async_remove_device(dev.id)
@ -855,7 +855,7 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator):
async_remove_addons_from_dev_reg(self.dev_reg, stale_addons)
if not self.is_hass_os and (
dev := self.dev_reg.async_get_device({(DOMAIN, "OS")})
dev := self.dev_reg.async_get_device(identifiers={(DOMAIN, "OS")})
):
# Remove the OS device if it exists and the installation is not hassos
self.dev_reg.async_remove_device(dev.id)

View file

@ -220,7 +220,9 @@ class ControllerManager:
# mapped_ids contains the mapped IDs (new:old)
for new_id, old_id in mapped_ids.items():
# update device registry
entry = self._device_registry.async_get_device({(DOMAIN, old_id)})
entry = self._device_registry.async_get_device(
identifiers={(DOMAIN, old_id)}
)
new_identifiers = {(DOMAIN, new_id)}
if entry:
self._device_registry.async_update_device(

View file

@ -128,7 +128,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entity_uids_to_remove = uids - set(module_data)
for uid in entity_uids_to_remove:
uids.remove(uid)
device = device_registry.async_get_device({(DOMAIN, uid)})
device = device_registry.async_get_device(identifiers={(DOMAIN, uid)})
device_registry.async_remove_device(device.id)
# Send out signal for new entity addition to Home Assistant

View file

@ -203,7 +203,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Determine if the device is a homekit bridge or accessory."""
dev_reg = dr.async_get(self.hass)
device = dev_reg.async_get_device(
identifiers=set(), connections={(dr.CONNECTION_NETWORK_MAC, hkid)}
connections={(dr.CONNECTION_NETWORK_MAC, hkid)}
)
if device is None:

View file

@ -58,7 +58,7 @@ async def async_setup_devices(bridge: "HueBridge"):
@callback
def remove_device(hue_device_id: str) -> None:
"""Remove device from registry."""
if device := dev_reg.async_get_device({(DOMAIN, hue_device_id)}):
if device := dev_reg.async_get_device(identifiers={(DOMAIN, hue_device_id)}):
# note: removal of any underlying entities is handled by core
dev_reg.async_remove_device(device.id)

View file

@ -147,7 +147,9 @@ class HueBaseEntity(Entity):
# regular devices are removed automatically by the logic in device.py.
if resource.type in (ResourceTypes.ROOM, ResourceTypes.ZONE):
dev_reg = async_get_device_registry(self.hass)
if device := dev_reg.async_get_device({(DOMAIN, resource.id)}):
if device := dev_reg.async_get_device(
identifiers={(DOMAIN, resource.id)}
):
dev_reg.async_remove_device(device.id)
# cleanup entities that are not strictly device-bound and have the bridge as parent
if self.device is None:

View file

@ -44,7 +44,7 @@ async def async_setup_hue_events(bridge: "HueBridge"):
return
hue_device = btn_controller.get_device(hue_resource.id)
device = dev_reg.async_get_device({(DOMAIN, hue_device.id)})
device = dev_reg.async_get_device(identifiers={(DOMAIN, hue_device.id)})
# Fire event
data = {
@ -70,7 +70,7 @@ async def async_setup_hue_events(bridge: "HueBridge"):
LOGGER.debug("Received relative_rotary event: %s", hue_resource)
hue_device = btn_controller.get_device(hue_resource.id)
device = dev_reg.async_get_device({(DOMAIN, hue_device.id)})
device = dev_reg.async_get_device(identifiers={(DOMAIN, hue_device.id)})
# Fire event
data = {

View file

@ -200,7 +200,9 @@ class IBeaconCoordinator:
def _async_purge_untrackable_entities(self, unique_ids: set[str]) -> None:
"""Remove entities that are no longer trackable."""
for unique_id in unique_ids:
if device := self._dev_reg.async_get_device({(DOMAIN, unique_id)}):
if device := self._dev_reg.async_get_device(
identifiers={(DOMAIN, unique_id)}
):
self._dev_reg.async_remove_device(device.id)
self._last_ibeacon_advertisement_by_unique_id.pop(unique_id, None)

View file

@ -43,9 +43,7 @@ def get_insteon_device_from_ha_device(ha_device):
async def async_device_name(dev_registry, address):
"""Get the Insteon device name from a device registry id."""
ha_device = dev_registry.async_get_device(
identifiers={(DOMAIN, str(address))}, connections=set()
)
ha_device = dev_registry.async_get_device(identifiers={(DOMAIN, str(address))})
if not ha_device:
if device := devices[address]:
return f"{device.description} ({device.model})"

View file

@ -422,7 +422,7 @@ class KodiEntity(MediaPlayerEntity):
version = (await self._kodi.get_application_properties(["version"]))["version"]
sw_version = f"{version['major']}.{version['minor']}"
dev_reg = dr.async_get(self.hass)
device = dev_reg.async_get_device({(DOMAIN, self.unique_id)})
device = dev_reg.async_get_device(identifiers={(DOMAIN, self.unique_id)})
dev_reg.async_update_device(device.id, sw_version=sw_version)
self._device_id = device.id

View file

@ -180,7 +180,7 @@ def async_host_input_received(
logical_address.is_group,
)
identifiers = {(DOMAIN, generate_unique_id(config_entry.entry_id, address))}
device = device_registry.async_get_device(identifiers, set())
device = device_registry.async_get_device(identifiers=identifiers)
if device is None:
return

View file

@ -291,7 +291,7 @@ def purge_device_registry(
# Find device that references the host.
references_host = set()
host_device = device_registry.async_get_device({(DOMAIN, entry_id)})
host_device = device_registry.async_get_device(identifiers={(DOMAIN, entry_id)})
if host_device is not None:
references_host.add(host_device.id)
@ -299,7 +299,9 @@ def purge_device_registry(
references_entry_data = set()
for device_data in imported_entry_data[CONF_DEVICES]:
device_unique_id = generate_unique_id(entry_id, device_data[CONF_ADDRESS])
device = device_registry.async_get_device({(DOMAIN, device_unique_id)})
device = device_registry.async_get_device(
identifiers={(DOMAIN, device_unique_id)}
)
if device is not None:
references_entry_data.add(device.id)

View file

@ -142,7 +142,7 @@ async def _async_migrate_unique_ids(
return None
sensor_id = unique_id.split("_")[1]
new_unique_id = f"occupancygroup_{bridge_unique_id}_{sensor_id}"
if dev_entry := dev_reg.async_get_device({(DOMAIN, unique_id)}):
if dev_entry := dev_reg.async_get_device(identifiers={(DOMAIN, unique_id)}):
dev_reg.async_update_device(
dev_entry.id, new_identifiers={(DOMAIN, new_unique_id)}
)

View file

@ -80,7 +80,7 @@ class MatterAdapter:
node.endpoints[data["endpoint_id"]],
)
identifier = (DOMAIN, f"{ID_TYPE_DEVICE_ID}_{node_device_id}")
if device := device_registry.async_get_device({identifier}):
if device := device_registry.async_get_device(identifiers={identifier}):
device_registry.async_remove_device(device.id)
def node_removed_callback(event: EventType, node_id: int) -> None:

View file

@ -152,7 +152,9 @@ class SignalUpdateCallback:
return
_LOGGER.debug("Event Update %s", events.keys())
device_registry = dr.async_get(self._hass)
device_entry = device_registry.async_get_device({(DOMAIN, device_id)})
device_entry = device_registry.async_get_device(
identifiers={(DOMAIN, device_id)}
)
if not device_entry:
return
for api_event_type, image_event in events.items():

View file

@ -100,6 +100,8 @@ def async_nest_devices_by_device_id(hass: HomeAssistant) -> Mapping[str, Device]
device_registry = dr.async_get(hass)
devices = {}
for nest_device_id, device in async_nest_devices(hass).items():
if device_entry := device_registry.async_get_device({(DOMAIN, nest_device_id)}):
if device_entry := device_registry.async_get_device(
identifiers={(DOMAIN, nest_device_id)}
):
devices[device_entry.id] = device
return devices

View file

@ -244,7 +244,7 @@ class NestEventMediaStore(EventMediaStore):
devices = {}
for device in device_manager.devices.values():
if device_entry := device_registry.async_get_device(
{(DOMAIN, device.name)}
identifiers={(DOMAIN, device.name)}
):
devices[device.name] = device_entry.id
return devices

View file

@ -70,7 +70,7 @@ class NetatmoBase(Entity):
await self.data_handler.unsubscribe(signal_name, None)
registry = dr.async_get(self.hass)
if device := registry.async_get_device({(DOMAIN, self._id)}):
if device := registry.async_get_device(identifiers={(DOMAIN, self._id)}):
self.hass.data[DOMAIN][DATA_DEVICE_IDS][self._id] = device.id
self.async_update_callback()

View file

@ -339,9 +339,13 @@ class NotionEntity(CoordinatorEntity[DataUpdateCoordinator[NotionData]]):
self._bridge_id = sensor.bridge.id
device_registry = dr.async_get(self.hass)
this_device = device_registry.async_get_device({(DOMAIN, sensor.hardware_id)})
this_device = device_registry.async_get_device(
identifiers={(DOMAIN, sensor.hardware_id)}
)
bridge = self.coordinator.data.bridges[self._bridge_id]
bridge_device = device_registry.async_get_device({(DOMAIN, bridge.hardware_id)})
bridge_device = device_registry.async_get_device(
identifiers={(DOMAIN, bridge.hardware_id)}
)
if not bridge_device or not this_device:
return

View file

@ -171,7 +171,7 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
registry = dr.async_get(self.hass)
if not (
device := registry.async_get_device(
identifiers=set(), connections={(dr.CONNECTION_NETWORK_MAC, mac)}
connections={(dr.CONNECTION_NETWORK_MAC, mac)}
)
):
return self.async_abort(reason="no_devices_found")

View file

@ -178,7 +178,9 @@ async def on_device_removed(
base_device_url = event.device_url.split("#")[0]
registry = dr.async_get(coordinator.hass)
if registered_device := registry.async_get_device({(DOMAIN, base_device_url)}):
if registered_device := registry.async_get_device(
identifiers={(DOMAIN, base_device_url)}
):
registry.async_remove_device(registered_device.id)
if event.device_url:

View file

@ -127,7 +127,7 @@ def async_get_entry_id_for_service_call(hass: HomeAssistant, call: ServiceCall)
def update_device_identifiers(hass: HomeAssistant, entry: ConfigEntry):
"""Update device identifiers to new identifiers."""
device_registry = async_get(hass)
device_entry = device_registry.async_get_device({(DOMAIN, DOMAIN)})
device_entry = device_registry.async_get_device(identifiers={(DOMAIN, DOMAIN)})
if device_entry and entry.entry_id in device_entry.config_entries:
new_identifiers = {(DOMAIN, entry.entry_id)}
_LOGGER.debug(

View file

@ -143,7 +143,6 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
device_entry = None
if entry.unique_id is not None:
device_entry = dev_reg.async_get_device(
identifiers=set(),
connections={(CONNECTION_NETWORK_MAC, format_mac(entry.unique_id))},
)
# https://github.com/home-assistant/core/pull/48076
@ -227,7 +226,6 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
device_entry = None
if entry.unique_id is not None:
device_entry = dev_reg.async_get_device(
identifiers=set(),
connections={(CONNECTION_NETWORK_MAC, format_mac(entry.unique_id))},
)
# https://github.com/home-assistant/core/pull/48076

View file

@ -268,7 +268,7 @@ def _async_register_base_station(
# Check for an old system ID format and remove it:
if old_base_station := device_registry.async_get_device(
{(DOMAIN, system.system_id)} # type: ignore[arg-type]
identifiers={(DOMAIN, system.system_id)} # type: ignore[arg-type]
):
# Update the new base station with any properties the user might have configured
# on the old base station:

View file

@ -119,7 +119,9 @@ async def _remove_device(
device_registry: DeviceRegistry,
) -> None:
"""Remove a discovered Tasmota device."""
device = device_registry.async_get_device(set(), {(CONNECTION_NETWORK_MAC, mac)})
device = device_registry.async_get_device(
connections={(CONNECTION_NETWORK_MAC, mac)}
)
if device is None or config_entry.entry_id not in device.config_entries:
return

View file

@ -223,8 +223,7 @@ async def async_setup_trigger(
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
set(),
{(CONNECTION_NETWORK_MAC, tasmota_trigger.cfg.mac)},
connections={(CONNECTION_NETWORK_MAC, tasmota_trigger.cfg.mac)},
)
if device is None:

View file

@ -302,7 +302,7 @@ async def async_start( # noqa: C901
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
device = device_registry.async_get_device(
set(), {(dr.CONNECTION_NETWORK_MAC, mac)}
connections={(dr.CONNECTION_NETWORK_MAC, mac)}
)
if device is None:

View file

@ -289,7 +289,9 @@ async def async_setup_entry(
)
# migrate to new device ids
device_entry = device_registry.async_get_device({(TIBBER_DOMAIN, old_id)})
device_entry = device_registry.async_get_device(
identifiers={(TIBBER_DOMAIN, old_id)}
)
if device_entry and entry.entry_id in device_entry.config_entries:
device_registry.async_update_device(
device_entry.id, new_identifiers={(TIBBER_DOMAIN, home.home_id)}

View file

@ -178,7 +178,7 @@ class ProtectData:
def _async_remove_device(self, device: ProtectAdoptableDeviceModel) -> None:
registry = dr.async_get(self._hass)
device_entry = registry.async_get_device(
identifiers=set(), connections={(dr.CONNECTION_NETWORK_MAC, device.mac)}
connections={(dr.CONNECTION_NETWORK_MAC, device.mac)}
)
if device_entry:
_LOGGER.debug("Device removed: %s", device.id)

View file

@ -100,7 +100,7 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon
if stale_monitors := current_monitors - new_monitors:
for monitor_id in stale_monitors:
if device := self._device_registry.async_get_device(
{(DOMAIN, monitor_id)}
identifiers={(DOMAIN, monitor_id)}
):
self._device_registry.async_remove_device(device.id)

View file

@ -254,7 +254,7 @@ class DriverEvents:
self.dev_reg, self.config_entry.entry_id
)
known_devices = [
self.dev_reg.async_get_device({get_device_id(driver, node)})
self.dev_reg.async_get_device(identifiers={get_device_id(driver, node)})
for node in controller.nodes.values()
]
@ -401,7 +401,7 @@ class ControllerEvents:
replaced: bool = event.get("replaced", False)
# grab device in device registry attached to this node
dev_id = get_device_id(self.driver_events.driver, node)
device = self.dev_reg.async_get_device({dev_id})
device = self.dev_reg.async_get_device(identifiers={dev_id})
# We assert because we know the device exists
assert device
if replaced:
@ -424,7 +424,7 @@ class ControllerEvents:
driver = self.driver_events.driver
device_id = get_device_id(driver, node)
device_id_ext = get_device_id_ext(driver, node)
device = self.dev_reg.async_get_device({device_id})
device = self.dev_reg.async_get_device(identifiers={device_id})
via_device_id = None
controller = driver.controller
# Get the controller node device ID if this node is not the controller
@ -610,7 +610,7 @@ class NodeEvents:
)
if (
not value.node.ready
or not (device := self.dev_reg.async_get_device({device_id}))
or not (device := self.dev_reg.async_get_device(identifiers={device_id}))
or value.value_id in self.controller_events.discovered_value_ids[device.id]
):
return
@ -632,7 +632,7 @@ class NodeEvents:
"""Relay stateless value notification events from Z-Wave nodes to hass."""
driver = self.controller_events.driver_events.driver
device = self.dev_reg.async_get_device(
{get_device_id(driver, notification.node)}
identifiers={get_device_id(driver, notification.node)}
)
# We assert because we know the device exists
assert device
@ -671,7 +671,7 @@ class NodeEvents:
"notification"
]
device = self.dev_reg.async_get_device(
{get_device_id(driver, notification.node)}
identifiers={get_device_id(driver, notification.node)}
)
# We assert because we know the device exists
assert device
@ -741,7 +741,9 @@ class NodeEvents:
driver = self.controller_events.driver_events.driver
disc_info = value_updates_disc_info[value.value_id]
device = self.dev_reg.async_get_device({get_device_id(driver, value.node)})
device = self.dev_reg.async_get_device(
identifiers={get_device_id(driver, value.node)}
)
# We assert because we know the device exists
assert device

View file

@ -2347,7 +2347,7 @@ def _get_node_statistics_dict(
"""Convert a node to a device id."""
driver = node.client.driver
assert driver
device = dev_reg.async_get_device({get_device_id(driver, node)})
device = dev_reg.async_get_device(identifiers={get_device_id(driver, node)})
assert device
return device.id

View file

@ -232,7 +232,7 @@ async def async_attach_trigger(
assert driver is not None # The node comes from the driver.
drivers.add(driver)
device_identifier = get_device_id(driver, node)
device = dev_reg.async_get_device({device_identifier})
device = dev_reg.async_get_device(identifiers={device_identifier})
assert device
# We need to store the device for the callback
unsubs.append(

View file

@ -179,7 +179,7 @@ async def async_attach_trigger(
assert driver is not None # The node comes from the driver.
drivers.add(driver)
device_identifier = get_device_id(driver, node)
device = dev_reg.async_get_device({device_identifier})
device = dev_reg.async_get_device(identifiers={device_identifier})
assert device
value_id = get_value_id_str(
node, command_class, property_, endpoint, property_key

View file

@ -96,7 +96,7 @@ class ZWaveMeController:
"""Remove old-format devices in the registry."""
for device_id in self.device_ids:
device = registry.async_get_device(
{(DOMAIN, f"{self.config.unique_id}-{device_id}")}
identifiers={(DOMAIN, f"{self.config.unique_id}-{device_id}")}
)
if device is not None:
registry.async_remove_device(device.id)

View file

@ -272,13 +272,14 @@ class DeviceRegistryItems(UserDict[str, _EntryTypeT]):
def get_entry(
self,
identifiers: set[tuple[str, str]],
identifiers: set[tuple[str, str]] | None,
connections: set[tuple[str, str]] | None,
) -> _EntryTypeT | None:
"""Get entry from identifiers or connections."""
for identifier in identifiers:
if identifier in self._identifiers:
return self._identifiers[identifier]
if identifiers:
for identifier in identifiers:
if identifier in self._identifiers:
return self._identifiers[identifier]
if not connections:
return None
for connection in _normalize_connections(connections):
@ -317,7 +318,7 @@ class DeviceRegistry:
@callback
def async_get_device(
self,
identifiers: set[tuple[str, str]],
identifiers: set[tuple[str, str]] | None = None,
connections: set[tuple[str, str]] | None = None,
) -> DeviceEntry | None:
"""Check if device is registered."""
@ -326,7 +327,7 @@ class DeviceRegistry:
def _async_get_deleted_device(
self,
identifiers: set[tuple[str, str]],
connections: set[tuple[str, str]] | None,
connections: set[tuple[str, str]],
) -> DeletedDeviceEntry | None:
"""Check if device is deleted."""
return self.deleted_devices.get_entry(identifiers, connections)
@ -365,7 +366,7 @@ class DeviceRegistry:
else:
connections = _normalize_connections(connections)
device = self.async_get_device(identifiers, connections)
device = self.async_get_device(identifiers=identifiers, connections=connections)
if device is None:
deleted_device = self._async_get_deleted_device(identifiers, connections)
@ -388,7 +389,7 @@ class DeviceRegistry:
name = default_name
if via_device is not None:
via = self.async_get_device({via_device})
via = self.async_get_device(identifiers={via_device})
via_device_id: str | UndefinedType = via.id if via else UNDEFINED
else:
via_device_id = UNDEFINED

View file

@ -102,7 +102,7 @@ async def test_select_entity_registering_device(
) -> None:
"""Test entity registering as an assist device."""
dev_reg = dr.async_get(hass)
device = dev_reg.async_get_device({("test", "test")})
device = dev_reg.async_get_device(identifiers={("test", "test")})
assert device is not None
# Test device is registered

View file

@ -260,7 +260,7 @@ async def test_device_setup_registry(
assert len(device_registry.devices) == 1
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
assert device_entry.identifiers == {(DOMAIN, device.mac)}
assert device_entry.name == device.name
@ -349,7 +349,7 @@ async def test_device_update_listener(
await hass.async_block_till_done()
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
assert device_entry.name == "New Name"
for entry in er.async_entries_for_device(entity_registry, device_entry.id):

View file

@ -33,7 +33,7 @@ async def test_remote_setup_works(
mock_setup = await device.setup_entry(hass)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
remotes = [entry for entry in entries if entry.domain == Platform.REMOTE]
@ -58,7 +58,7 @@ async def test_remote_send_command(
mock_setup = await device.setup_entry(hass)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
remotes = [entry for entry in entries if entry.domain == Platform.REMOTE]
@ -87,7 +87,7 @@ async def test_remote_turn_off_turn_on(
mock_setup = await device.setup_entry(hass)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
remotes = [entry for entry in entries if entry.domain == Platform.REMOTE]

View file

@ -34,7 +34,7 @@ async def test_a1_sensor_setup(
assert mock_api.check_sensors_raw.call_count == 1
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -75,7 +75,7 @@ async def test_a1_sensor_update(
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -121,7 +121,7 @@ async def test_rm_pro_sensor_setup(
assert mock_api.check_sensors.call_count == 1
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -150,7 +150,7 @@ async def test_rm_pro_sensor_update(
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -186,7 +186,7 @@ async def test_rm_pro_filter_crazy_temperature(
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -220,7 +220,7 @@ async def test_rm_mini3_no_sensor(
assert mock_api.check_sensors.call_count <= 1
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -241,7 +241,7 @@ async def test_rm4_pro_hts2_sensor_setup(
assert mock_api.check_sensors.call_count == 1
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -273,7 +273,7 @@ async def test_rm4_pro_hts2_sensor_update(
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -310,7 +310,7 @@ async def test_rm4_pro_no_sensor(
assert mock_api.check_sensors.call_count <= 1
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = {entry for entry in entries if entry.domain == Platform.SENSOR}
@ -341,7 +341,7 @@ async def test_scb1e_sensor_setup(
assert mock_api.get_state.call_count == 1
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]
@ -392,7 +392,7 @@ async def test_scb1e_sensor_update(
mock_setup = await device.setup_entry(hass, mock_api=mock_api)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
sensors = [entry for entry in entries if entry.domain == Platform.SENSOR]

View file

@ -22,7 +22,7 @@ async def test_switch_setup_works(
mock_setup = await device.setup_entry(hass)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
switches = [entry for entry in entries if entry.domain == Platform.SWITCH]
@ -46,7 +46,7 @@ async def test_switch_turn_off_turn_on(
mock_setup = await device.setup_entry(hass)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
switches = [entry for entry in entries if entry.domain == Platform.SWITCH]
@ -82,7 +82,7 @@ async def test_slots_switch_setup_works(
mock_setup = await device.setup_entry(hass)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
switches = [entry for entry in entries if entry.domain == Platform.SWITCH]
@ -107,7 +107,7 @@ async def test_slots_switch_turn_off_turn_on(
mock_setup = await device.setup_entry(hass)
device_entry = device_registry.async_get_device(
{(DOMAIN, mock_setup.entry.unique_id)}
identifiers={(DOMAIN, mock_setup.entry.unique_id)}
)
entries = er.async_entries_for_device(entity_registry, device_entry.id)
switches = [entry for entry in entries if entry.domain == Platform.SWITCH]

View file

@ -112,7 +112,7 @@ async def test_get_triggers_button(hass: HomeAssistant) -> None:
assert len(events) == 1
dev_reg = async_get_dev_reg(hass)
device = dev_reg.async_get_device({get_device_id(mac)})
device = dev_reg.async_get_device(identifiers={get_device_id(mac)})
assert device
expected_trigger = {
CONF_PLATFORM: "device",
@ -148,7 +148,7 @@ async def test_get_triggers_dimmer(hass: HomeAssistant) -> None:
assert len(events) == 1
dev_reg = async_get_dev_reg(hass)
device = dev_reg.async_get_device({get_device_id(mac)})
device = dev_reg.async_get_device(identifiers={get_device_id(mac)})
assert device
expected_trigger = {
CONF_PLATFORM: "device",
@ -243,7 +243,7 @@ async def test_if_fires_on_motion_detected(hass: HomeAssistant, calls) -> None:
await hass.async_block_till_done()
dev_reg = async_get_dev_reg(hass)
device = dev_reg.async_get_device({get_device_id(mac)})
device = dev_reg.async_get_device(identifiers={get_device_id(mac)})
device_id = device.id
assert await async_setup_component(

View file

@ -88,7 +88,7 @@ async def test_sensors_pro(
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2]
assert state.state == data[1]
device = device_registry.async_get_device({(DOMAIN, "20")})
device = device_registry.async_get_device(identifiers={(DOMAIN, "20")})
assert device
assert device.manufacturer == MANUFACTURER
assert device.name == "Dining Room"
@ -208,7 +208,7 @@ async def test_sensors_flex(
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2]
assert state.state == data[1]
device = device_registry.async_get_device({(DOMAIN, "20")})
device = device_registry.async_get_device(identifiers={(DOMAIN, "20")})
assert device
assert device.manufacturer == MANUFACTURER
assert device.name == "Dining Room"

View file

@ -67,7 +67,7 @@ async def test_unique_id_migrate(hass: HomeAssistant, mock_daikin) -> None:
assert config_entry.unique_id == HOST
assert device_registry.async_get_device({}, {(KEY_MAC, HOST)}).name is None
assert device_registry.async_get_device(connections={(KEY_MAC, HOST)}).name is None
entity = entity_registry.async_get("climate.daikin_127_0_0_1")
assert entity.unique_id == HOST
@ -86,7 +86,8 @@ async def test_unique_id_migrate(hass: HomeAssistant, mock_daikin) -> None:
assert config_entry.unique_id == MAC
assert (
device_registry.async_get_device({}, {(KEY_MAC, MAC)}).name == "DaikinAP00000"
device_registry.async_get_device(connections={(KEY_MAC, MAC)}).name
== "DaikinAP00000"
)
entity = entity_registry.async_get("climate.daikin_127_0_0_1")

View file

@ -66,7 +66,7 @@ async def test_device_info(
entry = hass.config_entries.async_entries(DOMAIN)[0]
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
assert device.connections == {("mac", "aa:bb:cc:dd:ee:ff")}
assert device.identifiers == {(DOMAIN, entry.entry_id)}

View file

@ -80,7 +80,9 @@ async def test_device_info(
await hass.config_entries.async_setup(config_entry.entry_id)
assert await async_setup_component(hass, DOMAIN, {})
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, config_entry.unique_id)})
device = device_registry.async_get_device(
identifiers={(DOMAIN, config_entry.unique_id)}
)
assert device.manufacturer == "Dremel"
assert device.model == "3D45"

View file

@ -53,7 +53,7 @@ async def test_device_info(
entry = await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
assert device.configuration_url == "https://engage.efergy.com/user/login"
assert device.connections == {("mac", "ff:ff:ff:ff:ff:ff")}

View file

@ -182,7 +182,7 @@ async def test_light_device_registry(
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers={}, connections={(dr.CONNECTION_NETWORK_MAC, MAC_ADDRESS)}
connections={(dr.CONNECTION_NETWORK_MAC, MAC_ADDRESS)}
)
assert device.sw_version == str(sw_version)
assert device.model == model

View file

@ -56,7 +56,7 @@ async def test_binary_sensor_get_state(
registry = er.async_get(hass)
registry_device = dr.async_get(hass)
device = registry_device.async_get_device({("freedompro", uid)})
device = registry_device.async_get_device(identifiers={("freedompro", uid)})
assert device is not None
assert device.identifiers == {("freedompro", uid)}
assert device.manufacturer == "Freedompro"

View file

@ -33,7 +33,7 @@ async def test_climate_get_state(hass: HomeAssistant, init_integration) -> None:
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({("freedompro", uid)})
device = device_registry.async_get_device(identifiers={("freedompro", uid)})
assert device is not None
assert device.identifiers == {("freedompro", uid)}
assert device.manufacturer == "Freedompro"

View file

@ -47,7 +47,7 @@ async def test_cover_get_state(
registry = er.async_get(hass)
registry_device = dr.async_get(hass)
device = registry_device.async_get_device({("freedompro", uid)})
device = registry_device.async_get_device(identifiers={("freedompro", uid)})
assert device is not None
assert device.identifiers == {("freedompro", uid)}
assert device.manufacturer == "Freedompro"

View file

@ -27,7 +27,7 @@ async def test_fan_get_state(hass: HomeAssistant, init_integration) -> None:
registry = er.async_get(hass)
registry_device = dr.async_get(hass)
device = registry_device.async_get_device({("freedompro", uid)})
device = registry_device.async_get_device(identifiers={("freedompro", uid)})
assert device is not None
assert device.identifiers == {("freedompro", uid)}
assert device.manufacturer == "Freedompro"

View file

@ -26,7 +26,7 @@ async def test_lock_get_state(hass: HomeAssistant, init_integration) -> None:
registry = er.async_get(hass)
registry_device = dr.async_get(hass)
device = registry_device.async_get_device({("freedompro", uid)})
device = registry_device.async_get_device(identifiers={("freedompro", uid)})
assert device is not None
assert device.identifiers == {("freedompro", uid)}
assert device.manufacturer == "Freedompro"

View file

@ -24,7 +24,7 @@ async def test_diagnostics(
"""Test Fully Kiosk diagnostics."""
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, "abcdef-123456")})
device = device_registry.async_get_device(identifiers={(DOMAIN, "abcdef-123456")})
diagnostics = await get_diagnostics_for_device(
hass, hass_client, init_integration, device

View file

@ -72,7 +72,7 @@ async def test_device_info(
entry = await async_init_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
assert device.connections == {("mac", "12:34:56:78:90:12")}
assert device.identifiers == {(DOMAIN, entry.entry_id)}

View file

@ -334,7 +334,7 @@ async def test_device_info_ismartgate(
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
device = device_registry.async_get_device({(DOMAIN, "xyz")})
device = device_registry.async_get_device(identifiers={(DOMAIN, "xyz")})
assert device
assert device.manufacturer == MANUFACTURER
assert device.name == "mycontroller"
@ -369,7 +369,7 @@ async def test_device_info_gogogate2(
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
device = device_registry.async_get_device({(DOMAIN, "xyz")})
device = device_registry.async_get_device(identifiers={(DOMAIN, "xyz")})
assert device
assert device.manufacturer == MANUFACTURER
assert device.name == "mycontroller"

View file

@ -123,7 +123,7 @@ async def test_device_info(
device_registry = dr.async_get(hass)
entry = hass.config_entries.async_entries(DOMAIN)[0]
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
assert device.entry_type is dr.DeviceEntryType.SERVICE
assert device.identifiers == {(DOMAIN, entry.entry_id)}

View file

@ -263,7 +263,7 @@ async def test_updates_from_players_changed_new_ids(
event = asyncio.Event()
# Assert device registry matches current id
assert device_registry.async_get_device({(DOMAIN, 1)})
assert device_registry.async_get_device(identifiers={(DOMAIN, 1)})
# Assert entity registry matches current id
assert (
entity_registry.async_get_entity_id(MEDIA_PLAYER_DOMAIN, DOMAIN, "1")
@ -284,7 +284,7 @@ async def test_updates_from_players_changed_new_ids(
# Assert device registry identifiers were updated
assert len(device_registry.devices) == 2
assert device_registry.async_get_device({(DOMAIN, 101)})
assert device_registry.async_get_device(identifiers={(DOMAIN, 101)})
# Assert entity registry unique id was updated
assert len(entity_registry.entities) == 2
assert (

View file

@ -55,7 +55,7 @@ def one_entity_state(hass, device_uid):
entity_reg = er.async_get(hass)
device_reg = dr.async_get(hass)
device_id = device_reg.async_get_device({(DOMAIN, device_uid)}).id
device_id = device_reg.async_get_device(identifiers={(DOMAIN, device_uid)}).id
entity_entries = er.async_entries_for_device(entity_reg, device_id)
assert len(entity_entries) == 1

View file

@ -744,7 +744,7 @@ async def test_homekit_start(
assert device_registry.async_get(bridge_with_wrong_mac.id) is None
device = device_registry.async_get_device(
{(DOMAIN, entry.entry_id, BRIDGE_SERIAL_NUMBER)}
identifiers={(DOMAIN, entry.entry_id, BRIDGE_SERIAL_NUMBER)}
)
assert device
formatted_mac = dr.format_mac(homekit.driver.state.mac)
@ -760,7 +760,7 @@ async def test_homekit_start(
await homekit.async_start()
device = device_registry.async_get_device(
{(DOMAIN, entry.entry_id, BRIDGE_SERIAL_NUMBER)}
identifiers={(DOMAIN, entry.entry_id, BRIDGE_SERIAL_NUMBER)}
)
assert device
formatted_mac = dr.format_mac(homekit.driver.state.mac)
@ -953,7 +953,7 @@ async def test_homekit_unpair(
formatted_mac = dr.format_mac(state.mac)
hk_bridge_dev = device_registry.async_get_device(
{}, {(dr.CONNECTION_NETWORK_MAC, formatted_mac)}
connections={(dr.CONNECTION_NETWORK_MAC, formatted_mac)}
)
await hass.services.async_call(

View file

@ -325,9 +325,7 @@ async def assert_devices_and_entities_created(
# we have detected broken serial numbers (and serial number is not used as an identifier).
device = device_registry.async_get_device(
{
(IDENTIFIER_ACCESSORY_ID, expected.unique_id),
}
identifiers={(IDENTIFIER_ACCESSORY_ID, expected.unique_id)}
)
logger.debug("Comparing device %r to %r", device, expected)

View file

@ -29,7 +29,7 @@ async def test_get_triggers(
# Get triggers for specific tap switch
hue_tap_device = device_reg.async_get_device(
{(hue.DOMAIN, "00:00:00:00:00:44:23:08")}
identifiers={(hue.DOMAIN, "00:00:00:00:00:44:23:08")}
)
triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, hue_tap_device.id
@ -50,7 +50,7 @@ async def test_get_triggers(
# Get triggers for specific dimmer switch
hue_dimmer_device = device_reg.async_get_device(
{(hue.DOMAIN, "00:17:88:01:10:3e:3a:dc")}
identifiers={(hue.DOMAIN, "00:17:88:01:10:3e:3a:dc")}
)
hue_bat_sensor = entity_registry.async_get(
"sensor.hue_dimmer_switch_1_battery_level"
@ -95,7 +95,7 @@ async def test_if_fires_on_state_change(
# Set an automation with a specific tap switch trigger
hue_tap_device = device_reg.async_get_device(
{(hue.DOMAIN, "00:00:00:00:00:44:23:08")}
identifiers={(hue.DOMAIN, "00:00:00:00:00:44:23:08")}
)
assert await async_setup_component(
hass,

View file

@ -60,7 +60,7 @@ async def test_get_triggers(
# Get triggers for `Wall switch with 2 controls`
hue_wall_switch_device = device_reg.async_get_device(
{(hue.DOMAIN, "3ff06175-29e8-44a8-8fe7-af591b0025da")}
identifiers={(hue.DOMAIN, "3ff06175-29e8-44a8-8fe7-af591b0025da")}
)
hue_bat_sensor = entity_registry.async_get(
"sensor.wall_switch_with_2_controls_battery"

View file

@ -460,7 +460,7 @@ async def test_hue_events(hass: HomeAssistant, mock_bridge_v1, device_reg) -> No
assert len(events) == 0
hue_tap_device = device_reg.async_get_device(
{(hue.DOMAIN, "00:00:00:00:00:44:23:08")}
identifiers={(hue.DOMAIN, "00:00:00:00:00:44:23:08")}
)
mock_bridge_v1.api.sensors["7"].last_event = {"type": "button"}
@ -492,7 +492,7 @@ async def test_hue_events(hass: HomeAssistant, mock_bridge_v1, device_reg) -> No
}
hue_dimmer_device = device_reg.async_get_device(
{(hue.DOMAIN, "00:17:88:01:10:3e:3a:dc")}
identifiers={(hue.DOMAIN, "00:17:88:01:10:3e:3a:dc")}
)
new_sensor_response = dict(new_sensor_response)
@ -595,7 +595,7 @@ async def test_hue_events(hass: HomeAssistant, mock_bridge_v1, device_reg) -> No
await hass.async_block_till_done()
hue_aurora_device = device_reg.async_get_device(
{(hue.DOMAIN, "ff:ff:00:0f:e7:fd:bc:b7")}
identifiers={(hue.DOMAIN, "ff:ff:00:0f:e7:fd:bc:b7")}
)
assert len(mock_bridge_v1.mock_requests) == 6

View file

@ -192,7 +192,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
device_id = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, device_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, device_id)})
assert device
assert device.config_entries == {TEST_CONFIG_ENTRY_ID}
assert device.identifiers == {(DOMAIN, device_id)}

View file

@ -775,7 +775,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
device_id = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, device_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, device_id)})
assert device
assert device.config_entries == {TEST_CONFIG_ENTRY_ID}
assert device.identifiers == {(DOMAIN, device_id)}

View file

@ -164,7 +164,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
device_identifer = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, device_identifer)})
device = device_registry.async_get_device(identifiers={(DOMAIN, device_identifer)})
assert device
assert device.config_entries == {TEST_CONFIG_ENTRY_ID}
assert device.identifiers == {(DOMAIN, device_identifer)}

View file

@ -49,13 +49,12 @@ async def test_device_remove_devices(
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device(
{
identifiers={
(
DOMAIN,
"426c7565-4368-6172-6d42-6561636f6e73_3838_4949_61DE521B-F0BF-9F44-64D4-75BBE1738105",
)
},
{},
)
assert (
await remove_device(await hass_ws_client(hass), device_entry.id, entry.entry_id)

View file

@ -128,6 +128,6 @@ def get_device(hass, entry, address):
"""Get LCN device for specified address."""
device_registry = dr.async_get(hass)
identifiers = {(DOMAIN, generate_unique_id(entry.entry_id, address))}
device = device_registry.async_get_device(identifiers)
device = device_registry.async_get_device(identifiers=identifiers)
assert device
return device

View file

@ -55,10 +55,12 @@ async def test_get_triggers_non_module_device(
not_included_types = ("transmitter", "transponder", "fingerprint", "send_keys")
device_registry = dr.async_get(hass)
host_device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
host_device = device_registry.async_get_device(
identifiers={(DOMAIN, entry.entry_id)}
)
group_device = get_device(hass, entry, (0, 5, True))
resource_device = device_registry.async_get_device(
{(DOMAIN, f"{entry.entry_id}-m000007-output1")}
identifiers={(DOMAIN, f"{entry.entry_id}-m000007-output1")}
)
for device in (host_device, group_device, resource_device):

View file

@ -52,7 +52,7 @@ async def test_device_info(
entry = hass.config_entries.async_entries(DOMAIN)[0]
device_registry = dr.async_get(hass)
await hass.async_block_till_done()
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
assert device.configuration_url == "http://127.0.0.1:8668"
assert device.identifiers == {(DOMAIN, entry.entry_id)}

View file

@ -100,7 +100,7 @@ async def test_light_unique_id(hass: HomeAssistant) -> None:
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers=set(), connections={(dr.CONNECTION_NETWORK_MAC, SERIAL)}
connections={(dr.CONNECTION_NETWORK_MAC, SERIAL)}
)
assert device.identifiers == {(DOMAIN, SERIAL)}
@ -123,7 +123,6 @@ async def test_light_unique_id_new_firmware(hass: HomeAssistant) -> None:
assert entity_registry.async_get(entity_id).unique_id == SERIAL
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(
identifiers=set(),
connections={(dr.CONNECTION_NETWORK_MAC, MAC_ADDRESS)},
)
assert device.identifiers == {(DOMAIN, SERIAL)}

View file

@ -41,7 +41,9 @@ async def test_device_registry_single_node_device(
dev_reg = dr.async_get(hass)
entry = dev_reg.async_get_device(
{(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")}
identifiers={
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
}
)
assert entry is not None
@ -70,7 +72,9 @@ async def test_device_registry_single_node_device_alt(
dev_reg = dr.async_get(hass)
entry = dev_reg.async_get_device(
{(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")}
identifiers={
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
}
)
assert entry is not None
@ -96,7 +100,7 @@ async def test_device_registry_bridge(
dev_reg = dr.async_get(hass)
# Validate bridge
bridge_entry = dev_reg.async_get_device({(DOMAIN, "mock-hub-id")})
bridge_entry = dev_reg.async_get_device(identifiers={(DOMAIN, "mock-hub-id")})
assert bridge_entry is not None
assert bridge_entry.name == "My Mock Bridge"
@ -106,7 +110,9 @@ async def test_device_registry_bridge(
assert bridge_entry.sw_version == "123.4.5"
# Device 1
device1_entry = dev_reg.async_get_device({(DOMAIN, "mock-id-kitchen-ceiling")})
device1_entry = dev_reg.async_get_device(
identifiers={(DOMAIN, "mock-id-kitchen-ceiling")}
)
assert device1_entry is not None
assert device1_entry.via_device_id == bridge_entry.id
@ -117,7 +123,9 @@ async def test_device_registry_bridge(
assert device1_entry.sw_version == "67.8.9"
# Device 2
device2_entry = dev_reg.async_get_device({(DOMAIN, "mock-id-living-room-ceiling")})
device2_entry = dev_reg.async_get_device(
identifiers={(DOMAIN, "mock-id-living-room-ceiling")}
)
assert device2_entry is not None
assert device2_entry.via_device_id == bridge_entry.id

View file

@ -857,7 +857,9 @@ async def test_webhook_handle_scan_tag(
hass: HomeAssistant, create_registrations, webhook_client
) -> None:
"""Test that we can scan tags."""
device = dr.async_get(hass).async_get_device({(DOMAIN, "mock-device-id")})
device = dr.async_get(hass).async_get_device(
identifiers={(DOMAIN, "mock-device-id")}
)
assert device is not None
events = async_capture_events(hass, EVENT_TAG_SCANNED)

View file

@ -159,15 +159,17 @@ async def test_setup_camera_new_data_camera_removed(hass: HomeAssistant) -> None
await hass.async_block_till_done()
assert hass.states.get(TEST_CAMERA_ENTITY_ID)
assert device_registry.async_get_device({TEST_CAMERA_DEVICE_IDENTIFIER})
assert device_registry.async_get_device(identifiers={TEST_CAMERA_DEVICE_IDENTIFIER})
client.async_get_cameras = AsyncMock(return_value={KEY_CAMERAS: []})
async_fire_time_changed(hass, dt_util.utcnow() + DEFAULT_SCAN_INTERVAL)
await hass.async_block_till_done()
await hass.async_block_till_done()
assert not hass.states.get(TEST_CAMERA_ENTITY_ID)
assert not device_registry.async_get_device({TEST_CAMERA_DEVICE_IDENTIFIER})
assert not device_registry.async_get_device({(DOMAIN, old_device_id)})
assert not device_registry.async_get_device(
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}
)
assert not device_registry.async_get_device(identifiers={(DOMAIN, old_device_id)})
assert not entity_registry.async_get_entity_id(
DOMAIN, "camera", old_entity_unique_id
)
@ -320,7 +322,7 @@ async def test_device_info(hass: HomeAssistant) -> None:
device_identifier = get_motioneye_device_identifier(entry.entry_id, TEST_CAMERA_ID)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({device_identifier})
device = device_registry.async_get_device(identifiers={device_identifier})
assert device
assert device.config_entries == {TEST_CONFIG_ENTRY_ID}
assert device.identifiers == {device_identifier}

View file

@ -88,7 +88,7 @@ async def test_sensor_device_info(hass: HomeAssistant) -> None:
)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({device_identifer})
device = device_registry.async_get_device(identifiers={device_identifer})
assert device
entity_registry = er.async_get(hass)

View file

@ -193,7 +193,7 @@ async def test_switch_device_info(hass: HomeAssistant) -> None:
)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({device_identifer})
device = device_registry.async_get_device(identifiers={device_identifer})
assert device
entity_registry = er.async_get(hass)

View file

@ -1001,7 +1001,7 @@ async def help_test_entity_device_info_with_identifier(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.identifiers == {("mqtt", "helloworld")}
assert device.manufacturer == "Whatever"
@ -1036,7 +1036,7 @@ async def help_test_entity_device_info_with_connection(
await hass.async_block_till_done()
device = registry.async_get_device(
set(), {(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
)
assert device is not None
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
@ -1069,14 +1069,14 @@ async def help_test_entity_device_info_remove(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = dev_registry.async_get_device({("mqtt", "helloworld")})
device = dev_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert ent_registry.async_get_entity_id(domain, mqtt.DOMAIN, "veryunique")
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", "")
await hass.async_block_till_done()
device = dev_registry.async_get_device({("mqtt", "helloworld")})
device = dev_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is None
assert not ent_registry.async_get_entity_id(domain, mqtt.DOMAIN, "veryunique")
@ -1103,7 +1103,7 @@ async def help_test_entity_device_info_update(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.name == "Beer"
@ -1112,7 +1112,7 @@ async def help_test_entity_device_info_update(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.name == "Milk"
@ -1232,7 +1232,7 @@ async def help_test_entity_debug_info(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -1272,7 +1272,7 @@ async def help_test_entity_debug_info_max_messages(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -1352,7 +1352,7 @@ async def help_test_entity_debug_info_message(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -1443,7 +1443,7 @@ async def help_test_entity_debug_info_remove(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -1493,7 +1493,7 @@ async def help_test_entity_debug_info_update_entity_id(
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
await hass.async_block_till_done()
device = device_registry.async_get_device({("mqtt", "helloworld")})
device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -1555,7 +1555,7 @@ async def help_test_entity_disabled_by_default(
await hass.async_block_till_done()
entity_id = ent_registry.async_get_entity_id(domain, mqtt.DOMAIN, "veryunique1")
assert entity_id is not None and hass.states.get(entity_id) is None
assert dev_registry.async_get_device({("mqtt", "helloworld")})
assert dev_registry.async_get_device(identifiers={("mqtt", "helloworld")})
# Discover an enabled entity, tied to the same device
config["enabled_by_default"] = True
@ -1571,7 +1571,7 @@ async def help_test_entity_disabled_by_default(
await hass.async_block_till_done()
assert not ent_registry.async_get_entity_id(domain, mqtt.DOMAIN, "veryunique1")
assert not ent_registry.async_get_entity_id(domain, mqtt.DOMAIN, "veryunique2")
assert not dev_registry.async_get_device({("mqtt", "helloworld")})
assert not dev_registry.async_get_device(identifiers={("mqtt", "helloworld")})
async def help_test_entity_category(

View file

@ -249,7 +249,7 @@ async def test_cleanup_device_tracker(
await hass.async_block_till_done()
# Verify device and registry entries are created
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is not None
entity_entry = entity_registry.async_get("device_tracker.mqtt_unique")
assert entity_entry is not None
@ -273,7 +273,7 @@ async def test_cleanup_device_tracker(
await hass.async_block_till_done()
# Verify device and registry entries are cleared
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is None
entity_entry = entity_registry.async_get("device_tracker.mqtt_unique")
assert entity_entry is None

View file

@ -64,7 +64,7 @@ async def test_get_triggers(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
expected_triggers = [
{
"platform": "device",
@ -98,7 +98,7 @@ async def test_get_unknown_triggers(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -145,7 +145,7 @@ async def test_get_non_existing_triggers(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id
)
@ -171,7 +171,7 @@ async def test_discover_bad_triggers(
)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data0)
await hass.async_block_till_done()
assert device_registry.async_get_device({("mqtt", "0AFFD2")}) is None
assert device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")}) is None
# Test sending correct data
data1 = (
@ -185,7 +185,7 @@ async def test_discover_bad_triggers(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
expected_triggers = [
{
"platform": "device",
@ -235,7 +235,7 @@ async def test_update_remove_triggers(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
expected_triggers1 = [
{
"platform": "device",
@ -268,7 +268,7 @@ async def test_update_remove_triggers(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", "")
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is None
@ -299,7 +299,7 @@ async def test_if_fires_on_mqtt_message(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla2/config", data2)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -380,7 +380,7 @@ async def test_if_fires_on_mqtt_message_template(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla2/config", data2)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -463,7 +463,7 @@ async def test_if_fires_on_mqtt_message_late_discover(
)
async_fire_mqtt_message(hass, "homeassistant/sensor/bla0/config", data0)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -543,7 +543,7 @@ async def test_if_fires_on_mqtt_message_after_update(
)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -615,7 +615,7 @@ async def test_no_resubscribe_same_topic(
)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -663,7 +663,7 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -735,7 +735,7 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,
@ -801,7 +801,7 @@ async def test_attach_remove(
)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
calls = []
@ -864,7 +864,7 @@ async def test_attach_remove_late(
)
async_fire_mqtt_message(hass, "homeassistant/sensor/bla0/config", data0)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
calls = []
@ -930,7 +930,7 @@ async def test_attach_remove_late2(
)
async_fire_mqtt_message(hass, "homeassistant/sensor/bla0/config", data0)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
calls = []
@ -999,7 +999,7 @@ async def test_entity_device_info_with_connection(
await hass.async_block_till_done()
device = registry.async_get_device(
set(), {(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
)
assert device is not None
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
@ -1036,7 +1036,7 @@ async def test_entity_device_info_with_identifier(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.identifiers == {("mqtt", "helloworld")}
assert device.manufacturer == "Whatever"
@ -1072,7 +1072,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.name == "Beer"
@ -1081,7 +1081,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.name == "Milk"
@ -1110,7 +1110,9 @@ async def test_cleanup_trigger(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1134,7 +1136,9 @@ async def test_cleanup_trigger(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
# Verify retained discovery topic has been cleared
@ -1163,7 +1167,9 @@ async def test_cleanup_device(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1175,7 +1181,9 @@ async def test_cleanup_device(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -1210,7 +1218,9 @@ async def test_cleanup_device_several_triggers(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1224,7 +1234,9 @@ async def test_cleanup_device_several_triggers(
await hass.async_block_till_done()
# Verify device registry entry is not cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1237,7 +1249,9 @@ async def test_cleanup_device_several_triggers(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -1274,7 +1288,9 @@ async def test_cleanup_device_with_entity1(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1286,7 +1302,9 @@ async def test_cleanup_device_with_entity1(
await hass.async_block_till_done()
# Verify device registry entry is not cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1298,7 +1316,9 @@ async def test_cleanup_device_with_entity1(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -1335,7 +1355,9 @@ async def test_cleanup_device_with_entity2(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1347,7 +1369,9 @@ async def test_cleanup_device_with_entity2(
await hass.async_block_till_done()
# Verify device registry entry is not cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -1359,7 +1383,9 @@ async def test_cleanup_device_with_entity2(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -1404,7 +1430,7 @@ async def test_trigger_debug_info(
await hass.async_block_till_done()
device = registry.async_get_device(
set(), {(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
)
assert device is not None
@ -1457,7 +1483,7 @@ async def test_unload_entry(
)
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", data1)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert await async_setup_component(
hass,

View file

@ -75,7 +75,7 @@ async def test_entry_diagnostics(
)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
expected_debug_info = {
"entities": [
@ -190,7 +190,7 @@ async def test_redact_diagnostics(
async_fire_mqtt_message(hass, "attributes-topic", location_data)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
expected_debug_info = {
"entities": [

View file

@ -727,7 +727,7 @@ async def test_cleanup_device(
await hass.async_block_till_done()
# Verify device and registry entries are created
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is not None
entity_entry = entity_registry.async_get("sensor.mqtt_sensor")
assert entity_entry is not None
@ -751,7 +751,7 @@ async def test_cleanup_device(
await hass.async_block_till_done()
# Verify device and registry entries are cleared
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is None
entity_entry = entity_registry.async_get("sensor.mqtt_sensor")
assert entity_entry is None
@ -786,7 +786,7 @@ async def test_cleanup_device_mqtt(
await hass.async_block_till_done()
# Verify device and registry entries are created
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is not None
entity_entry = entity_registry.async_get("sensor.mqtt_sensor")
assert entity_entry is not None
@ -799,7 +799,7 @@ async def test_cleanup_device_mqtt(
await hass.async_block_till_done()
# Verify device and registry entries are cleared
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is None
entity_entry = entity_registry.async_get("sensor.mqtt_sensor")
assert entity_entry is None
@ -866,7 +866,7 @@ async def test_cleanup_device_multiple_config_entries(
# Verify device and registry entries are created
device_entry = device_registry.async_get_device(
set(), {("mac", "12:34:56:AB:CD:EF")}
connections={("mac", "12:34:56:AB:CD:EF")}
)
assert device_entry is not None
assert device_entry.config_entries == {
@ -897,7 +897,7 @@ async def test_cleanup_device_multiple_config_entries(
# Verify device is still there but entity is cleared
device_entry = device_registry.async_get_device(
set(), {("mac", "12:34:56:AB:CD:EF")}
connections={("mac", "12:34:56:AB:CD:EF")}
)
assert device_entry is not None
entity_entry = entity_registry.async_get("sensor.mqtt_sensor")
@ -966,7 +966,7 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
# Verify device and registry entries are created
device_entry = device_registry.async_get_device(
set(), {("mac", "12:34:56:AB:CD:EF")}
connections={("mac", "12:34:56:AB:CD:EF")}
)
assert device_entry is not None
assert device_entry.config_entries == {
@ -989,7 +989,7 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
# Verify device is still there but entity is cleared
device_entry = device_registry.async_get_device(
set(), {("mac", "12:34:56:AB:CD:EF")}
connections={("mac", "12:34:56:AB:CD:EF")}
)
assert device_entry is not None
entity_entry = entity_registry.async_get("sensor.mqtt_sensor")
@ -1518,7 +1518,7 @@ async def test_clear_config_topic_disabled_entity(
# Verify device is created
device_entry = device_registry.async_get_device(
set(), {("mac", "12:34:56:AB:CD:EF")}
connections={("mac", "12:34:56:AB:CD:EF")}
)
assert device_entry is not None
@ -1584,7 +1584,7 @@ async def test_clean_up_registry_monitoring(
# Verify device is created
device_entry = device_registry.async_get_device(
set(), {("mac", "12:34:56:AB:CD:EF")}
connections={("mac", "12:34:56:AB:CD:EF")}
)
assert device_entry is not None

View file

@ -2604,7 +2604,7 @@ async def test_default_entry_setting_are_applied(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is not None
@ -2757,7 +2757,7 @@ async def test_mqtt_ws_remove_discovered_device(
await hass.async_block_till_done()
# Verify device entry is created
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is not None
client = await hass_ws_client(hass)
@ -2774,7 +2774,7 @@ async def test_mqtt_ws_remove_discovered_device(
assert response["success"]
# Verify device entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is None
@ -2809,7 +2809,7 @@ async def test_mqtt_ws_get_device_debug_info(
await hass.async_block_till_done()
# Verify device entry is created
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is not None
client = await hass_ws_client(hass)
@ -2864,7 +2864,7 @@ async def test_mqtt_ws_get_device_debug_info_binary(
await hass.async_block_till_done()
# Verify device entry is created
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
assert device_entry is not None
small_png = (
@ -2971,7 +2971,7 @@ async def test_debug_info_multiple_devices(
for dev in devices:
domain = dev["domain"]
id = dev["config"]["device"]["identifiers"][0]
device = registry.async_get_device({("mqtt", id)})
device = registry.async_get_device(identifiers={("mqtt", id)})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3052,7 +3052,7 @@ async def test_debug_info_multiple_entities_triggers(
await hass.async_block_till_done()
device_id = config[0]["config"]["device"]["identifiers"][0]
device = registry.async_get_device({("mqtt", device_id)})
device = registry.async_get_device(identifiers={("mqtt", device_id)})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
assert len(debug_info_data["entities"]) == 2
@ -3132,7 +3132,7 @@ async def test_debug_info_wildcard(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3180,7 +3180,7 @@ async def test_debug_info_filter_same(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3241,7 +3241,7 @@ async def test_debug_info_same_topic(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3294,7 +3294,7 @@ async def test_debug_info_qos_retain(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id)

View file

@ -1142,7 +1142,7 @@ async def test_entity_device_info_with_hub(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.via_device_id == hub.id

View file

@ -75,13 +75,13 @@ async def test_discover_bad_tag(
data0 = '{ "device":{"identifiers":["0AFFD2"]}, "topics": "foobar/tag_scanned" }'
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data0)
await hass.async_block_till_done()
assert device_registry.async_get_device({("mqtt", "0AFFD2")}) is None
assert device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")}) is None
# Test sending correct data
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", json.dumps(config1))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan.
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN)
await hass.async_block_till_done()
@ -100,7 +100,7 @@ async def test_if_fires_on_mqtt_message_with_device(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan.
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN)
@ -138,7 +138,7 @@ async def test_if_fires_on_mqtt_message_with_template(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan.
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN_JSON)
@ -180,7 +180,7 @@ async def test_if_fires_on_mqtt_message_after_update_with_device(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config1))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan.
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN)
@ -275,7 +275,7 @@ async def test_if_fires_on_mqtt_message_after_update_with_template(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config1))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan.
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN_JSON)
@ -320,7 +320,7 @@ async def test_no_resubscribe_same_topic(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
await hass.async_block_till_done()
assert device_registry.async_get_device({("mqtt", "0AFFD2")})
assert device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
call_count = mqtt_mock.async_subscribe.call_count
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
@ -340,7 +340,7 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_with_device(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan.
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN)
@ -417,7 +417,7 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan.
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN)
@ -467,7 +467,7 @@ async def test_entity_device_info_with_connection(
await hass.async_block_till_done()
device = registry.async_get_device(
set(), {(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
)
assert device is not None
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
@ -501,7 +501,7 @@ async def test_entity_device_info_with_identifier(
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.identifiers == {("mqtt", "helloworld")}
assert device.manufacturer == "Whatever"
@ -534,7 +534,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.name == "Beer"
@ -543,7 +543,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data)
await hass.async_block_till_done()
device = registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None
assert device.name == "Milk"
@ -588,20 +588,24 @@ async def test_cleanup_tag(
await hass.async_block_till_done()
# Verify device registry entries are created
device_entry1 = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry1 = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry1 is not None
assert device_entry1.config_entries == {config_entry.entry_id, mqtt_entry.entry_id}
device_entry2 = device_registry.async_get_device({("mqtt", "hejhopp")})
device_entry2 = device_registry.async_get_device(identifiers={("mqtt", "hejhopp")})
assert device_entry2 is not None
# Remove other config entry from the device
device_registry.async_update_device(
device_entry1.id, remove_config_entry_id=config_entry.entry_id
)
device_entry1 = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry1 = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry1 is not None
assert device_entry1.config_entries == {mqtt_entry.entry_id}
device_entry2 = device_registry.async_get_device({("mqtt", "hejhopp")})
device_entry2 = device_registry.async_get_device(identifiers={("mqtt", "hejhopp")})
assert device_entry2 is not None
mqtt_mock.async_publish.assert_not_called()
@ -621,9 +625,11 @@ async def test_cleanup_tag(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry1 = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry1 = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry1 is None
device_entry2 = device_registry.async_get_device({("mqtt", "hejhopp")})
device_entry2 = device_registry.async_get_device(identifiers={("mqtt", "hejhopp")})
assert device_entry2 is not None
# Verify retained discovery topic has been cleared
@ -649,14 +655,18 @@ async def test_cleanup_device(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", "")
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -684,14 +694,18 @@ async def test_cleanup_device_several_tags(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", "")
await hass.async_block_till_done()
# Verify device registry entry is not cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
# Fake tag scan.
@ -704,7 +718,9 @@ async def test_cleanup_device_several_tags(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -749,7 +765,9 @@ async def test_cleanup_device_with_entity_and_trigger_1(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -761,7 +779,9 @@ async def test_cleanup_device_with_entity_and_trigger_1(
await hass.async_block_till_done()
# Verify device registry entry is not cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla2/config", "")
@ -771,7 +791,9 @@ async def test_cleanup_device_with_entity_and_trigger_1(
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -816,7 +838,9 @@ async def test_cleanup_device_with_entity2(
await hass.async_block_till_done()
# Verify device registry entry is created
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
triggers = await async_get_device_automations(
@ -831,14 +855,18 @@ async def test_cleanup_device_with_entity2(
await hass.async_block_till_done()
# Verify device registry entry is not cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is not None
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", "")
await hass.async_block_till_done()
# Verify device registry entry is cleared
device_entry = device_registry.async_get_device({("mqtt", "helloworld")})
device_entry = device_registry.async_get_device(
identifiers={("mqtt", "helloworld")}
)
assert device_entry is None
@ -899,7 +927,7 @@ async def test_unload_entry(
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
await hass.async_block_till_done()
device_entry = device_registry.async_get_device({("mqtt", "0AFFD2")})
device_entry = device_registry.async_get_device(identifiers={("mqtt", "0AFFD2")})
# Fake tag scan, should be processed
async_fire_mqtt_message(hass, "foobar/tag_scanned", DEFAULT_TAG_SCAN)

View file

@ -103,7 +103,7 @@ async def test_get_triggers(
await setup_platform()
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device({("nest", DEVICE_ID)})
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
expected_triggers = [
{
@ -198,7 +198,7 @@ async def test_triggers_for_invalid_device_id(
await setup_platform()
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device({("nest", DEVICE_ID)})
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
assert device_entry is not None
# Create an additional device that does not exist. Fetching supported
@ -324,7 +324,7 @@ async def test_subscriber_automation(
await setup_platform()
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device({("nest", DEVICE_ID)})
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
assert await setup_automation(hass, device_entry.id, "camera_motion")

View file

@ -117,7 +117,7 @@ async def test_device_diagnostics(
assert config_entry.state is ConfigEntryState.LOADED
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, NEST_DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, NEST_DEVICE_ID)})
assert device is not None
assert (

View file

@ -256,7 +256,7 @@ async def test_supported_device(hass: HomeAssistant, setup_platform) -> None:
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -318,7 +318,7 @@ async def test_camera_event(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -448,7 +448,7 @@ async def test_event_order(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -493,7 +493,7 @@ async def test_multiple_image_events_in_session(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -607,7 +607,7 @@ async def test_multiple_clip_preview_events_in_session(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -695,7 +695,7 @@ async def test_browse_invalid_device_id(
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -716,7 +716,7 @@ async def test_browse_invalid_event_id(
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -739,7 +739,7 @@ async def test_resolve_missing_event_id(
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -771,7 +771,7 @@ async def test_resolve_invalid_event_id(
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -819,7 +819,7 @@ async def test_camera_event_clip_preview(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -916,7 +916,7 @@ async def test_event_media_render_invalid_event_id(
"""Test event media API called with an invalid device id."""
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -958,7 +958,7 @@ async def test_event_media_failure(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -998,7 +998,7 @@ async def test_media_permission_unauthorized(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -1034,9 +1034,9 @@ async def test_multiple_devices(
await setup_platform()
device_registry = dr.async_get(hass)
device1 = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device1 = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device1
device2 = device_registry.async_get_device({(DOMAIN, device_id2)})
device2 = device_registry.async_get_device(identifiers={(DOMAIN, device_id2)})
assert device2
# Very no events have been received yet
@ -1121,7 +1121,7 @@ async def test_media_store_persistence(
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -1174,7 +1174,7 @@ async def test_media_store_persistence(
await hass.async_block_till_done()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -1233,7 +1233,7 @@ async def test_media_store_save_filesystem_error(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -1272,7 +1272,7 @@ async def test_media_store_load_filesystem_error(
assert camera is not None
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -1322,7 +1322,7 @@ async def test_camera_event_media_eviction(
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME
@ -1399,7 +1399,7 @@ async def test_camera_image_resize(
await setup_platform()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, DEVICE_ID)})
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
assert device
assert device.name == DEVICE_NAME

View file

@ -161,7 +161,7 @@ async def test_if_fires_on_event(
},
)
device = device_registry.async_get_device(set(), {connection})
device = device_registry.async_get_device(connections={connection})
assert device is not None
# Fake that the entity is turning on.
@ -244,7 +244,7 @@ async def test_if_fires_on_event_legacy(
},
)
device = device_registry.async_get_device(set(), {connection})
device = device_registry.async_get_device(connections={connection})
assert device is not None
# Fake that the entity is turning on.
@ -328,7 +328,7 @@ async def test_if_fires_on_event_with_subtype(
},
)
device = device_registry.async_get_device(set(), {connection})
device = device_registry.async_get_device(connections={connection})
assert device is not None
# Fake that the entity is turning on.

View file

@ -288,7 +288,9 @@ async def test_options_remove_sensor(
assert result["step_id"] == "remove_sensor"
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device({(DOMAIN, str(TEST_SENSOR_INDEX1))})
device_entry = device_registry.async_get_device(
identifiers={(DOMAIN, str(TEST_SENSOR_INDEX1))}
)
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"sensor_device_id": device_entry.id},

View file

@ -51,7 +51,7 @@ async def test_device_info(
entry = await setup_integration(hass, aioclient_mock)
device_registry = dr.async_get(hass)
await hass.async_block_till_done()
device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
device = device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
assert device.configuration_url == "http://192.168.1.189:7887/test"
assert device.identifiers == {(DOMAIN, entry.entry_id)}

View file

@ -67,7 +67,7 @@ async def test_set_value(
assert await setup_integration()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, SERIAL_NUMBER)})
device = device_registry.async_get_device(identifiers={(DOMAIN, SERIAL_NUMBER)})
assert device
assert device.name == "Rain Bird Controller"
assert device.model == "ST8x-WiFi"

View file

@ -37,7 +37,9 @@ def check_device_registry(
) -> None:
"""Ensure that the expected_device is correctly registered."""
assert len(device_registry.devices) == 1
registry_entry = device_registry.async_get_device(expected_device[ATTR_IDENTIFIERS])
registry_entry = device_registry.async_get_device(
identifiers=expected_device[ATTR_IDENTIFIERS]
)
assert registry_entry is not None
assert registry_entry.identifiers == expected_device[ATTR_IDENTIFIERS]
assert registry_entry.manufacturer == expected_device[ATTR_MANUFACTURER]

Some files were not shown because too many files have changed in this diff Show more