From 726741e4ca374e49935269de7ae246dc44614b1a Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Mon, 7 Sep 2026 14:32:00 +0200 Subject: [PATCH] Fix unique_id for service entities in Alexa Devices (#181526) --- .../components/alexa_devices/select.py | 30 ++++++++++--------- tests/components/alexa_devices/test_select.py | 4 +++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/alexa_devices/select.py b/homeassistant/components/alexa_devices/select.py index d93ed6bc623d..49c559c1583d 100644 --- a/homeassistant/components/alexa_devices/select.py +++ b/homeassistant/components/alexa_devices/select.py @@ -66,24 +66,26 @@ async def async_setup_entry( new_devices = current_devices - known_devices if new_devices: known_devices.update(new_devices) - select_entities = [ - AmazonSelectEntity(coordinator, serial_num, select_desc) - for select_desc in SELECTS - for serial_num in new_devices - if select_desc.is_available_fn(coordinator.data[serial_num]) - ] - select_service_entites = [ - AmazonSelectServiceEntity(coordinator, select_desc) - for select_desc in SERVICE_SELECTS - for serial_num in new_devices - if select_desc.is_available_fn(coordinator.data[serial_num]) - ] - async_add_entities(select_entities) - async_add_entities(select_service_entites) + async_add_entities( + [ + AmazonSelectEntity(coordinator, serial_num, select_desc) + for select_desc in SELECTS + for serial_num in new_devices + if select_desc.is_available_fn(coordinator.data[serial_num]) + ] + ) _check_device() entry.async_on_unload(coordinator.async_add_listener(_check_device)) + # Service entities + async_add_entities( + [ + AmazonSelectServiceEntity(coordinator, select_desc) + for select_desc in SERVICE_SELECTS + ] + ) + class AmazonSelectEntity(AmazonEntity, SelectEntity): """Representation of a select entity.""" diff --git a/tests/components/alexa_devices/test_select.py b/tests/components/alexa_devices/test_select.py index 998218e87141..55dc4b2ccb05 100644 --- a/tests/components/alexa_devices/test_select.py +++ b/tests/components/alexa_devices/test_select.py @@ -108,6 +108,7 @@ async def test_offline_device( async def test_service_select_option( hass: HomeAssistant, + caplog: pytest.LogCaptureFixture, mock_amazon_devices_client: AsyncMock, mock_config_entry: MockConfigEntry, ) -> None: @@ -119,6 +120,9 @@ async def test_service_select_option( await setup_integration(hass, mock_config_entry) + # A single account-wide entity is created regardless of the number of devices + assert "does not generate unique IDs" not in caplog.text + assert (state := hass.states.get(ENTITY_ID_2)) assert state.state == TEST_DEVICE_1.account_name