Add test coverage for send_voice_assistant_event

This commit is contained in:
J. Nick Koston 2023-11-26 16:40:26 -06:00
parent 0fab7a6b99
commit 32cbc989ff
No known key found for this signature in database
2 changed files with 22 additions and 2 deletions

View File

@ -1303,8 +1303,7 @@ class APIClient:
def send_voice_assistant_event(
self, event_type: VoiceAssistantEventType, data: dict[str, str] | None
) -> None:
req = VoiceAssistantEventResponse()
req.event_type = event_type
req = VoiceAssistantEventResponse(event_type=event_type)
data_args = []
if data is not None:

View File

@ -57,6 +57,8 @@ from aioesphomeapi.api_pb2 import (
SubscribeLogsResponse,
SwitchCommandRequest,
TextCommandRequest,
VoiceAssistantEventData,
VoiceAssistantEventResponse,
)
from aioesphomeapi.client import APIClient
from aioesphomeapi.connection import APIConnection
@ -94,6 +96,7 @@ from aioesphomeapi.model import (
UserServiceArg,
UserServiceArgType,
)
from aioesphomeapi.model import VoiceAssistantEventType as VoiceAssistantEventModelType
from aioesphomeapi.reconnect_logic import ReconnectLogic, ReconnectLogicState
from .common import (
@ -1666,3 +1669,21 @@ async def test_bluetooth_device_connect_cancelled(
)
# Make sure we do not leak message handlers
assert handlers_after == handlers_before
@pytest.mark.asyncio
async def test_send_voice_assistant_event(auth_client: APIClient) -> None:
send = patch_send(auth_client)
auth_client.send_voice_assistant_event(
VoiceAssistantEventModelType.VOICE_ASSISTANT_ERROR,
{
"error": "error",
},
)
send.assert_called_once_with(
VoiceAssistantEventResponse(
event_type=VoiceAssistantEventModelType.VOICE_ASSISTANT_ERROR.value,
data=[VoiceAssistantEventData(name="error", value="error")],
)
)