From d37e958a0b847e2f05c73d7bd3567db17bbb21fa Mon Sep 17 00:00:00 2001 From: jameson_uk <1040621+jamesonuk@users.noreply.github.com> Date: Thu, 5 Feb 2026 13:07:14 +0000 Subject: [PATCH] Add config entry tests to alexa_devices (#162295) --- .../components/alexa_devices/strings.json | 3 + .../components/alexa_devices/test_services.py | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/homeassistant/components/alexa_devices/strings.json b/homeassistant/components/alexa_devices/strings.json index 6cfbe59b2c6..12b9c6948e1 100644 --- a/homeassistant/components/alexa_devices/strings.json +++ b/homeassistant/components/alexa_devices/strings.json @@ -90,6 +90,9 @@ "cannot_retrieve_data_with_error": { "message": "Error retrieving data: {error}" }, + "config_entry_not_found": { + "message": "Config entry not found: {device_id}" + }, "device_serial_number_missing": { "message": "Device serial number missing: {device_id}" }, diff --git a/tests/components/alexa_devices/test_services.py b/tests/components/alexa_devices/test_services.py index 9ea1a271a7f..254daa0749a 100644 --- a/tests/components/alexa_devices/test_services.py +++ b/tests/components/alexa_devices/test_services.py @@ -188,3 +188,69 @@ async def test_config_entry_not_loaded( assert exc_info.value.translation_domain == DOMAIN assert exc_info.value.translation_key == "entry_not_loaded" assert exc_info.value.translation_placeholders == {"entry": mock_config_entry.title} + + +async def test_invalid_config_entry( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + mock_amazon_devices_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test invalid config entry.""" + + await setup_integration(hass, mock_config_entry) + + device_entry = device_registry.async_get_device( + identifiers={(DOMAIN, TEST_DEVICE_1_SN)} + ) + assert device_entry + + device_entry.config_entries.add("non_existing_entry_id") + await hass.async_block_till_done() + + # Call Service + await hass.services.async_call( + DOMAIN, + SERVICE_SOUND_NOTIFICATION, + { + ATTR_SOUND: "bell_02", + ATTR_DEVICE_ID: device_entry.id, + }, + blocking=True, + ) + # No exception should be raised + assert mock_amazon_devices_client.call_alexa_sound.call_count == 1 + + +async def test_missing_config_entry( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + mock_amazon_devices_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test missing config entry.""" + + await setup_integration(hass, mock_config_entry) + + device_entry = device_registry.async_get_device( + identifiers={(DOMAIN, TEST_DEVICE_1_SN)} + ) + assert device_entry + + device_entry.config_entries.clear() + + # Call Service + with pytest.raises(ServiceValidationError) as exc_info: + await hass.services.async_call( + DOMAIN, + SERVICE_SOUND_NOTIFICATION, + { + ATTR_SOUND: "bell_02", + ATTR_DEVICE_ID: device_entry.id, + }, + blocking=True, + ) + + assert exc_info.value.translation_domain == DOMAIN + assert exc_info.value.translation_key == "config_entry_not_found" + assert exc_info.value.translation_placeholders == {"device_id": device_entry.id}