diff --git a/homeassistant/components/tplink/camera.py b/homeassistant/components/tplink/camera.py index 5ed279909d6..8aa49cf3c93 100644 --- a/homeassistant/components/tplink/camera.py +++ b/homeassistant/components/tplink/camera.py @@ -108,7 +108,7 @@ class TPLinkCameraEntity(CoordinatedTPLinkEntity, Camera): def _get_unique_id(self) -> str: """Return unique ID for the entity.""" - return f"{legacy_device_id(self._device)}-{self.entity_description}" + return f"{legacy_device_id(self._device)}-{self.entity_description.key}" @callback def _async_update_attrs(self) -> None: diff --git a/tests/components/tplink/snapshots/test_camera.ambr b/tests/components/tplink/snapshots/test_camera.ambr index 4ce1813d704..4417395078a 100644 --- a/tests/components/tplink/snapshots/test_camera.ambr +++ b/tests/components/tplink/snapshots/test_camera.ambr @@ -28,7 +28,7 @@ 'previous_unique_id': None, 'supported_features': , 'translation_key': 'live_view', - 'unique_id': "123456789ABCDEFGH-TPLinkCameraEntityDescription(key='live_view', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name=, translation_key='live_view', translation_placeholders=None, unit_of_measurement=None, deprecated_info=None)", + 'unique_id': '123456789ABCDEFGH-live_view', 'unit_of_measurement': None, }) # --- diff --git a/tests/components/tplink/test_camera.py b/tests/components/tplink/test_camera.py index d8b0f82e32a..8ca56a84b6b 100644 --- a/tests/components/tplink/test_camera.py +++ b/tests/components/tplink/test_camera.py @@ -24,6 +24,7 @@ from homeassistant.core import HomeAssistant, HomeAssistantError from homeassistant.helpers import device_registry as dr, entity_registry as er from . import ( + DEVICE_ID, IP_ADDRESS3, MAC_ADDRESS3, SMALLEST_VALID_JPEG_BYTES, @@ -68,6 +69,33 @@ async def test_states( ) +async def test_camera_unique_id( + hass: HomeAssistant, + mock_camera_config_entry: MockConfigEntry, + device_registry: dr.DeviceRegistry, +) -> None: + """Test camera unique id.""" + mock_device = _mocked_device( + modules=[Module.Camera], + alias="my_camera", + ip_address=IP_ADDRESS3, + mac=MAC_ADDRESS3, + device_id=DEVICE_ID, + ) + + await setup_platform_for_device( + hass, mock_camera_config_entry, Platform.CAMERA, mock_device + ) + + device_entries = dr.async_entries_for_config_entry( + device_registry, mock_camera_config_entry.entry_id + ) + assert device_entries + entity_id = "camera.my_camera_live_view" + entity_registry = er.async_get(hass) + assert entity_registry.async_get(entity_id).unique_id == f"{DEVICE_ID}-live_view" + + async def test_handle_mjpeg_stream( hass: HomeAssistant, mock_camera_config_entry: MockConfigEntry,