mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-02-01 23:22:27 +01:00
Voice Assistant Timers (#878)
This commit is contained in:
parent
3bae70e462
commit
0eede84ead
@ -1536,6 +1536,26 @@ message VoiceAssistantAudio {
|
||||
bool end = 2;
|
||||
}
|
||||
|
||||
enum VoiceAssistantTimerEvent {
|
||||
VOICE_ASSISTANT_TIMER_STARTED = 0;
|
||||
VOICE_ASSISTANT_TIMER_UPDATED = 1;
|
||||
VOICE_ASSISTANT_TIMER_CANCELLED = 2;
|
||||
VOICE_ASSISTANT_TIMER_FINISHED = 3;
|
||||
}
|
||||
|
||||
message VoiceAssistantTimerEventResponse {
|
||||
option (id) = 115;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (ifdef) = "USE_VOICE_ASSISTANT";
|
||||
|
||||
VoiceAssistantTimerEvent event_type = 1;
|
||||
string timer_id = 2;
|
||||
string name = 3;
|
||||
uint32 total_seconds = 4;
|
||||
uint32 seconds_left = 5;
|
||||
bool is_active = 6;
|
||||
}
|
||||
|
||||
// ==================== ALARM CONTROL PANEL ====================
|
||||
enum AlarmControlPanelState {
|
||||
ALARM_STATE_DISARMED = 0;
|
||||
|
File diff suppressed because one or more lines are too long
@ -74,6 +74,7 @@ from .api_pb2 import ( # type: ignore
|
||||
VoiceAssistantEventResponse,
|
||||
VoiceAssistantRequest,
|
||||
VoiceAssistantResponse,
|
||||
VoiceAssistantTimerEventResponse,
|
||||
)
|
||||
from .client_callbacks import (
|
||||
on_bluetooth_connections_free_response,
|
||||
@ -131,6 +132,7 @@ from .model import (
|
||||
VoiceAssistantCommand,
|
||||
VoiceAssistantEventType,
|
||||
VoiceAssistantSubscriptionFlag,
|
||||
VoiceAssistantTimerEventType,
|
||||
message_types_to_names,
|
||||
)
|
||||
from .model_conversions import (
|
||||
@ -1386,6 +1388,25 @@ class APIClient:
|
||||
req = VoiceAssistantAudio(data=data)
|
||||
self._get_connection().send_message(req)
|
||||
|
||||
def send_voice_assistant_timer_event(
|
||||
self,
|
||||
event_type: VoiceAssistantTimerEventType,
|
||||
timer_id: str,
|
||||
name: str | None,
|
||||
total_seconds: int,
|
||||
seconds_left: int,
|
||||
is_active: bool,
|
||||
) -> None:
|
||||
req = VoiceAssistantTimerEventResponse(
|
||||
event_type=event_type,
|
||||
timer_id=timer_id,
|
||||
name=name,
|
||||
total_seconds=total_seconds,
|
||||
seconds_left=seconds_left,
|
||||
is_active=is_active,
|
||||
)
|
||||
self._get_connection().send_message(req)
|
||||
|
||||
def alarm_control_panel_command(
|
||||
self,
|
||||
key: int,
|
||||
|
@ -119,6 +119,7 @@ from .api_pb2 import ( # type: ignore
|
||||
VoiceAssistantEventResponse,
|
||||
VoiceAssistantRequest,
|
||||
VoiceAssistantResponse,
|
||||
VoiceAssistantTimerEventResponse,
|
||||
)
|
||||
|
||||
TWO_CHAR = re.compile(r".{2}")
|
||||
@ -384,4 +385,5 @@ MESSAGE_TYPE_TO_PROTO = {
|
||||
112: ListEntitiesDateTimeResponse,
|
||||
113: DateTimeStateResponse,
|
||||
114: DateTimeCommandRequest,
|
||||
115: VoiceAssistantTimerEventResponse,
|
||||
}
|
||||
|
@ -124,6 +124,7 @@ class VoiceAssistantFeature(enum.IntFlag):
|
||||
VOICE_ASSISTANT = 1 << 0
|
||||
SPEAKER = 1 << 1
|
||||
API_AUDIO = 1 << 2
|
||||
TIMERS = 1 << 3
|
||||
|
||||
|
||||
class VoiceAssistantSubscriptionFlag(enum.IntFlag):
|
||||
@ -1260,6 +1261,13 @@ class VoiceAssistantEventType(APIIntEnum):
|
||||
VOICE_ASSISTANT_TTS_STREAM_END = 99
|
||||
|
||||
|
||||
class VoiceAssistantTimerEventType(APIIntEnum):
|
||||
VOICE_ASSISTANT_TIMER_STARTED = 0
|
||||
VOICE_ASSISTANT_TIMER_UPDATED = 1
|
||||
VOICE_ASSISTANT_TIMER_CANCELLED = 2
|
||||
VOICE_ASSISTANT_TIMER_FINISHED = 3
|
||||
|
||||
|
||||
_TYPE_TO_NAME = {
|
||||
BinarySensorInfo: "binary_sensor",
|
||||
ButtonInfo: "button",
|
||||
|
@ -72,6 +72,7 @@ from aioesphomeapi.api_pb2 import (
|
||||
VoiceAssistantEventResponse,
|
||||
VoiceAssistantRequest,
|
||||
VoiceAssistantResponse,
|
||||
VoiceAssistantTimerEventResponse,
|
||||
)
|
||||
from aioesphomeapi.client import APIClient, BluetoothConnectionDroppedError
|
||||
from aioesphomeapi.connection import APIConnection
|
||||
@ -113,6 +114,9 @@ from aioesphomeapi.model import (
|
||||
VoiceAssistantAudioSettings as VoiceAssistantAudioSettingsModel,
|
||||
)
|
||||
from aioesphomeapi.model import VoiceAssistantEventType as VoiceAssistantEventModelType
|
||||
from aioesphomeapi.model import (
|
||||
VoiceAssistantTimerEventType as VoiceAssistantTimerEventModelType,
|
||||
)
|
||||
from aioesphomeapi.reconnect_logic import ReconnectLogic, ReconnectLogicState
|
||||
|
||||
from .common import (
|
||||
@ -2485,6 +2489,31 @@ async def test_subscribe_voice_assistant_api_audio(
|
||||
assert len(send.mock_calls) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_voice_assistant_timer_event(auth_client: APIClient) -> None:
|
||||
send = patch_send(auth_client)
|
||||
|
||||
auth_client.send_voice_assistant_timer_event(
|
||||
VoiceAssistantTimerEventModelType.VOICE_ASSISTANT_TIMER_STARTED,
|
||||
timer_id="test",
|
||||
name="test",
|
||||
total_seconds=99,
|
||||
seconds_left=45,
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
send.assert_called_once_with(
|
||||
VoiceAssistantTimerEventResponse(
|
||||
event_type=VoiceAssistantTimerEventModelType.VOICE_ASSISTANT_TIMER_STARTED,
|
||||
timer_id="test",
|
||||
name="test",
|
||||
total_seconds=99,
|
||||
seconds_left=45,
|
||||
is_active=True,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_version_after_connection_closed(
|
||||
api_client: tuple[
|
||||
|
Loading…
Reference in New Issue
Block a user