diff --git a/homeassistant/components/melnor/entity.py b/homeassistant/components/melnor/entity.py index 21a4e75ff21d..2f1b5f909280 100644 --- a/homeassistant/components/melnor/entity.py +++ b/homeassistant/components/melnor/entity.py @@ -6,7 +6,7 @@ from melnor_bluetooth.device import Device, Valve from homeassistant.components.number import EntityDescription from homeassistant.core import callback -from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN @@ -30,6 +30,7 @@ class MelnorBluetoothEntity(CoordinatorEntity[MelnorDataUpdateCoordinator]): self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, self._device.mac)}, + connections={(CONNECTION_BLUETOOTH, self._device.mac)}, manufacturer="Melnor", model=self._device.model, name=self._device.name, diff --git a/tests/components/melnor/snapshots/test_init.ambr b/tests/components/melnor/snapshots/test_init.ambr new file mode 100644 index 000000000000..575043cb8cdc --- /dev/null +++ b/tests/components/melnor/snapshots/test_init.ambr @@ -0,0 +1,36 @@ +# serializer version: 1 +# name: test_device_registry + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'config_entries_subentries': , + 'configuration_url': None, + 'connections': set({ + tuple( + 'bluetooth', + 'FAKE-ADDRESS-1', + ), + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'melnor', + 'FAKE-ADDRESS-1', + ), + }), + 'labels': set({ + }), + 'manufacturer': 'Melnor', + 'model': 'test_model', + 'model_id': None, + 'name': 'test_melnor', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': None, + 'sw_version': None, + 'via_device_id': None, + }) +# --- diff --git a/tests/components/melnor/test_init.py b/tests/components/melnor/test_init.py new file mode 100644 index 000000000000..229d1b3cc337 --- /dev/null +++ b/tests/components/melnor/test_init.py @@ -0,0 +1,37 @@ +"""Test the Melnor integration setup.""" + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.melnor.const import DOMAIN +from homeassistant.core import HomeAssistant +from homeassistant.helpers import device_registry as dr + +from .conftest import ( + FAKE_ADDRESS_1, + mock_config_entry, + patch_async_ble_device_from_address, + patch_async_register_callback, + patch_melnor_device, +) + + +async def test_device_registry( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test the device registry entry, including the Bluetooth connection.""" + entry = mock_config_entry(hass) + + with ( + patch_async_ble_device_from_address(), + patch_melnor_device(), + patch_async_register_callback(), + ): + assert await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + device_entry = device_registry.async_get_device( + identifiers={(DOMAIN, FAKE_ADDRESS_1)} + ) + assert device_entry == snapshot