Merge branch 'main' into pr/RFDarter/824

This commit is contained in:
Jesse Hills 2024-03-06 00:10:07 +00:00
commit bbce829e0d
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
9 changed files with 260 additions and 231 deletions

3
.gitignore vendored
View File

@ -93,3 +93,6 @@ desktop.ini
# mypy
/.mypy_cache/*
# cython generated source
*.c

View File

@ -16,6 +16,10 @@ RUN if [ "$TARGETARCH" = "amd64" ]; then \
&& unzip /tmp/protoc.zip -d /usr -x readme.txt \
&& rm /tmp/protoc.zip
RUN useradd -ms /bin/bash esphome
USER esphome
WORKDIR /aioesphomeapi
COPY requirements_test.txt ./

View File

@ -588,6 +588,7 @@ message ListEntitiesTextSensorResponse {
string icon = 5;
bool disabled_by_default = 6;
EntityCategory entity_category = 7;
string device_class = 8;
}
message TextSensorStateResponse {
option (id) = 27;
@ -1511,6 +1512,7 @@ message VoiceAssistantRequest {
string conversation_id = 2;
uint32 flags = 3;
VoiceAssistantAudioSettings audio_settings = 4;
string wake_word_phrase = 5;
}
message VoiceAssistantResponse {

File diff suppressed because one or more lines are too long

View File

@ -1218,7 +1218,7 @@ class APIClient:
def subscribe_voice_assistant(
self,
handle_start: Callable[
[str, int, VoiceAssistantAudioSettingsModel],
[str, int, VoiceAssistantAudioSettingsModel, str | None],
Coroutine[Any, Any, int | None],
],
handle_stop: Callable[[], Coroutine[Any, Any, None]],
@ -1250,9 +1250,15 @@ class APIClient:
command = VoiceAssistantCommand.from_pb(msg)
if command.start:
wake_word_phrase: str | None = command.wake_word_phrase
if wake_word_phrase == "":
wake_word_phrase = None
start_task = asyncio.create_task(
handle_start(
command.conversation_id, command.flags, command.audio_settings
command.conversation_id,
command.flags,
command.audio_settings,
wake_word_phrase,
)
)
start_task.add_done_callback(_started)

View File

@ -441,7 +441,7 @@ class SwitchState(EntityState):
# ==================== TEXT SENSOR ====================
@_frozen_dataclass_decorator
class TextSensorInfo(EntityInfo):
pass
device_class: str = ""
@_frozen_dataclass_decorator
@ -1134,6 +1134,7 @@ class VoiceAssistantCommand(APIModelBase):
default=VoiceAssistantAudioSettings(),
converter=VoiceAssistantAudioSettings.from_pb,
)
wake_word_phrase: str = ""
class LogLevel(APIIntEnum):

View File

@ -1,4 +1,4 @@
pylint==3.0.3
pylint==3.1.0
black==24.2.0
flake8==7.0.0
isort==5.13.2

View File

@ -11,7 +11,7 @@ with open(os.path.join(here, "README.rst"), encoding="utf-8") as readme_file:
long_description = readme_file.read()
VERSION = "22.0.0"
VERSION = "23.0.0"
PROJECT_NAME = "aioesphomeapi"
PROJECT_PACKAGE_NAME = "aioesphomeapi"
PROJECT_LICENSE = "MIT"

View File

@ -2071,9 +2071,12 @@ async def test_subscribe_voice_assistant(
stops = []
async def handle_start(
conversation_id: str, flags: int, audio_settings: VoiceAssistantAudioSettings
conversation_id: str,
flags: int,
audio_settings: VoiceAssistantAudioSettings,
wake_word_phrase: str | None,
) -> int | None:
starts.append((conversation_id, flags, audio_settings))
starts.append((conversation_id, flags, audio_settings, wake_word_phrase))
return 42
async def handle_stop() -> None:
@ -2092,6 +2095,7 @@ async def test_subscribe_voice_assistant(
start=True,
flags=42,
audio_settings=audio_settings,
wake_word_phrase="okay nabu",
)
mock_data_received(protocol, generate_plaintext_packet(response))
await asyncio.sleep(0)
@ -2105,6 +2109,7 @@ async def test_subscribe_voice_assistant(
auto_gain=42,
volume_multiplier=42,
),
"okay nabu",
)
]
assert stops == []
@ -2141,9 +2146,12 @@ async def test_subscribe_voice_assistant_failure(
stops = []
async def handle_start(
conversation_id: str, flags: int, audio_settings: VoiceAssistantAudioSettings
conversation_id: str,
flags: int,
audio_settings: VoiceAssistantAudioSettings,
wake_word_phrase: str | None,
) -> int | None:
starts.append((conversation_id, flags, audio_settings))
starts.append((conversation_id, flags, audio_settings, wake_word_phrase))
# Return None to indicate failure
return None
@ -2176,6 +2184,7 @@ async def test_subscribe_voice_assistant_failure(
auto_gain=42,
volume_multiplier=42,
),
None,
)
]
assert stops == []
@ -2212,9 +2221,12 @@ async def test_subscribe_voice_assistant_cancels_long_running_handle_start(
stops = []
async def handle_start(
conversation_id: str, flags: int, audio_settings: VoiceAssistantAudioSettings
conversation_id: str,
flags: int,
audio_settings: VoiceAssistantAudioSettings,
wake_word_phrase: str | None,
) -> int | None:
starts.append((conversation_id, flags, audio_settings))
starts.append((conversation_id, flags, audio_settings, wake_word_phrase))
await asyncio.sleep(10)
# Return None to indicate failure
starts.append("never")
@ -2252,6 +2264,7 @@ async def test_subscribe_voice_assistant_cancels_long_running_handle_start(
auto_gain=42,
volume_multiplier=42,
),
None,
)
]