Compare commits

...

49 Commits

Author SHA1 Message Date
github-actions[bot] 6a23cca5d3 Bump version to 24.5.1 2024-05-29 07:22:45 +00:00
dependabot[bot] 44dafb9f06
Bump docker/login-action from 3.1.0 to 3.2.0 (#879)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-29 09:22:26 +02:00
github-actions[bot] 8cd85de0af Bump version to 24.5.0 2024-05-27 22:32:52 +00:00
Jesse Hills 0eede84ead
Voice Assistant Timers (#878) 2024-05-28 10:32:36 +12:00
dependabot[bot] 3bae70e462
Bump pypa/cibuildwheel from 2.18.0 to 2.18.1 (#876)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-28 09:28:20 +12:00
github-actions[bot] 2ae6ff8338 Bump version to 24.4.1 2024-05-27 21:28:00 +00:00
dependabot[bot] 24652a226d
Bump pytest-asyncio from 0.23.6 to 0.23.7 (#874)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-28 09:27:46 +12:00
dependabot[bot] e8d27e514e
Bump pylint from 3.2.0 to 3.2.2 (#875)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-28 09:27:38 +12:00
github-actions[bot] d62d67f585 Bump version to 24.4.0 2024-05-14 22:05:43 +00:00
Mischa Siekmann 8778ad485c
Adding announcement flag to media player command (#871)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2024-05-15 10:05:18 +12:00
dependabot[bot] 8e6717c197
Bump pylint from 3.1.0 to 3.2.0 (#873) 2024-05-15 07:03:46 +09:00
dependabot[bot] adcd5b1a13
Bump pypa/cibuildwheel from 2.17.0 to 2.18.0 (#872) 2024-05-13 19:50:28 +09:00
dependabot[bot] 6e2d5d4fde
Bump mypy from 1.9.0 to 1.10.0 (#868) 2024-05-13 09:17:09 +09:00
dependabot[bot] 8dd044e89d
Bump black from 24.4.0 to 24.4.2 (#869)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-13 08:48:14 +09:00
github-actions[bot] e97a716d44 Bump version to 24.3.1 2024-04-23 02:44:35 +00:00
dependabot[bot] ab390acf93
Bump types-protobuf from 4.25.0.20240417 to 5.26.0.20240422 (#865)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-23 14:44:20 +12:00
github-actions[bot] 1c4d7a60bb Bump version to 24.3.0 2024-04-22 10:48:36 +00:00
David Friedland f1538a7ed0
Support for Event entity messages (#853)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2024-04-22 22:48:21 +12:00
github-actions[bot] e88f1468cb Bump version to 24.2.1 2024-04-22 05:04:53 +00:00
Jesse Hills 397c64f3e3
Alphabetise model_conversions.py (#864) 2024-04-22 17:04:38 +12:00
github-actions[bot] 0257210087 Bump version to 24.2.0 2024-04-22 03:58:30 +00:00
Jesse Hills b935707ceb
Add Datetime entities (#859) 2024-04-22 15:58:16 +12:00
dependabot[bot] 27247a5192
Bump types-protobuf from 4.25.0.20240410 to 4.25.0.20240417 (#863)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-18 17:25:28 +12:00
github-actions[bot] 01eaee25c0 Bump version to 24.1.1 2024-04-17 21:18:54 +00:00
J. Nick Koston 4cff8555d2
Remove zeroconf listener removal workaround (#860) 2024-04-17 16:18:36 -05:00
github-actions[bot] 56369fb332 Bump version to 24.1.0 2024-04-17 01:50:05 +00:00
Keith Burzinski 0ed69bbb30
Add valve component (#852)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2024-04-17 13:45:33 +12:00
dependabot[bot] b10cbd6c9a
Bump types-protobuf from 4.24.0.20240311 to 4.25.0.20240410 (#858)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-17 10:27:59 +12:00
dependabot[bot] d9dde5bc14
Bump black from 24.3.0 to 24.4.0 (#861)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-17 10:26:57 +12:00
Jesse Hills 0ad9dd5aa5
Use trusted publishing token (#862) 2024-04-17 10:26:39 +12:00
Jesse Hills 725e501815
Remove deprecated settings for devcontainer (#857) 2024-04-12 11:29:29 +12:00
dependabot[bot] 78f6ed9e63
Bump docker/setup-buildx-action from 3.2.0 to 3.3.0 (#856)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-09 16:38:04 +12:00
dependabot[bot] c3b31878d3
Bump pypa/cibuildwheel from 2.16.5 to 2.17.0 (#845)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:28:59 +12:00
dependabot[bot] 301cf02153
Bump types-protobuf from 4.24.0.20240129 to 4.24.0.20240311 (#843)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:26:05 +12:00
dependabot[bot] 6a8185e70d
Bump pytest-asyncio from 0.23.5.post1 to 0.23.6 (#851)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:25:44 +12:00
dependabot[bot] ce3513153c
Bump black from 24.2.0 to 24.3.0 (#849)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:25:34 +12:00
github-actions[bot] 6b5c6ed20b Bump version to 24.0.1 2024-04-08 02:25:25 +00:00
dependabot[bot] 96f4171d4f
Bump docker/setup-buildx-action from 3.1.0 to 3.2.0 (#848)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:25:11 +12:00
dependabot[bot] c1585b59a0
Bump docker/build-push-action from 5.2.0 to 5.3.0 (#846)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:25:00 +12:00
dependabot[bot] 10a00aed17
Bump docker/login-action from 3.0.0 to 3.1.0 (#847)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:24:49 +12:00
github-actions[bot] 3da9d7f8ca Bump version to 24.0.0 2024-04-07 22:44:27 +00:00
Jesse Hills 27a968df1b
Send/Receive Voice Assistant Audio Messages (#854)
Co-authored-by: Michael Hansen <mike@rhasspy.org>
2024-04-08 10:44:10 +12:00
github-actions[bot] 15d1949654 Bump version to 23.2.0 2024-03-20 01:31:14 +00:00
Jesse Hills 7da8a353cd
Implement datetime time entity (#850) 2024-03-20 14:31:00 +13:00
dependabot[bot] ff23e4c9a0
Bump docker/build-push-action from 5.1.0 to 5.2.0 (#838)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 00:21:16 -10:00
dependabot[bot] 6bb219ef35
Bump docker/setup-buildx-action from 3.0.0 to 3.1.0 (#833)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 00:20:58 -10:00
dependabot[bot] d52d2e2a09
Bump mypy from 1.8.0 to 1.9.0 (#844)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 00:19:59 -10:00
github-actions[bot] bcebfd29e4 Bump version to 23.1.2 2024-03-11 10:15:23 +00:00
dependabot[bot] 9f0a1a22ec
Bump pytest-asyncio from 0.23.5 to 0.23.5.post1 (#842)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 00:15:08 -10:00
17 changed files with 1217 additions and 307 deletions

View File

@ -19,8 +19,6 @@
"settings": {
"python.languageServer": "Pylance",
"python.pythonPath": "/usr/bin/python3",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,

View File

@ -28,13 +28,13 @@ jobs:
uses: actions/checkout@v4
-
name: Log in to docker hub
uses: docker/login-action@v3.0.0
uses: docker/login-action@v3.2.0
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Log in to the GitHub container registry
uses: docker/login-action@v3.0.0
uses: docker/login-action@v3.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
@ -44,10 +44,10 @@ jobs:
uses: docker/setup-qemu-action@v3.0.0
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.0.0
uses: docker/setup-buildx-action@v3.3.0
-
name: Build and Push
uses: docker/build-push-action@v5.1.0
uses: docker/build-push-action@v5.3.0
with:
context: .
tags: |

View File

@ -25,7 +25,7 @@ jobs:
platforms: arm64
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
uses: pypa/cibuildwheel@v2.18.1
env:
CIBW_SKIP: cp36-* cp37-* cp38-* cp39-* cp310-* pp* *musllinux*
CIBW_BEFORE_ALL_LINUX: apt-get install -y gcc || yum install -y gcc || apk add gcc
@ -58,11 +58,11 @@ jobs:
id-token: write
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.8.14

View File

@ -44,8 +44,11 @@ service APIConnection {
rpc siren_command (SirenCommandRequest) returns (void) {}
rpc button_command (ButtonCommandRequest) returns (void) {}
rpc lock_command (LockCommandRequest) returns (void) {}
rpc valve_command (ValveCommandRequest) returns (void) {}
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
rpc date_command (DateCommandRequest) returns (void) {}
rpc time_command (TimeCommandRequest) returns (void) {}
rpc datetime_command (DateTimeCommandRequest) returns (void) {}
rpc subscribe_bluetooth_le_advertisements (SubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
rpc bluetooth_device_request(BluetoothDeviceRequest) returns (void) {}
@ -217,7 +220,8 @@ message DeviceInfoResponse {
string friendly_name = 13;
uint32 voice_assistant_version = 14;
uint32 legacy_voice_assistant_version = 14;
uint32 voice_assistant_feature_flags = 17;
string suggested_area = 16;
}
@ -1171,6 +1175,9 @@ message MediaPlayerCommandRequest {
bool has_media_url = 6;
string media_url = 7;
bool has_announcement = 8;
bool announcement = 9;
}
// ==================== BLUETOOTH ====================
@ -1447,12 +1454,18 @@ message BluetoothDeviceClearCacheResponse {
}
// ==================== VOICE ASSISTANT ====================
enum VoiceAssistantSubscribeFlag {
VOICE_ASSISTANT_SUBSCRIBE_NONE = 0;
VOICE_ASSISTANT_SUBSCRIBE_API_AUDIO = 1;
}
message SubscribeVoiceAssistantRequest {
option (id) = 89;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_VOICE_ASSISTANT";
bool subscribe = 1;
uint32 flags = 2;
}
message VoiceAssistantAudioSettings {
@ -1514,6 +1527,35 @@ message VoiceAssistantEventResponse {
repeated VoiceAssistantEventData data = 2;
}
message VoiceAssistantAudio {
option (id) = 106;
option (source) = SOURCE_BOTH;
option (ifdef) = "USE_VOICE_ASSISTANT";
bytes data = 1;
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;
@ -1660,3 +1702,157 @@ message DateCommandRequest {
uint32 month = 3;
uint32 day = 4;
}
// ==================== DATETIME TIME ====================
message ListEntitiesTimeResponse {
option (id) = 103;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_DATETIME_TIME";
string object_id = 1;
fixed32 key = 2;
string name = 3;
string unique_id = 4;
string icon = 5;
bool disabled_by_default = 6;
EntityCategory entity_category = 7;
}
message TimeStateResponse {
option (id) = 104;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_DATETIME_TIME";
option (no_delay) = true;
fixed32 key = 1;
// If the time does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 2;
uint32 hour = 3;
uint32 minute = 4;
uint32 second = 5;
}
message TimeCommandRequest {
option (id) = 105;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_DATETIME_TIME";
option (no_delay) = true;
fixed32 key = 1;
uint32 hour = 2;
uint32 minute = 3;
uint32 second = 4;
}
// ==================== EVENT ====================
message ListEntitiesEventResponse {
option (id) = 107;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_EVENT";
string object_id = 1;
fixed32 key = 2;
string name = 3;
string unique_id = 4;
string icon = 5;
bool disabled_by_default = 6;
EntityCategory entity_category = 7;
string device_class = 8;
repeated string event_types = 9;
}
message EventResponse {
option (id) = 108;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_EVENT";
fixed32 key = 1;
string event_type = 2;
}
// ==================== VALVE ====================
message ListEntitiesValveResponse {
option (id) = 109;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_VALVE";
string object_id = 1;
fixed32 key = 2;
string name = 3;
string unique_id = 4;
string icon = 5;
bool disabled_by_default = 6;
EntityCategory entity_category = 7;
string device_class = 8;
bool assumed_state = 9;
bool supports_position = 10;
bool supports_stop = 11;
}
enum ValveOperation {
VALVE_OPERATION_IDLE = 0;
VALVE_OPERATION_IS_OPENING = 1;
VALVE_OPERATION_IS_CLOSING = 2;
}
message ValveStateResponse {
option (id) = 110;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_VALVE";
option (no_delay) = true;
fixed32 key = 1;
float position = 2;
ValveOperation current_operation = 3;
}
message ValveCommandRequest {
option (id) = 111;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_VALVE";
option (no_delay) = true;
fixed32 key = 1;
bool has_position = 2;
float position = 3;
bool stop = 4;
}
// ==================== DATETIME DATETIME ====================
message ListEntitiesDateTimeResponse {
option (id) = 112;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_DATETIME_DATETIME";
string object_id = 1;
fixed32 key = 2;
string name = 3;
string unique_id = 4;
string icon = 5;
bool disabled_by_default = 6;
EntityCategory entity_category = 7;
}
message DateTimeStateResponse {
option (id) = 113;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_DATETIME_DATETIME";
option (no_delay) = true;
fixed32 key = 1;
// If the datetime does not have a valid state yet.
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
bool missing_state = 2;
fixed32 epoch_seconds = 3;
}
message DateTimeCommandRequest {
option (id) = 114;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_DATETIME_DATETIME";
option (no_delay) = true;
fixed32 key = 1;
fixed32 epoch_seconds = 2;
}

File diff suppressed because one or more lines are too long

View File

@ -38,6 +38,7 @@ from .api_pb2 import ( # type: ignore
ClimateCommandRequest,
CoverCommandRequest,
DateCommandRequest,
DateTimeCommandRequest,
DeviceInfoRequest,
DeviceInfoResponse,
ExecuteServiceArgument,
@ -65,11 +66,15 @@ from .api_pb2 import ( # type: ignore
SubscribeVoiceAssistantRequest,
SwitchCommandRequest,
TextCommandRequest,
TimeCommandRequest,
UnsubscribeBluetoothLEAdvertisementsRequest,
ValveCommandRequest,
VoiceAssistantAudio,
VoiceAssistantEventData,
VoiceAssistantEventResponse,
VoiceAssistantRequest,
VoiceAssistantResponse,
VoiceAssistantTimerEventResponse,
)
from .client_callbacks import (
on_bluetooth_connections_free_response,
@ -120,11 +125,14 @@ from .model import (
MediaPlayerCommand,
UserService,
UserServiceArgType,
VoiceAssistantAudioData,
)
from .model import VoiceAssistantAudioSettings as VoiceAssistantAudioSettingsModel
from .model import (
VoiceAssistantCommand,
VoiceAssistantEventType,
VoiceAssistantSubscriptionFlag,
VoiceAssistantTimerEventType,
message_types_to_names,
)
from .model_conversions import (
@ -1108,6 +1116,23 @@ class APIClient:
DateCommandRequest(key=key, year=year, month=month, day=day)
)
def time_command(self, key: int, hour: int, minute: int, second: int) -> None:
self._get_connection().send_message(
TimeCommandRequest(key=key, hour=hour, minute=minute, second=second)
)
def datetime_command(
self,
key: int,
epoch_seconds: int,
) -> None:
self._get_connection().send_message(
DateTimeCommandRequest(
key=key,
epoch_seconds=epoch_seconds,
)
)
def select_command(self, key: int, state: str) -> None:
self._get_connection().send_message(SelectCommandRequest(key=key, state=state))
@ -1148,6 +1173,20 @@ class APIClient:
req.code = code
self._get_connection().send_message(req)
def valve_command(
self,
key: int,
position: float | None = None,
stop: bool = False,
) -> None:
req = ValveCommandRequest(key=key)
if position is not None:
req.has_position = True
req.position = position
if stop:
req.stop = stop
self._get_connection().send_message(req)
def media_player_command(
self,
key: int,
@ -1155,6 +1194,7 @@ class APIClient:
command: MediaPlayerCommand | None = None,
volume: float | None = None,
media_url: str | None = None,
announcement: bool | None = None,
) -> None:
req = MediaPlayerCommandRequest(key=key)
if command is not None:
@ -1166,6 +1206,9 @@ class APIClient:
if media_url is not None:
req.media_url = media_url
req.has_media_url = True
if announcement is not None:
req.announcement = announcement
req.has_announcement = True
self._get_connection().send_message(req)
def text_command(self, key: int, state: str) -> None:
@ -1220,11 +1263,19 @@ class APIClient:
def subscribe_voice_assistant(
self,
*,
handle_start: Callable[
[str, int, VoiceAssistantAudioSettingsModel, str | None],
Coroutine[Any, Any, int | None],
],
handle_stop: Callable[[], Coroutine[Any, Any, None]],
handle_audio: (
Callable[
[bytes],
Coroutine[Any, Any, None],
]
| None
) = None,
) -> Callable[[], None]:
"""Subscribes to voice assistant messages from the device.
@ -1270,17 +1321,40 @@ class APIClient:
else:
self._create_background_task(handle_stop())
connection.send_message(SubscribeVoiceAssistantRequest(subscribe=True))
remove_callbacks = []
flags = 0
if handle_audio is not None:
flags |= VoiceAssistantSubscriptionFlag.API_AUDIO
remove_callback = connection.add_message_callback(
_on_voice_assistant_request, (VoiceAssistantRequest,)
def _on_voice_assistant_audio(msg: VoiceAssistantAudio) -> None:
audio = VoiceAssistantAudioData.from_pb(msg)
if audio.end:
self._create_background_task(handle_stop())
else:
self._create_background_task(handle_audio(audio.data))
remove_callbacks.append(
connection.add_message_callback(
_on_voice_assistant_audio, (VoiceAssistantAudio,)
)
)
connection.send_message(
SubscribeVoiceAssistantRequest(subscribe=True, flags=flags)
)
remove_callbacks.append(
connection.add_message_callback(
_on_voice_assistant_request, (VoiceAssistantRequest,)
)
)
def unsub() -> None:
nonlocal start_task
if self._connection is not None:
remove_callback()
for remove_callback in remove_callbacks:
remove_callback()
self._connection.send_message(
SubscribeVoiceAssistantRequest(subscribe=False)
)
@ -1310,6 +1384,29 @@ class APIClient:
)
self._get_connection().send_message(req)
def send_voice_assistant_audio(self, data: bytes) -> None:
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,

View File

@ -145,7 +145,7 @@ CONNECTION_STATE_CLOSED = ConnectionState.CLOSED
def _make_hello_request(client_info: str) -> HelloRequest:
"""Make a HelloRequest."""
return HelloRequest(
client_info=client_info, api_version_major=1, api_version_minor=9
client_info=client_info, api_version_major=1, api_version_minor=10
)

View File

@ -40,10 +40,13 @@ from .api_pb2 import ( # type: ignore
CoverStateResponse,
DateCommandRequest,
DateStateResponse,
DateTimeCommandRequest,
DateTimeStateResponse,
DeviceInfoRequest,
DeviceInfoResponse,
DisconnectRequest,
DisconnectResponse,
EventResponse,
ExecuteServiceRequest,
FanCommandRequest,
FanStateResponse,
@ -62,7 +65,9 @@ from .api_pb2 import ( # type: ignore
ListEntitiesClimateResponse,
ListEntitiesCoverResponse,
ListEntitiesDateResponse,
ListEntitiesDateTimeResponse,
ListEntitiesDoneResponse,
ListEntitiesEventResponse,
ListEntitiesFanResponse,
ListEntitiesLightResponse,
ListEntitiesLockResponse,
@ -76,6 +81,8 @@ from .api_pb2 import ( # type: ignore
ListEntitiesSwitchResponse,
ListEntitiesTextResponse,
ListEntitiesTextSensorResponse,
ListEntitiesTimeResponse,
ListEntitiesValveResponse,
LockCommandRequest,
LockStateResponse,
MediaPlayerCommandRequest,
@ -103,10 +110,16 @@ from .api_pb2 import ( # type: ignore
TextCommandRequest,
TextSensorStateResponse,
TextStateResponse,
TimeCommandRequest,
TimeStateResponse,
UnsubscribeBluetoothLEAdvertisementsRequest,
ValveCommandRequest,
ValveStateResponse,
VoiceAssistantAudio,
VoiceAssistantEventResponse,
VoiceAssistantRequest,
VoiceAssistantResponse,
VoiceAssistantTimerEventResponse,
)
TWO_CHAR = re.compile(r".{2}")
@ -360,4 +373,17 @@ MESSAGE_TYPE_TO_PROTO = {
100: ListEntitiesDateResponse,
101: DateStateResponse,
102: DateCommandRequest,
103: ListEntitiesTimeResponse,
104: TimeStateResponse,
105: TimeCommandRequest,
106: VoiceAssistantAudio,
107: ListEntitiesEventResponse,
108: EventResponse,
109: ListEntitiesValveResponse,
110: ValveStateResponse,
111: ValveCommandRequest,
112: ListEntitiesDateTimeResponse,
113: DateTimeStateResponse,
114: DateTimeCommandRequest,
115: VoiceAssistantTimerEventResponse,
}

View File

@ -120,6 +120,17 @@ class BluetoothProxySubscriptionFlag(enum.IntFlag):
RAW_ADVERTISEMENTS = 1 << 0
class VoiceAssistantFeature(enum.IntFlag):
VOICE_ASSISTANT = 1 << 0
SPEAKER = 1 << 1
API_AUDIO = 1 << 2
TIMERS = 1 << 3
class VoiceAssistantSubscriptionFlag(enum.IntFlag):
API_AUDIO = 1 << 2
@_frozen_dataclass_decorator
class DeviceInfo(APIModelBase):
uses_password: bool = False
@ -134,7 +145,8 @@ class DeviceInfo(APIModelBase):
project_name: str = ""
project_version: str = ""
webserver_port: int = 0
voice_assistant_version: int = 0
legacy_voice_assistant_version: int = 0
voice_assistant_feature_flags: int = 0
legacy_bluetooth_proxy_version: int = 0
bluetooth_proxy_feature_flags: int = 0
suggested_area: str = ""
@ -155,6 +167,16 @@ class DeviceInfo(APIModelBase):
return flags
return self.bluetooth_proxy_feature_flags
def voice_assistant_feature_flags_compat(self, api_version: APIVersion) -> int:
if api_version < APIVersion(1, 10):
flags: int = 0
if self.legacy_voice_assistant_version >= 1:
flags |= VoiceAssistantFeature.VOICE_ASSISTANT
if self.legacy_voice_assistant_version == 2:
flags |= VoiceAssistantFeature.SPEAKER
return flags
return self.voice_assistant_feature_flags
class EntityCategory(APIIntEnum):
NONE = 0
@ -241,6 +263,18 @@ class CoverState(EntityState):
return self.position == 0.0
# ==================== EVENT ==================
@_frozen_dataclass_decorator
class EventInfo(EntityInfo):
device_class: str = ""
event_types: list[str] = converter_field(default_factory=list, converter=list)
@_frozen_dataclass_decorator
class Event(EntityState):
event_type: str = ""
# ==================== FAN ====================
@_frozen_dataclass_decorator
class FanInfo(EntityInfo):
@ -653,6 +687,34 @@ class DateState(EntityState):
day: int = 0
# ==================== DATETIME TIME ====================
@_frozen_dataclass_decorator
class TimeInfo(EntityInfo):
pass
@_frozen_dataclass_decorator
class TimeState(EntityState):
missing_state: bool = False
hour: int = 0
minute: int = 0
second: int = 0
# ==================== DATETIME DATETIME ====================
@_frozen_dataclass_decorator
class DateTimeInfo(EntityInfo):
pass
@_frozen_dataclass_decorator
class DateTimeState(EntityState):
missing_state: bool = False
epoch_seconds: int = 0
# ==================== SELECT ====================
@_frozen_dataclass_decorator
class SelectInfo(EntityInfo):
@ -716,6 +778,31 @@ class LockEntityState(EntityState):
)
# ==================== VALVE ====================
@_frozen_dataclass_decorator
class ValveInfo(EntityInfo):
device_class: str = ""
assumed_state: bool = False
supports_stop: bool = False
supports_position: bool = False
class ValveOperation(APIIntEnum):
IDLE = 0
IS_OPENING = 1
IS_CLOSING = 2
@_frozen_dataclass_decorator
class ValveState(EntityState):
position: float = converter_field(
default=0.0, converter=fix_float_single_double_conversion
)
current_operation: ValveOperation | None = converter_field(
default=ValveOperation.IDLE, converter=ValveOperation.convert
)
# ==================== MEDIA PLAYER ====================
class MediaPlayerState(APIIntEnum):
NONE = 0
@ -823,6 +910,7 @@ COMPONENT_TYPE_TO_INFO: dict[str, type[EntityInfo]] = {
"climate": ClimateInfo,
"number": NumberInfo,
"date": DateInfo,
"datetime": DateTimeInfo,
"select": SelectInfo,
"siren": SirenInfo,
"button": ButtonInfo,
@ -830,6 +918,9 @@ COMPONENT_TYPE_TO_INFO: dict[str, type[EntityInfo]] = {
"media_player": MediaPlayerInfo,
"alarm_control_panel": AlarmControlPanelInfo,
"text": TextInfo,
"time": TimeInfo,
"valve": ValveInfo,
"event": EventInfo,
}
@ -1135,6 +1226,12 @@ class VoiceAssistantCommand(APIModelBase):
wake_word_phrase: str = ""
@_frozen_dataclass_decorator
class VoiceAssistantAudioData(APIModelBase):
data: bytes = field(default_factory=bytes) # pylint: disable=invalid-field-call
end: bool = False
class LogLevel(APIIntEnum):
LOG_LEVEL_NONE = 0
LOG_LEVEL_ERROR = 1
@ -1164,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",
@ -1172,6 +1276,7 @@ _TYPE_TO_NAME = {
LightInfo: "light",
NumberInfo: "number",
DateInfo: "date",
DateTimeInfo: "datetime",
SelectInfo: "select",
SensorInfo: "sensor",
SirenInfo: "siren",
@ -1183,6 +1288,9 @@ _TYPE_TO_NAME = {
MediaPlayerInfo: "media_player",
AlarmControlPanelInfo: "alarm_control_panel",
TextInfo: "text_info",
TimeInfo: "time",
ValveInfo: "valve",
EventInfo: "event",
}

View File

@ -8,6 +8,8 @@ from .api_pb2 import ( # type: ignore
ClimateStateResponse,
CoverStateResponse,
DateStateResponse,
DateTimeStateResponse,
EventResponse,
FanStateResponse,
LightStateResponse,
ListEntitiesAlarmControlPanelResponse,
@ -17,6 +19,8 @@ from .api_pb2 import ( # type: ignore
ListEntitiesClimateResponse,
ListEntitiesCoverResponse,
ListEntitiesDateResponse,
ListEntitiesDateTimeResponse,
ListEntitiesEventResponse,
ListEntitiesFanResponse,
ListEntitiesLightResponse,
ListEntitiesLockResponse,
@ -29,6 +33,8 @@ from .api_pb2 import ( # type: ignore
ListEntitiesSwitchResponse,
ListEntitiesTextResponse,
ListEntitiesTextSensorResponse,
ListEntitiesTimeResponse,
ListEntitiesValveResponse,
LockStateResponse,
MediaPlayerStateResponse,
NumberStateResponse,
@ -38,6 +44,8 @@ from .api_pb2 import ( # type: ignore
SwitchStateResponse,
TextSensorStateResponse,
TextStateResponse,
TimeStateResponse,
ValveStateResponse,
)
from .model import (
AlarmControlPanelEntityState,
@ -52,8 +60,12 @@ from .model import (
CoverState,
DateInfo,
DateState,
DateTimeInfo,
DateTimeState,
EntityInfo,
EntityState,
Event,
EventInfo,
FanInfo,
FanState,
LightInfo,
@ -76,45 +88,57 @@ from .model import (
TextSensorInfo,
TextSensorState,
TextState,
TimeInfo,
TimeState,
ValveInfo,
ValveState,
)
SUBSCRIBE_STATES_RESPONSE_TYPES: dict[Any, type[EntityState]] = {
AlarmControlPanelStateResponse: AlarmControlPanelEntityState,
BinarySensorStateResponse: BinarySensorState,
ClimateStateResponse: ClimateState,
CoverStateResponse: CoverState,
DateStateResponse: DateState,
DateTimeStateResponse: DateTimeState,
EventResponse: Event,
FanStateResponse: FanState,
LightStateResponse: LightState,
LockStateResponse: LockEntityState,
MediaPlayerStateResponse: MediaPlayerEntityState,
NumberStateResponse: NumberState,
DateStateResponse: DateState,
SelectStateResponse: SelectState,
SensorStateResponse: SensorState,
SirenStateResponse: SirenState,
SwitchStateResponse: SwitchState,
TextStateResponse: TextState,
TextSensorStateResponse: TextSensorState,
ClimateStateResponse: ClimateState,
LockStateResponse: LockEntityState,
MediaPlayerStateResponse: MediaPlayerEntityState,
AlarmControlPanelStateResponse: AlarmControlPanelEntityState,
TextStateResponse: TextState,
TimeStateResponse: TimeState,
ValveStateResponse: ValveState,
}
LIST_ENTITIES_SERVICES_RESPONSE_TYPES: dict[Any, type[EntityInfo] | None] = {
ListEntitiesAlarmControlPanelResponse: AlarmControlPanelInfo,
ListEntitiesBinarySensorResponse: BinarySensorInfo,
ListEntitiesButtonResponse: ButtonInfo,
ListEntitiesCameraResponse: CameraInfo,
ListEntitiesClimateResponse: ClimateInfo,
ListEntitiesCoverResponse: CoverInfo,
ListEntitiesDateResponse: DateInfo,
ListEntitiesDateTimeResponse: DateTimeInfo,
ListEntitiesEventResponse: EventInfo,
ListEntitiesFanResponse: FanInfo,
ListEntitiesLightResponse: LightInfo,
ListEntitiesLockResponse: LockInfo,
ListEntitiesMediaPlayerResponse: MediaPlayerInfo,
ListEntitiesNumberResponse: NumberInfo,
ListEntitiesDateResponse: DateInfo,
ListEntitiesSelectResponse: SelectInfo,
ListEntitiesSensorResponse: SensorInfo,
ListEntitiesServicesResponse: None,
ListEntitiesSirenResponse: SirenInfo,
ListEntitiesSwitchResponse: SwitchInfo,
ListEntitiesTextResponse: TextInfo,
ListEntitiesTextSensorResponse: TextSensorInfo,
ListEntitiesServicesResponse: None,
ListEntitiesCameraResponse: CameraInfo,
ListEntitiesClimateResponse: ClimateInfo,
ListEntitiesLockResponse: LockInfo,
ListEntitiesMediaPlayerResponse: MediaPlayerInfo,
ListEntitiesAlarmControlPanelResponse: AlarmControlPanelInfo,
ListEntitiesTimeResponse: TimeInfo,
ListEntitiesValveResponse: ValveInfo,
}

View File

@ -413,16 +413,11 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
self._cli.log_name,
record_update.new,
)
# We can't stop the zeroconf listener here because we are in the middle of
# a zeroconf callback which is iterating the listeners.
#
# So we schedule a stop for the next event loop iteration as well as the
# connect attempt.
#
# If we scheduled the connect attempt immediately, the listener could fire
# again before the connect attempt and we cancel and reschedule the connect
# attempt again.
#
self.loop.call_soon(self._connect_from_zeroconf)
self._connect_from_zeroconf()
self._accept_zeroconf_records = False
return

View File

@ -1,7 +1,7 @@
aiohappyeyeballs>=2.3.0
async-interrupt>=1.1.1
protobuf>=3.19.0
zeroconf>=0.128.4,<1.0
zeroconf>=0.132.2,<1.0
chacha20poly1305-reuseable>=0.12.1
cryptography>=42.0.2
noiseprotocol>=0.3.1,<1.0

View File

@ -1,10 +1,10 @@
pylint==3.1.0
black==24.2.0
pylint==3.2.2
black==24.4.2
flake8==7.0.0
isort==5.13.2
mypy==1.8.0
types-protobuf==4.24.0.20240129
mypy==1.10.0
types-protobuf==5.26.0.20240422
pytest>=6.2.4,<9
pytest-asyncio==0.23.5
pytest-asyncio==0.23.7
mock>=4.0.3,<6
pytest-cov>=4.1.0

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 = "23.1.1"
VERSION = "24.5.1"
PROJECT_NAME = "aioesphomeapi"
PROJECT_PACKAGE_NAME = "aioesphomeapi"
PROJECT_LICENSE = "MIT"

View File

@ -42,6 +42,7 @@ from aioesphomeapi.api_pb2 import (
ClimateCommandRequest,
CoverCommandRequest,
DateCommandRequest,
DateTimeCommandRequest,
DeviceInfoResponse,
DisconnectResponse,
ExecuteServiceArgument,
@ -63,11 +64,15 @@ from aioesphomeapi.api_pb2 import (
SubscribeVoiceAssistantRequest,
SwitchCommandRequest,
TextCommandRequest,
TimeCommandRequest,
ValveCommandRequest,
VoiceAssistantAudio,
VoiceAssistantAudioSettings,
VoiceAssistantEventData,
VoiceAssistantEventResponse,
VoiceAssistantRequest,
VoiceAssistantResponse,
VoiceAssistantTimerEventResponse,
)
from aioesphomeapi.client import APIClient, BluetoothConnectionDroppedError
from aioesphomeapi.connection import APIConnection
@ -109,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 (
@ -641,6 +649,54 @@ async def test_date_command(
send.assert_called_once_with(DateCommandRequest(**req))
# Test time command
@pytest.mark.asyncio
@pytest.mark.parametrize(
"cmd, req",
[
(
dict(key=1, hour=12, minute=30, second=30),
dict(key=1, hour=12, minute=30, second=30),
),
(
dict(key=1, hour=0, minute=0, second=0),
dict(key=1, hour=0, minute=0, second=0),
),
],
)
async def test_time_command(
auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]
) -> None:
send = patch_send(auth_client)
auth_client.time_command(**cmd)
send.assert_called_once_with(TimeCommandRequest(**req))
# Test date_time command
@pytest.mark.asyncio
@pytest.mark.parametrize(
"cmd, req",
[
(
dict(key=1, epoch_seconds=1735648230),
dict(key=1, epoch_seconds=1735648230),
),
(
dict(key=1, epoch_seconds=1735689600),
dict(key=1, epoch_seconds=1735689600),
),
],
)
async def test_datetime_command(
auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]
) -> None:
send = patch_send(auth_client)
auth_client.datetime_command(**cmd)
send.assert_called_once_with(DateTimeCommandRequest(**req))
@pytest.mark.asyncio
@pytest.mark.parametrize(
"cmd, req",
@ -666,6 +722,49 @@ async def test_lock_command(
send.assert_called_once_with(LockCommandRequest(**req))
@pytest.mark.asyncio
@pytest.mark.parametrize(
"cmd, req",
[
(dict(key=1), dict(key=1)),
(dict(key=1, position=1.0),),
(dict(key=1, position=0.0),),
(dict(key=1, stop=True),),
],
)
async def test_valve_command(
auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]
) -> None:
send = patch_send(auth_client)
auth_client.valve_command(**cmd)
send.assert_called_once_with(ValveCommandRequest(**req))
@pytest.mark.asyncio
@pytest.mark.parametrize(
"cmd, req",
[
(dict(key=1), dict(key=1)),
(dict(key=1, position=0.5), dict(key=1, has_position=True, position=0.5)),
(dict(key=1, position=0.0), dict(key=1, has_position=True, position=0.0)),
(dict(key=1, stop=True), dict(key=1, stop=True)),
(
dict(key=1, position=1.0),
dict(key=1, has_position=True, position=1.0),
),
],
)
async def test_valve_command(
auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]
) -> None:
send = patch_send(auth_client)
patch_api_version(auth_client, APIVersion(1, 1))
auth_client.valve_command(**cmd)
send.assert_called_once_with(ValveCommandRequest(**req))
@pytest.mark.asyncio
@pytest.mark.parametrize(
"cmd, req",
@ -699,6 +798,16 @@ async def test_select_command(
dict(key=1, media_url="http://example.com"),
dict(key=1, has_media_url=True, media_url="http://example.com"),
),
(
dict(key=1, media_url="http://example.com", announcement=True),
dict(
key=1,
has_media_url=True,
media_url="http://example.com",
has_announcement=True,
announcement=True,
),
),
],
)
async def test_media_player_command(
@ -2082,7 +2191,9 @@ async def test_subscribe_voice_assistant(
async def handle_stop() -> None:
stops.append(True)
unsub = client.subscribe_voice_assistant(handle_start, handle_stop)
unsub = client.subscribe_voice_assistant(
handle_start=handle_start, handle_stop=handle_stop
)
send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=True))
send.reset_mock()
audio_settings = VoiceAssistantAudioSettings(
@ -2158,7 +2269,9 @@ async def test_subscribe_voice_assistant_failure(
async def handle_stop() -> None:
stops.append(True)
unsub = client.subscribe_voice_assistant(handle_start, handle_stop)
unsub = client.subscribe_voice_assistant(
handle_start=handle_start, handle_stop=handle_stop
)
send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=True))
send.reset_mock()
audio_settings = VoiceAssistantAudioSettings(
@ -2235,7 +2348,9 @@ async def test_subscribe_voice_assistant_cancels_long_running_handle_start(
async def handle_stop() -> None:
stops.append(True)
unsub = client.subscribe_voice_assistant(handle_start, handle_stop)
unsub = client.subscribe_voice_assistant(
handle_start=handle_start, handle_stop=handle_stop
)
send.assert_called_once_with(SubscribeVoiceAssistantRequest(subscribe=True))
send.reset_mock()
audio_settings = VoiceAssistantAudioSettings(
@ -2269,6 +2384,136 @@ async def test_subscribe_voice_assistant_cancels_long_running_handle_start(
]
@pytest.mark.asyncio
async def test_subscribe_voice_assistant_api_audio(
api_client: tuple[
APIClient, APIConnection, asyncio.Transport, APIPlaintextFrameHelper
],
) -> None:
"""Test subscribe_voice_assistant."""
client, connection, transport, protocol = api_client
send = patch_send(client)
starts = []
stops = []
data_received = 0
async def handle_start(
conversation_id: str,
flags: int,
audio_settings: VoiceAssistantAudioSettings,
wake_word_phrase: str | None,
) -> int | None:
starts.append((conversation_id, flags, audio_settings, wake_word_phrase))
return 0
async def handle_stop() -> None:
stops.append(True)
async def handle_audio(data: bytes) -> None:
nonlocal data_received
data_received += len(data)
unsub = client.subscribe_voice_assistant(
handle_start=handle_start, handle_stop=handle_stop, handle_audio=handle_audio
)
send.assert_called_once_with(
SubscribeVoiceAssistantRequest(subscribe=True, flags=4)
)
send.reset_mock()
audio_settings = VoiceAssistantAudioSettings(
noise_suppression_level=42,
auto_gain=42,
volume_multiplier=42,
)
response: message.Message = VoiceAssistantRequest(
conversation_id="theone",
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)
await asyncio.sleep(0)
assert starts == [
(
"theone",
42,
VoiceAssistantAudioSettingsModel(
noise_suppression_level=42,
auto_gain=42,
volume_multiplier=42,
),
"okay nabu",
)
]
assert stops == []
send.assert_called_once_with(VoiceAssistantResponse(port=0))
send.reset_mock()
response: message.Message = VoiceAssistantAudio(
data=bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
)
mock_data_received(protocol, generate_plaintext_packet(response))
await asyncio.sleep(0)
assert data_received == 10
response: message.Message = VoiceAssistantAudio(
end=True,
)
mock_data_received(protocol, generate_plaintext_packet(response))
await asyncio.sleep(0)
assert stops == [True]
send.reset_mock()
client.send_voice_assistant_audio(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
send.assert_called_once_with(
VoiceAssistantAudio(data=bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
)
response: message.Message = VoiceAssistantRequest(
conversation_id="theone",
start=False,
)
mock_data_received(protocol, generate_plaintext_packet(response))
await asyncio.sleep(0)
assert stops == [True, 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
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[
@ -2306,6 +2551,7 @@ async def test_calls_after_connection_closed(
client.cover_command,
client.fan_command,
client.light_command,
client.valve_command,
client.media_player_command,
client.siren_command,
):

View File

@ -14,7 +14,9 @@ from aioesphomeapi.api_pb2 import (
ClimateStateResponse,
CoverStateResponse,
DateStateResponse,
DateTimeStateResponse,
DeviceInfoResponse,
EventResponse,
FanStateResponse,
HomeassistantServiceMap,
HomeassistantServiceResponse,
@ -25,6 +27,8 @@ from aioesphomeapi.api_pb2 import (
ListEntitiesClimateResponse,
ListEntitiesCoverResponse,
ListEntitiesDateResponse,
ListEntitiesDateTimeResponse,
ListEntitiesEventResponse,
ListEntitiesFanResponse,
ListEntitiesLightResponse,
ListEntitiesLockResponse,
@ -36,6 +40,8 @@ from aioesphomeapi.api_pb2 import (
ListEntitiesServicesResponse,
ListEntitiesSwitchResponse,
ListEntitiesTextSensorResponse,
ListEntitiesTimeResponse,
ListEntitiesValveResponse,
LockStateResponse,
MediaPlayerStateResponse,
NumberStateResponse,
@ -45,6 +51,8 @@ from aioesphomeapi.api_pb2 import (
SwitchStateResponse,
TextSensorStateResponse,
TextStateResponse,
TimeStateResponse,
ValveStateResponse,
)
from aioesphomeapi.model import (
_TYPE_TO_NAME,
@ -73,7 +81,11 @@ from aioesphomeapi.model import (
CoverState,
DateInfo,
DateState,
DateTimeInfo,
DateTimeState,
DeviceInfo,
Event,
EventInfo,
FanInfo,
FanState,
HomeassistantServiceCall,
@ -98,9 +110,14 @@ from aioesphomeapi.model import (
TextSensorInfo,
TextSensorState,
TextState,
TimeInfo,
TimeState,
UserService,
UserServiceArg,
UserServiceArgType,
ValveInfo,
ValveState,
VoiceAssistantFeature,
build_unique_id,
converter_field,
)
@ -256,11 +273,19 @@ def test_api_version_ord():
(ButtonInfo, ListEntitiesButtonResponse),
(LockInfo, ListEntitiesLockResponse),
(LockEntityState, LockStateResponse),
(ValveInfo, ListEntitiesValveResponse),
(ValveState, ValveStateResponse),
(MediaPlayerInfo, ListEntitiesMediaPlayerResponse),
(MediaPlayerEntityState, MediaPlayerStateResponse),
(AlarmControlPanelInfo, ListEntitiesAlarmControlPanelResponse),
(AlarmControlPanelEntityState, AlarmControlPanelStateResponse),
(TextState, TextStateResponse),
(TimeInfo, ListEntitiesTimeResponse),
(TimeState, TimeStateResponse),
(DateTimeInfo, ListEntitiesDateTimeResponse),
(DateTimeState, DateTimeStateResponse),
(EventInfo, ListEntitiesEventResponse),
(Event, EventResponse),
],
)
def test_basic_pb_conversions(model, pb):
@ -373,9 +398,11 @@ def test_user_service_conversion():
CameraInfo,
ClimateInfo,
LockInfo,
ValveInfo,
MediaPlayerInfo,
AlarmControlPanelInfo,
TextInfo,
TimeInfo,
],
)
def test_build_unique_id(model):
@ -425,6 +452,24 @@ def test_bluetooth_backcompat_for_device_info(
assert info.bluetooth_proxy_feature_flags_compat(APIVersion(1, 9)) == 42
# Add va compat test
@pytest.mark.parametrize(
("version", "flags"),
[
(1, VoiceAssistantFeature.VOICE_ASSISTANT),
(2, VoiceAssistantFeature.VOICE_ASSISTANT | VoiceAssistantFeature.SPEAKER),
],
)
def test_voice_assistant_backcompat_for_device_info(
version: int, flags: VoiceAssistantFeature
) -> None:
info = DeviceInfo(
legacy_voice_assistant_version=version, voice_assistant_feature_flags=42
)
assert info.voice_assistant_feature_flags_compat(APIVersion(1, 9)) is flags
assert info.voice_assistant_feature_flags_compat(APIVersion(1, 10)) == 42
@pytest.mark.parametrize(
(
"legacy_supports_brightness",

View File

@ -441,8 +441,6 @@ async def test_reconnect_zeroconf(
"Triggering connect because of received mDNS record" in caplog.text
) is should_trigger_zeroconf
assert rl._accept_zeroconf_records is not should_trigger_zeroconf
assert rl._zc_listening is True # should change after one iteration of the loop
await asyncio.sleep(0)
assert rl._zc_listening is not should_trigger_zeroconf
# The reconnect is scheduled to run in the next loop iteration