Add test coverage for send_voice_assistant_event (#743)
This commit is contained in:
parent
0fab7a6b99
commit
1a4c8bff17
|
@ -1303,20 +1303,15 @@ class APIClient:
|
||||||
def send_voice_assistant_event(
|
def send_voice_assistant_event(
|
||||||
self, event_type: VoiceAssistantEventType, data: dict[str, str] | None
|
self, event_type: VoiceAssistantEventType, data: dict[str, str] | None
|
||||||
) -> None:
|
) -> None:
|
||||||
req = VoiceAssistantEventResponse()
|
req = VoiceAssistantEventResponse(event_type=event_type)
|
||||||
req.event_type = event_type
|
|
||||||
|
|
||||||
data_args = []
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
for name, value in data.items():
|
# pylint: disable=no-member
|
||||||
arg = VoiceAssistantEventData()
|
req.data.extend(
|
||||||
arg.name = name
|
[
|
||||||
arg.value = value
|
VoiceAssistantEventData(name=name, value=value)
|
||||||
data_args.append(arg)
|
for name, value in data.items()
|
||||||
|
]
|
||||||
# pylint: disable=no-member
|
)
|
||||||
req.data.extend(data_args)
|
|
||||||
|
|
||||||
self._get_connection().send_message(req)
|
self._get_connection().send_message(req)
|
||||||
|
|
||||||
async def alarm_control_panel_command(
|
async def alarm_control_panel_command(
|
||||||
|
|
|
@ -57,6 +57,8 @@ from aioesphomeapi.api_pb2 import (
|
||||||
SubscribeLogsResponse,
|
SubscribeLogsResponse,
|
||||||
SwitchCommandRequest,
|
SwitchCommandRequest,
|
||||||
TextCommandRequest,
|
TextCommandRequest,
|
||||||
|
VoiceAssistantEventData,
|
||||||
|
VoiceAssistantEventResponse,
|
||||||
)
|
)
|
||||||
from aioesphomeapi.client import APIClient
|
from aioesphomeapi.client import APIClient
|
||||||
from aioesphomeapi.connection import APIConnection
|
from aioesphomeapi.connection import APIConnection
|
||||||
|
@ -94,6 +96,7 @@ from aioesphomeapi.model import (
|
||||||
UserServiceArg,
|
UserServiceArg,
|
||||||
UserServiceArgType,
|
UserServiceArgType,
|
||||||
)
|
)
|
||||||
|
from aioesphomeapi.model import VoiceAssistantEventType as VoiceAssistantEventModelType
|
||||||
from aioesphomeapi.reconnect_logic import ReconnectLogic, ReconnectLogicState
|
from aioesphomeapi.reconnect_logic import ReconnectLogic, ReconnectLogicState
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
|
@ -1666,3 +1669,33 @@ async def test_bluetooth_device_connect_cancelled(
|
||||||
)
|
)
|
||||||
# Make sure we do not leak message handlers
|
# Make sure we do not leak message handlers
|
||||||
assert handlers_after == handlers_before
|
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", "ok": "ok"},
|
||||||
|
)
|
||||||
|
send.assert_called_once_with(
|
||||||
|
VoiceAssistantEventResponse(
|
||||||
|
event_type=VoiceAssistantEventModelType.VOICE_ASSISTANT_ERROR.value,
|
||||||
|
data=[
|
||||||
|
VoiceAssistantEventData(name="error", value="error"),
|
||||||
|
VoiceAssistantEventData(name="ok", value="ok"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
send.reset_mock()
|
||||||
|
auth_client.send_voice_assistant_event(
|
||||||
|
VoiceAssistantEventModelType.VOICE_ASSISTANT_ERROR, None
|
||||||
|
)
|
||||||
|
send.assert_called_once_with(
|
||||||
|
VoiceAssistantEventResponse(
|
||||||
|
event_type=VoiceAssistantEventModelType.VOICE_ASSISTANT_ERROR.value,
|
||||||
|
data=[],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue