Compare commits
52 Commits
Author | SHA1 | Date |
---|---|---|
github-actions[bot] | 6a23cca5d3 | |
dependabot[bot] | 44dafb9f06 | |
github-actions[bot] | 8cd85de0af | |
Jesse Hills | 0eede84ead | |
dependabot[bot] | 3bae70e462 | |
github-actions[bot] | 2ae6ff8338 | |
dependabot[bot] | 24652a226d | |
dependabot[bot] | e8d27e514e | |
github-actions[bot] | d62d67f585 | |
Mischa Siekmann | 8778ad485c | |
dependabot[bot] | 8e6717c197 | |
dependabot[bot] | adcd5b1a13 | |
dependabot[bot] | 6e2d5d4fde | |
dependabot[bot] | 8dd044e89d | |
github-actions[bot] | e97a716d44 | |
dependabot[bot] | ab390acf93 | |
github-actions[bot] | 1c4d7a60bb | |
David Friedland | f1538a7ed0 | |
github-actions[bot] | e88f1468cb | |
Jesse Hills | 397c64f3e3 | |
github-actions[bot] | 0257210087 | |
Jesse Hills | b935707ceb | |
dependabot[bot] | 27247a5192 | |
github-actions[bot] | 01eaee25c0 | |
J. Nick Koston | 4cff8555d2 | |
github-actions[bot] | 56369fb332 | |
Keith Burzinski | 0ed69bbb30 | |
dependabot[bot] | b10cbd6c9a | |
dependabot[bot] | d9dde5bc14 | |
Jesse Hills | 0ad9dd5aa5 | |
Jesse Hills | 725e501815 | |
dependabot[bot] | 78f6ed9e63 | |
dependabot[bot] | c3b31878d3 | |
dependabot[bot] | 301cf02153 | |
dependabot[bot] | 6a8185e70d | |
dependabot[bot] | ce3513153c | |
github-actions[bot] | 6b5c6ed20b | |
dependabot[bot] | 96f4171d4f | |
dependabot[bot] | c1585b59a0 | |
dependabot[bot] | 10a00aed17 | |
github-actions[bot] | 3da9d7f8ca | |
Jesse Hills | 27a968df1b | |
github-actions[bot] | 15d1949654 | |
Jesse Hills | 7da8a353cd | |
dependabot[bot] | ff23e4c9a0 | |
dependabot[bot] | 6bb219ef35 | |
dependabot[bot] | d52d2e2a09 | |
github-actions[bot] | bcebfd29e4 | |
dependabot[bot] | 9f0a1a22ec | |
J. Nick Koston | e4ab837111 | |
github-actions[bot] | 73a40131be | |
J. Nick Koston | eabc3d421f |
|
@ -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,
|
||||
|
|
|
@ -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: |
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
@ -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 (
|
||||
|
@ -928,6 +936,7 @@ class APIClient:
|
|||
tilt: float | None = None,
|
||||
stop: bool = False,
|
||||
) -> None:
|
||||
connection = self._get_connection()
|
||||
req = CoverCommandRequest(key=key)
|
||||
apiv = self.api_version
|
||||
if TYPE_CHECKING:
|
||||
|
@ -951,7 +960,7 @@ class APIClient:
|
|||
elif position == 0.0:
|
||||
req.legacy_command = LegacyCoverCommand.CLOSE
|
||||
req.has_legacy_command = True
|
||||
self._get_connection().send_message(req)
|
||||
connection.send_message(req)
|
||||
|
||||
def fan_command(
|
||||
self,
|
||||
|
@ -1058,6 +1067,7 @@ class APIClient:
|
|||
custom_preset: str | None = None,
|
||||
target_humidity: float | None = None,
|
||||
) -> None:
|
||||
connection = self._get_connection()
|
||||
req = ClimateCommandRequest(key=key)
|
||||
if mode is not None:
|
||||
req.has_mode = True
|
||||
|
@ -1096,7 +1106,7 @@ class APIClient:
|
|||
if target_humidity is not None:
|
||||
req.has_target_humidity = True
|
||||
req.target_humidity = target_humidity
|
||||
self._get_connection().send_message(req)
|
||||
connection.send_message(req)
|
||||
|
||||
def number_command(self, key: int, state: float) -> None:
|
||||
self._get_connection().send_message(NumberCommandRequest(key=key, state=state))
|
||||
|
@ -1106,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))
|
||||
|
||||
|
@ -1146,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,
|
||||
|
@ -1153,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:
|
||||
|
@ -1164,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:
|
||||
|
@ -1172,6 +1217,7 @@ class APIClient:
|
|||
def execute_service(
|
||||
self, service: UserService, data: ExecuteServiceDataType
|
||||
) -> None:
|
||||
connection = self._get_connection()
|
||||
req = ExecuteServiceRequest(key=service.key)
|
||||
args = []
|
||||
apiv = self.api_version
|
||||
|
@ -1196,7 +1242,7 @@ class APIClient:
|
|||
# pylint: disable=no-member
|
||||
req.args.extend(args)
|
||||
|
||||
self._get_connection().send_message(req)
|
||||
connection.send_message(req)
|
||||
|
||||
def _request_image(self, *, single: bool = False, stream: bool = False) -> None:
|
||||
self._get_connection().send_message(
|
||||
|
@ -1217,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.
|
||||
|
||||
|
@ -1267,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)
|
||||
)
|
||||
|
@ -1307,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,
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
2
setup.py
2
setup.py
|
@ -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.0"
|
||||
VERSION = "24.5.1"
|
||||
PROJECT_NAME = "aioesphomeapi"
|
||||
PROJECT_PACKAGE_NAME = "aioesphomeapi"
|
||||
PROJECT_LICENSE = "MIT"
|
||||
|
|
|
@ -57,7 +57,7 @@ def patchable_api_client() -> APIClient:
|
|||
pass
|
||||
|
||||
cli = PatchableAPIClient(
|
||||
address="1.2.3.4",
|
||||
address="127.0.0.1",
|
||||
port=6052,
|
||||
password=None,
|
||||
)
|
||||
|
|
|
@ -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 (
|
||||
|
@ -203,7 +211,7 @@ async def test_finish_connection_wraps_exceptions_as_unhandled_api_error(
|
|||
) -> None:
|
||||
"""Verify finish_connect re-wraps exceptions as UnhandledAPIError."""
|
||||
|
||||
cli = APIClient("1.2.3.4", 1234, None)
|
||||
cli = APIClient("127.0.0.1", 1234, None)
|
||||
with patch("aioesphomeapi.client.APIConnection", PatchableAPIConnection):
|
||||
await cli.start_connection()
|
||||
|
||||
|
@ -219,7 +227,7 @@ async def test_finish_connection_wraps_exceptions_as_unhandled_api_error(
|
|||
@pytest.mark.asyncio
|
||||
async def test_connection_released_if_connecting_is_cancelled() -> None:
|
||||
"""Verify connection is unset if connecting is cancelled."""
|
||||
cli = APIClient("1.2.3.4", 1234, None)
|
||||
cli = APIClient("127.0.0.1", 1234, None)
|
||||
asyncio.get_event_loop()
|
||||
|
||||
async def _start_connection_with_delay(*args, **kwargs):
|
||||
|
@ -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(
|
||||
|
@ -930,7 +1039,7 @@ async def test_noise_psk_handles_subclassed_string():
|
|||
pass
|
||||
|
||||
cli = PatchableAPIClient(
|
||||
address=Estr("1.2.3.4"),
|
||||
address=Estr("127.0.0.1"),
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk=Estr("QRTIErOb/fcE9Ukd/5qA3RGYMn0Y+p06U58SCtOXvPc="),
|
||||
|
@ -966,7 +1075,7 @@ async def test_noise_psk_handles_subclassed_string():
|
|||
async def test_no_noise_psk():
|
||||
"""Test not using a noise_psk."""
|
||||
cli = APIClient(
|
||||
address=Estr("1.2.3.4"),
|
||||
address=Estr("127.0.0.1"),
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk=None,
|
||||
|
@ -982,7 +1091,7 @@ async def test_no_noise_psk():
|
|||
async def test_empty_noise_psk_or_expected_name():
|
||||
"""Test an empty noise_psk is treated as None."""
|
||||
cli = APIClient(
|
||||
address=Estr("1.2.3.4"),
|
||||
address=Estr("127.0.0.1"),
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk="",
|
||||
|
@ -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[
|
||||
|
@ -2280,3 +2525,56 @@ async def test_api_version_after_connection_closed(
|
|||
assert client.api_version == APIVersion(1, 9)
|
||||
await client.disconnect(force=True)
|
||||
assert client.api_version is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_calls_after_connection_closed(
|
||||
api_client: tuple[
|
||||
APIClient, APIConnection, asyncio.Transport, APIPlaintextFrameHelper
|
||||
],
|
||||
) -> None:
|
||||
"""Test calls after connection close should raise APIConnectionError."""
|
||||
client, connection, transport, protocol = api_client
|
||||
assert client.api_version == APIVersion(1, 9)
|
||||
await client.disconnect(force=True)
|
||||
assert client.api_version is None
|
||||
service = UserService(
|
||||
name="my_service",
|
||||
key=1,
|
||||
args=[],
|
||||
)
|
||||
with pytest.raises(APIConnectionError):
|
||||
client.execute_service(service, {})
|
||||
for method in (
|
||||
client.button_command,
|
||||
client.climate_command,
|
||||
client.cover_command,
|
||||
client.fan_command,
|
||||
client.light_command,
|
||||
client.valve_command,
|
||||
client.media_player_command,
|
||||
client.siren_command,
|
||||
):
|
||||
with pytest.raises(APIConnectionError):
|
||||
await method(1)
|
||||
|
||||
with pytest.raises(APIConnectionError):
|
||||
await client.alarm_control_panel_command(1, AlarmControlPanelCommand.ARM_HOME)
|
||||
|
||||
with pytest.raises(APIConnectionError):
|
||||
await client.date_command(1, 1, 1, 1)
|
||||
|
||||
with pytest.raises(APIConnectionError):
|
||||
await client.lock_command(1, LockCommand.LOCK)
|
||||
|
||||
with pytest.raises(APIConnectionError):
|
||||
await client.number_command(1, 1)
|
||||
|
||||
with pytest.raises(APIConnectionError):
|
||||
await client.select_command(1, "1")
|
||||
|
||||
with pytest.raises(APIConnectionError):
|
||||
await client.switch_command(1, True)
|
||||
|
||||
with pytest.raises(APIConnectionError):
|
||||
await client.text_command(1, "1")
|
||||
|
|
|
@ -46,7 +46,7 @@ async def test_log_runner(
|
|||
async_zeroconf = get_mock_async_zeroconf()
|
||||
|
||||
cli = PatchableAPIClient(
|
||||
address=Estr("1.2.3.4"),
|
||||
address=Estr("127.0.0.1"),
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk=None,
|
||||
|
@ -115,7 +115,7 @@ async def test_log_runner_reconnects_on_disconnect(
|
|||
async_zeroconf = get_mock_async_zeroconf()
|
||||
|
||||
cli = PatchableAPIClient(
|
||||
address=Estr("1.2.3.4"),
|
||||
address=Estr("127.0.0.1"),
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk=None,
|
||||
|
@ -195,7 +195,7 @@ async def test_log_runner_reconnects_on_subscribe_failure(
|
|||
async_zeroconf = get_mock_async_zeroconf()
|
||||
|
||||
cli = PatchableAPIClient(
|
||||
address=Estr("1.2.3.4"),
|
||||
address=Estr("127.0.0.1"),
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk=None,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -102,7 +102,7 @@ async def test_reconnect_logic_name_from_host_and_set():
|
|||
async def test_reconnect_logic_name_from_address():
|
||||
"""Test that the name is set correctly from the address."""
|
||||
cli = APIClient(
|
||||
address="1.2.3.4",
|
||||
address="127.0.0.1",
|
||||
port=6052,
|
||||
password=None,
|
||||
)
|
||||
|
@ -119,14 +119,14 @@ async def test_reconnect_logic_name_from_address():
|
|||
on_connect=on_connect,
|
||||
zeroconf_instance=get_mock_zeroconf(),
|
||||
)
|
||||
assert cli.log_name == "1.2.3.4"
|
||||
assert cli.log_name == "127.0.0.1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reconnect_logic_name_from_name():
|
||||
"""Test that the name is set correctly from the address."""
|
||||
cli = APIClient(
|
||||
address="1.2.3.4",
|
||||
address="127.0.0.1",
|
||||
port=6052,
|
||||
password=None,
|
||||
)
|
||||
|
@ -144,7 +144,7 @@ async def test_reconnect_logic_name_from_name():
|
|||
zeroconf_instance=get_mock_zeroconf(),
|
||||
name="mydevice",
|
||||
)
|
||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
||||
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -201,7 +201,7 @@ async def test_reconnect_logic_state(patchable_api_client: APIClient):
|
|||
name="mydevice",
|
||||
on_connect_error=on_connect_fail,
|
||||
)
|
||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
||||
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||
|
||||
with patch.object(cli, "start_connection", side_effect=APIConnectionError):
|
||||
await rl.start()
|
||||
|
@ -274,7 +274,7 @@ async def test_reconnect_retry(
|
|||
name="mydevice",
|
||||
on_connect_error=on_connect_fail,
|
||||
)
|
||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
||||
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||
caplog.clear()
|
||||
|
||||
with patch.object(cli, "start_connection", side_effect=APIConnectionError):
|
||||
|
@ -288,9 +288,9 @@ async def test_reconnect_retry(
|
|||
assert len(on_connect_fail_called) == 1
|
||||
assert isinstance(on_connect_fail_called[-1], APIConnectionError)
|
||||
assert rl._connection_state is ReconnectLogicState.DISCONNECTED
|
||||
assert "connect to ESPHome API for mydevice @ 1.2.3.4" in caplog.text
|
||||
assert "connect to ESPHome API for mydevice @ 127.0.0.1" in caplog.text
|
||||
for record in caplog.records:
|
||||
if "connect to ESPHome API for mydevice @ 1.2.3.4" in record.message:
|
||||
if "connect to ESPHome API for mydevice @ 127.0.0.1" in record.message:
|
||||
assert record.levelno == logging.WARNING
|
||||
|
||||
caplog.clear()
|
||||
|
@ -307,9 +307,9 @@ async def test_reconnect_retry(
|
|||
assert len(on_connect_fail_called) == 2
|
||||
assert isinstance(on_connect_fail_called[-1], APIConnectionError)
|
||||
assert rl._connection_state is ReconnectLogicState.DISCONNECTED
|
||||
assert "connect to ESPHome API for mydevice @ 1.2.3.4" in caplog.text
|
||||
assert "connect to ESPHome API for mydevice @ 127.0.0.1" in caplog.text
|
||||
for record in caplog.records:
|
||||
if "connect to ESPHome API for mydevice @ 1.2.3.4" in record.message:
|
||||
if "connect to ESPHome API for mydevice @ 127.0.0.1" in record.message:
|
||||
assert record.levelno == logging.DEBUG
|
||||
|
||||
caplog.clear()
|
||||
|
@ -320,7 +320,7 @@ async def test_reconnect_retry(
|
|||
await asyncio.sleep(0)
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert "connect to ESPHome API for mydevice @ 1.2.3.4" not in caplog.text
|
||||
assert "connect to ESPHome API for mydevice @ 127.0.0.1" not in caplog.text
|
||||
assert len(on_disconnect_called) == 0
|
||||
assert len(on_connect_called) == 1
|
||||
assert len(on_connect_fail_called) == 2
|
||||
|
@ -372,7 +372,7 @@ DNS_POINTER = DNSPointer(
|
|||
_TYPE_A,
|
||||
_CLASS_IN,
|
||||
1000,
|
||||
ip_address("1.2.3.4").packed,
|
||||
ip_address("127.0.0.1").packed,
|
||||
),
|
||||
True,
|
||||
ReconnectLogicState.READY,
|
||||
|
@ -403,7 +403,7 @@ async def test_reconnect_zeroconf(
|
|||
name="mydevice",
|
||||
on_connect_error=AsyncMock(),
|
||||
)
|
||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
||||
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||
|
||||
with patch.object(
|
||||
cli, "start_connection", side_effect=quick_connect_fail
|
||||
|
@ -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
|
||||
|
@ -474,7 +472,7 @@ async def test_reconnect_zeroconf_not_while_handshaking(
|
|||
name="mydevice",
|
||||
on_connect_error=AsyncMock(),
|
||||
)
|
||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
||||
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||
|
||||
with patch.object(
|
||||
cli, "start_connection", side_effect=quick_connect_fail
|
||||
|
@ -531,7 +529,7 @@ async def test_connect_task_not_cancelled_while_handshaking(
|
|||
name="mydevice",
|
||||
on_connect_error=AsyncMock(),
|
||||
)
|
||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
||||
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||
|
||||
with patch.object(
|
||||
cli, "start_connection", side_effect=quick_connect_fail
|
||||
|
@ -591,7 +589,7 @@ async def test_connect_aborts_if_stopped(
|
|||
name="mydevice",
|
||||
on_connect_error=AsyncMock(),
|
||||
)
|
||||
assert cli.log_name == "mydevice @ 1.2.3.4"
|
||||
assert cli.log_name == "mydevice @ 127.0.0.1"
|
||||
|
||||
with patch.object(
|
||||
cli, "start_connection", side_effect=quick_connect_fail
|
||||
|
@ -694,7 +692,7 @@ async def test_handling_unexpected_disconnect(aiohappyeyeballs_start_connection)
|
|||
async_zeroconf = get_mock_async_zeroconf()
|
||||
|
||||
cli = PatchableAPIClient(
|
||||
address="1.2.3.4",
|
||||
address="127.0.0.1",
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk=None,
|
||||
|
@ -770,7 +768,7 @@ async def test_backoff_on_encryption_error(
|
|||
async_zeroconf = get_mock_async_zeroconf()
|
||||
|
||||
cli = PatchableAPIClient(
|
||||
address="1.2.3.4",
|
||||
address="127.0.0.1",
|
||||
port=6052,
|
||||
password=None,
|
||||
noise_psk="",
|
||||
|
|
Loading…
Reference in New Issue