Skip to content

Commit d37e958

Browse files
authored
Add config entry tests to alexa_devices (home-assistant#162295)
1 parent 0498ac7 commit d37e958

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

homeassistant/components/alexa_devices/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
"cannot_retrieve_data_with_error": {
9191
"message": "Error retrieving data: {error}"
9292
},
93+
"config_entry_not_found": {
94+
"message": "Config entry not found: {device_id}"
95+
},
9396
"device_serial_number_missing": {
9497
"message": "Device serial number missing: {device_id}"
9598
},

tests/components/alexa_devices/test_services.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,69 @@ async def test_config_entry_not_loaded(
188188
assert exc_info.value.translation_domain == DOMAIN
189189
assert exc_info.value.translation_key == "entry_not_loaded"
190190
assert exc_info.value.translation_placeholders == {"entry": mock_config_entry.title}
191+
192+
193+
async def test_invalid_config_entry(
194+
hass: HomeAssistant,
195+
device_registry: dr.DeviceRegistry,
196+
mock_amazon_devices_client: AsyncMock,
197+
mock_config_entry: MockConfigEntry,
198+
) -> None:
199+
"""Test invalid config entry."""
200+
201+
await setup_integration(hass, mock_config_entry)
202+
203+
device_entry = device_registry.async_get_device(
204+
identifiers={(DOMAIN, TEST_DEVICE_1_SN)}
205+
)
206+
assert device_entry
207+
208+
device_entry.config_entries.add("non_existing_entry_id")
209+
await hass.async_block_till_done()
210+
211+
# Call Service
212+
await hass.services.async_call(
213+
DOMAIN,
214+
SERVICE_SOUND_NOTIFICATION,
215+
{
216+
ATTR_SOUND: "bell_02",
217+
ATTR_DEVICE_ID: device_entry.id,
218+
},
219+
blocking=True,
220+
)
221+
# No exception should be raised
222+
assert mock_amazon_devices_client.call_alexa_sound.call_count == 1
223+
224+
225+
async def test_missing_config_entry(
226+
hass: HomeAssistant,
227+
device_registry: dr.DeviceRegistry,
228+
mock_amazon_devices_client: AsyncMock,
229+
mock_config_entry: MockConfigEntry,
230+
) -> None:
231+
"""Test missing config entry."""
232+
233+
await setup_integration(hass, mock_config_entry)
234+
235+
device_entry = device_registry.async_get_device(
236+
identifiers={(DOMAIN, TEST_DEVICE_1_SN)}
237+
)
238+
assert device_entry
239+
240+
device_entry.config_entries.clear()
241+
242+
# Call Service
243+
with pytest.raises(ServiceValidationError) as exc_info:
244+
await hass.services.async_call(
245+
DOMAIN,
246+
SERVICE_SOUND_NOTIFICATION,
247+
{
248+
ATTR_SOUND: "bell_02",
249+
ATTR_DEVICE_ID: device_entry.id,
250+
},
251+
blocking=True,
252+
)
253+
254+
assert exc_info.value.translation_domain == DOMAIN
255+
assert exc_info.value.translation_key == "config_entry_not_found"
256+
assert exc_info.value.translation_placeholders == {"device_id": device_entry.id}

0 commit comments

Comments
 (0)