Add coverage for unsubscribing from voice assistants (#745)

This commit is contained in:
J. Nick Koston 2023-11-26 17:07:48 -06:00 committed by GitHub
parent 1a4bdfbed8
commit a148479679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1729,7 +1729,7 @@ async def test_subscribe_voice_assistant(
async def handle_stop() -> None: async def handle_stop() -> None:
stops.append(True) stops.append(True)
await client.subscribe_voice_assistant(handle_start, handle_stop) unsub = await client.subscribe_voice_assistant(handle_start, handle_stop)
send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=True)) send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=True))
send.reset_mock() send.reset_mock()
audio_settings = VoiceAssistantAudioSettings( audio_settings = VoiceAssistantAudioSettings(
@ -1767,6 +1767,15 @@ async def test_subscribe_voice_assistant(
mock_data_received(protocol, generate_plaintext_packet(response)) mock_data_received(protocol, generate_plaintext_packet(response))
await asyncio.sleep(0) await asyncio.sleep(0)
assert stops == [True] assert stops == [True]
send.reset_mock()
unsub()
send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=False))
send.reset_mock()
await client.disconnect(force=True)
# Ensure abort callback is a no-op after disconnect
# and does not raise
unsub()
assert len(send.mock_calls) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
@ -1791,7 +1800,7 @@ async def test_subscribe_voice_assistant_failure(
async def handle_stop() -> None: async def handle_stop() -> None:
stops.append(True) stops.append(True)
await client.subscribe_voice_assistant(handle_start, handle_stop) unsub = await client.subscribe_voice_assistant(handle_start, handle_stop)
send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=True)) send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=True))
send.reset_mock() send.reset_mock()
audio_settings = VoiceAssistantAudioSettings( audio_settings = VoiceAssistantAudioSettings(
@ -1829,3 +1838,12 @@ async def test_subscribe_voice_assistant_failure(
mock_data_received(protocol, generate_plaintext_packet(response)) mock_data_received(protocol, generate_plaintext_packet(response))
await asyncio.sleep(0) await asyncio.sleep(0)
assert stops == [True] assert stops == [True]
send.reset_mock()
unsub()
send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=False))
send.reset_mock()
await client.disconnect(force=True)
# Ensure abort callback is a no-op after disconnect
# and does not raise
unsub()
assert len(send.mock_calls) == 0