Give UniFi Protect speakers adopted at runtime their speaker unique ID (#188403)

This commit is contained in:
Raphael Hehl
2026-10-26 15:26:58 +00:00
committed by GitHub
parent 286cde03f9
commit 8f418f9ed5
2 changed files with 24 additions and 1 deletions
@@ -51,7 +51,7 @@ async def async_setup_entry(
and isinstance(device, Camera)
and (device.has_speaker or device.has_removable_speaker)
):
async_add_entities([ProtectMediaPlayer(data, device)])
async_add_entities([ProtectMediaPlayer(data, device, _SPEAKER_DESCRIPTION)])
data.async_subscribe_adopt(_add_new_device)
async_add_entities(
@@ -47,6 +47,29 @@ async def test_media_player_camera_remove(
assert_entity_counts(hass, Platform.MEDIA_PLAYER, 1, 1)
async def test_media_player_adopted_at_runtime(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
doorbell: Camera,
) -> None:
"""A speaker camera adopted while running gets the speaker unique ID and name."""
await init_entry(hass, ufp, [])
assert_entity_counts(hass, Platform.MEDIA_PLAYER, 0, 0)
doorbell._api = ufp.api
await adopt_devices(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.MEDIA_PLAYER, 1, 1)
entity = entity_registry.async_get("media_player.test_camera_speaker")
assert entity
assert entity.unique_id == f"{doorbell.mac}_speaker"
state = hass.states.get("media_player.test_camera_speaker")
assert state
assert state.name == "Test Camera Speaker"
async def test_media_player_setup(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,