PyLoxone-Audio 0.1.4.post1__tar.gz → 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/API.md +13 -3
- pyloxone_audio-0.1.6/CHANGELOG.md +25 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/DIAGNOSTICS-REFERENCE.md +1 -1
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/MANIFEST.in +1 -1
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/PKG-INFO +6 -2
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/PyLoxone_Audio.egg-info/PKG-INFO +6 -2
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/PyLoxone_Audio.egg-info/SOURCES.txt +9 -1
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/README.md +5 -1
- pyloxone_audio-0.1.6/RELEASE-NOTES-0.1.6.md +19 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/__init__.py +2 -2
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/diagnostic_events.py +1 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/metadata.py +14 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/native.py +83 -15
- pyloxone_audio-0.1.6/pyloxone_audio/session.py +230 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyproject.toml +1 -1
- pyloxone_audio-0.1.6/tests/library/session_support.py +149 -0
- pyloxone_audio-0.1.6/tests/library/test_reusable_command_session.py +70 -0
- pyloxone_audio-0.1.6/tests/library/test_session_benchmark.py +54 -0
- pyloxone_audio-0.1.6/tests/library/test_session_cancelled_close.py +34 -0
- pyloxone_audio-0.1.6/tests/library/test_session_isolation.py +152 -0
- pyloxone_audio-0.1.6/tests/library/test_session_owner_controls.py +124 -0
- pyloxone_audio-0.1.6/tests/library/test_session_playback_policy.py +52 -0
- pyloxone_audio-0.1.4.post1/CHANGELOG.md +0 -13
- pyloxone_audio-0.1.4.post1/RELEASE-NOTES-0.1.4.post1.md +0 -14
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/AUTOMATION-GROUPING.md +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/DIAGNOSTICS.md +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/KNOWN-ISSUES.md +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/LICENSE +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/NOTICE.md +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/PyLoxone_Audio.egg-info/dependency_links.txt +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/PyLoxone_Audio.egg-info/requires.txt +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/PyLoxone_Audio.egg-info/top_level.txt +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/USER-GUIDE.md +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/announcement.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/catalogue.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/clock.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/grouping.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/models.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/py.typed +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/radio.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/selection.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/pyloxone_audio/sources.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/setup.cfg +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/conftest.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/fixtures/audioserver/README.md +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/fixtures/audioserver/sebastian_alarm_end.txt +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/fixtures/audioserver/sebastian_loxone_radio.json +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/fixtures/audioserver/sebastian_tts.json +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/fixtures/audioserver/sebastian_tunein.json +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/pytest.ini +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audio_grouping.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audio_modes.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_announcement.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_connection.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_events.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_library_source.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_metadata.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_playback.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_seek.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_timing.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_audioserver_wire.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_automation_group_intent.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_boundary_environment.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_boundary_ownership.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_boundary_qualification.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_diagnostic_events.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_diagnostic_operations.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_diagnostic_request_kinds.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_diagnostic_timing.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_diagnostic_wire.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_distribution_dependencies.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_exact_track_start.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_group_commands.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_group_coordinator.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_group_planning.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_group_revocation_r1.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_group_transport.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_grouping_numeric_validation.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_playback_failure_recovery.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_portable_policies.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_published_authentication.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_restore_readiness.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_room_reply_review03.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_room_transport.py +0 -0
- {pyloxone_audio-0.1.4.post1 → pyloxone_audio-0.1.6}/tests/library/test_volume_failure_recovery.py +0 -0
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
# PyLoxone-Audio 0.1.
|
|
1
|
+
# PyLoxone-Audio 0.1.6 — API and compatibility
|
|
2
|
+
|
|
3
|
+
## Command-session lifecycle
|
|
4
|
+
|
|
5
|
+
The 0.1.6 adapter explicitly enables `AudioServerCommands.reuse_session`. Direct library consumers retain the original one-shot default. One command owner belongs to one entry/server/current authentication lifetime; never share it between entries or accounts. The host publishes token revocation through `observe_authentication()` and awaits `async_close()` on unload. Changing host/options uses the existing unload/new-owner lifecycle, not mutation of an active owner's endpoint.
|
|
6
|
+
|
|
7
|
+
The reusable transport keeps the existing single-request lock, authentication/serializers and command proof. After authentication, one bounded-inbox reader owns receive. Unsolicited events are drained but are not metadata authority; command echoes must match the active command (including the vendor's search-query key convention). An uncertain, cancelled, timed-out, malformed or uncorrelated session is retired without replay. The native protocol has no demonstrated unique request ID for a delayed identical echo.
|
|
8
|
+
|
|
9
|
+
Mapped metadata bindings call `observe_playback(player_id, playing)` from native observations and revoke on removal/disconnect/stop. Positive playback has the same 30-second freshness bound as active metadata. Reconciler eligibility, source/group capability and operation fences remain separate: they must not suppress known mapped playback for retention. Any fresh playing room retains the session; after the last room stops or its lease expires, the monotonic idle allowance is five minutes. Meaningful commands renew activity; status reads and unsolicited/background frames do not. The entire request lease, including authentication, excludes idle expiry. Required reads may reconnect. Browse has no new outer lock and yields between native requests.
|
|
10
|
+
|
|
11
|
+
Diagnostics adds `session_reused` rather than inventing new connection/authentication stages for warm requests. `request_finished` still follows the actual request boundary. The Miniserver and metadata/event connections are separate and unchanged.
|
|
2
12
|
|
|
3
13
|
An Apache-2.0 Python library for native audio communication, consumed by the
|
|
4
|
-
existing PyLoxone integration. The matching reference adapter is 0.1.
|
|
14
|
+
existing PyLoxone integration. The matching reference adapter is 0.1.6
|
|
5
15
|
on stock PyLoxone 0.10.3. See [NOTICE.md](NOTICE.md) for attribution.
|
|
6
16
|
|
|
7
17
|
## Concrete public API and ownership
|
|
@@ -85,7 +95,7 @@ the supported enable/export workflow, exact bounds and evidence/privacy limits.
|
|
|
85
95
|
|
|
86
96
|
## Installation and host compatibility
|
|
87
97
|
|
|
88
|
-
Requires Python >=3.14. Install `PyLoxone-Audio==0.1.
|
|
98
|
+
Requires Python >=3.14. Install `PyLoxone-Audio==0.1.6` for standalone consumers.
|
|
89
99
|
Home Assistant users need the matching component and frontend described in the
|
|
90
100
|
[installation guide](https://github.com/davehocking/PyLoxone-Audio/blob/main/preview-build/README.md); HA installs Python dependencies.
|
|
91
101
|
Keep domain `loxone`, existing entries/entities and the exact compatible pin.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.6
|
|
4
|
+
|
|
5
|
+
- Reuse the entry-owned authenticated command connection to reduce warm command and catalogue wait-time.
|
|
6
|
+
- Keep fresh mapped playback sessions; otherwise expire after five minutes without meaningful activity.
|
|
7
|
+
- Retain request serialization, native proof, revocation and no-replay safeguards; unchanged r13 frontend.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## 0.1.5
|
|
11
|
+
|
|
12
|
+
- Matching library and reference adapter 0.1.5 with frontend r13.
|
|
13
|
+
- Short installation and maintainer guides, with an upgrade from the previous public adapter.
|
|
14
|
+
|
|
15
|
+
## 0.1.4.post1
|
|
16
|
+
|
|
17
|
+
- Documentation and packaging revision of library 0.1.4, paired with reference adapter 0.1.4 and the exact library requirement `PyLoxone-Audio==0.1.4.post1`. Audio behaviour and frontend r12 are unchanged.
|
|
18
|
+
|
|
19
|
+
## 0.1.4
|
|
20
|
+
|
|
21
|
+
- Longer bounded feedback waits for large serially qualified audio groups.
|
|
22
|
+
- Full-width group/member volume sliders with percentage and −/+ controls.
|
|
23
|
+
- Original release: library 0.1.4, reference adapter 0.10.3.dev19 and frontend r12 on stock PyLoxone 0.10.3.
|
|
24
|
+
|
|
25
|
+
[Current release notes](https://github.com/davehocking/PyLoxone-Audio/blob/v0.1.5/RELEASE-NOTES-0.1.5.md). Earlier releases remain in Git history and GitHub Releases.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Audio diagnostics and native Home Assistant tools
|
|
2
2
|
|
|
3
|
-
For library 0.1.
|
|
3
|
+
For library 0.1.6 and reference adapter 0.1.6. Start with the
|
|
4
4
|
[installation guide](https://github.com/davehocking/PyLoxone-Audio/blob/main/preview-build/README.md).
|
|
5
5
|
New users default OFF; existing saved preferences are preserved. Install the
|
|
6
6
|
matching adapter/library pair: installing only the wheel does not add the switch.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyLoxone-Audio
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: Native audio transport and source policies for PyLoxone
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Homepage, https://github.com/davehocking/PyLoxone-Audio
|
|
@@ -20,7 +20,7 @@ Dynamic: license-file
|
|
|
20
20
|
|
|
21
21
|
Audio features for [PyLoxone](https://github.com/JoDehli/PyLoxone), using your existing Home Assistant integration and room players.
|
|
22
22
|
|
|
23
|
-
**Version 0.1.
|
|
23
|
+
**Version 0.1.6:** library **0.1.6**, reference adapter **0.1.6**, frontend **r13**, based on PyLoxone **0.10.3**. Install the matching preview below; Home Assistant resolves `PyLoxone-Audio==0.1.6` through its normal dependency handling. Installing the library alone does not update the integration.
|
|
24
24
|
|
|
25
25
|
## Start here
|
|
26
26
|
|
|
@@ -44,6 +44,10 @@ Despite its name, that option also enables Browse/Search, source selection and r
|
|
|
44
44
|
|
|
45
45
|
**Audio diagnostics** is a separate, optional switch. It does not enable playback.
|
|
46
46
|
|
|
47
|
+
## What changes in 0.1.6
|
|
48
|
+
|
|
49
|
+
Warm audio commands and sequential Browse requests reuse an authenticated Audio Server connection instead of repeating setup and close. Cold setup and slow source replies can still take time. See the [release notes](RELEASE-NOTES-0.1.6.md) for the connection policy and offline evidence.
|
|
50
|
+
|
|
47
51
|
## What it adds
|
|
48
52
|
|
|
49
53
|
- Now-playing information and Browse/Search for supported native sources.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyLoxone-Audio
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: Native audio transport and source policies for PyLoxone
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Homepage, https://github.com/davehocking/PyLoxone-Audio
|
|
@@ -20,7 +20,7 @@ Dynamic: license-file
|
|
|
20
20
|
|
|
21
21
|
Audio features for [PyLoxone](https://github.com/JoDehli/PyLoxone), using your existing Home Assistant integration and room players.
|
|
22
22
|
|
|
23
|
-
**Version 0.1.
|
|
23
|
+
**Version 0.1.6:** library **0.1.6**, reference adapter **0.1.6**, frontend **r13**, based on PyLoxone **0.10.3**. Install the matching preview below; Home Assistant resolves `PyLoxone-Audio==0.1.6` through its normal dependency handling. Installing the library alone does not update the integration.
|
|
24
24
|
|
|
25
25
|
## Start here
|
|
26
26
|
|
|
@@ -44,6 +44,10 @@ Despite its name, that option also enables Browse/Search, source selection and r
|
|
|
44
44
|
|
|
45
45
|
**Audio diagnostics** is a separate, optional switch. It does not enable playback.
|
|
46
46
|
|
|
47
|
+
## What changes in 0.1.6
|
|
48
|
+
|
|
49
|
+
Warm audio commands and sequential Browse requests reuse an authenticated Audio Server connection instead of repeating setup and close. Cold setup and slow source replies can still take time. See the [release notes](RELEASE-NOTES-0.1.6.md) for the connection policy and offline evidence.
|
|
50
|
+
|
|
47
51
|
## What it adds
|
|
48
52
|
|
|
49
53
|
- Now-playing information and Browse/Search for supported native sources.
|
|
@@ -8,7 +8,7 @@ LICENSE
|
|
|
8
8
|
MANIFEST.in
|
|
9
9
|
NOTICE.md
|
|
10
10
|
README.md
|
|
11
|
-
RELEASE-NOTES-0.1.
|
|
11
|
+
RELEASE-NOTES-0.1.6.md
|
|
12
12
|
USER-GUIDE.md
|
|
13
13
|
pyproject.toml
|
|
14
14
|
PyLoxone_Audio.egg-info/PKG-INFO
|
|
@@ -28,9 +28,11 @@ pyloxone_audio/native.py
|
|
|
28
28
|
pyloxone_audio/py.typed
|
|
29
29
|
pyloxone_audio/radio.py
|
|
30
30
|
pyloxone_audio/selection.py
|
|
31
|
+
pyloxone_audio/session.py
|
|
31
32
|
pyloxone_audio/sources.py
|
|
32
33
|
tests/library/conftest.py
|
|
33
34
|
tests/library/pytest.ini
|
|
35
|
+
tests/library/session_support.py
|
|
34
36
|
tests/library/test_audio_grouping.py
|
|
35
37
|
tests/library/test_audio_modes.py
|
|
36
38
|
tests/library/test_audioserver_announcement.py
|
|
@@ -63,8 +65,14 @@ tests/library/test_playback_failure_recovery.py
|
|
|
63
65
|
tests/library/test_portable_policies.py
|
|
64
66
|
tests/library/test_published_authentication.py
|
|
65
67
|
tests/library/test_restore_readiness.py
|
|
68
|
+
tests/library/test_reusable_command_session.py
|
|
66
69
|
tests/library/test_room_reply_review03.py
|
|
67
70
|
tests/library/test_room_transport.py
|
|
71
|
+
tests/library/test_session_benchmark.py
|
|
72
|
+
tests/library/test_session_cancelled_close.py
|
|
73
|
+
tests/library/test_session_isolation.py
|
|
74
|
+
tests/library/test_session_owner_controls.py
|
|
75
|
+
tests/library/test_session_playback_policy.py
|
|
68
76
|
tests/library/test_volume_failure_recovery.py
|
|
69
77
|
tests/library/fixtures/audioserver/README.md
|
|
70
78
|
tests/library/fixtures/audioserver/sebastian_alarm_end.txt
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Audio features for [PyLoxone](https://github.com/JoDehli/PyLoxone), using your existing Home Assistant integration and room players.
|
|
4
4
|
|
|
5
|
-
**Version 0.1.
|
|
5
|
+
**Version 0.1.6:** library **0.1.6**, reference adapter **0.1.6**, frontend **r13**, based on PyLoxone **0.10.3**. Install the matching preview below; Home Assistant resolves `PyLoxone-Audio==0.1.6` through its normal dependency handling. Installing the library alone does not update the integration.
|
|
6
6
|
|
|
7
7
|
## Start here
|
|
8
8
|
|
|
@@ -26,6 +26,10 @@ Despite its name, that option also enables Browse/Search, source selection and r
|
|
|
26
26
|
|
|
27
27
|
**Audio diagnostics** is a separate, optional switch. It does not enable playback.
|
|
28
28
|
|
|
29
|
+
## What changes in 0.1.6
|
|
30
|
+
|
|
31
|
+
Warm audio commands and sequential Browse requests reuse an authenticated Audio Server connection instead of repeating setup and close. Cold setup and slow source replies can still take time. See the [release notes](RELEASE-NOTES-0.1.6.md) for the connection policy and offline evidence.
|
|
32
|
+
|
|
29
33
|
## What it adds
|
|
30
34
|
|
|
31
35
|
- Now-playing information and Browse/Search for supported native sources.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# 0.1.6 — reduced command wait-time
|
|
2
|
+
|
|
3
|
+
Library and reference adapter **0.1.6**, exact dependency `PyLoxone-Audio==0.1.6`, on PyLoxone **0.10.3**. Frontend **r13** is unchanged.
|
|
4
|
+
|
|
5
|
+
## What changes
|
|
6
|
+
|
|
7
|
+
The adapter reuses one authenticated Audio Server command connection across its rooms. Clean warm commands and sequential Browse requests no longer open, authenticate and close a new connection each time. Native replies, source confirmation and existing ownership checks are still required; commands are not automatically replayed after uncertain failures.
|
|
8
|
+
|
|
9
|
+
The connection remains available while mapped rooms report fresh playback. Otherwise it closes after five minutes without meaningful command activity. Background status/event traffic does not renew that allowance, and expiry does not close an in-flight request. A later required read or command can open a new connection. Reload/unload closes the owned reader and connection.
|
|
10
|
+
|
|
11
|
+
## Evidence and limits
|
|
12
|
+
|
|
13
|
+
Paired offline tests used identical native sends, response delays and outcomes against exact 0.1.5 and 0.1.6. Four clean requests used one handshake instead of four. Injected connection/authentication/close delays produced lower full-operation warm latency through both the native transport and registered HA services. These are synthetic benchmarks, not measured household Browse or speaker latency. Cold setup, slow source responses and a request already in progress can still delay another command; Browse releases the shared lock between individual requests.
|
|
14
|
+
|
|
15
|
+
This release does not diagnose or claim to fix the separately reported static-group, capability-flapping or next/previous eligibility issues. Existing group/source/announcement behaviour and operation deadlines are unchanged. The native protocol has no demonstrated unique per-request ID for distinguishing a delayed byte-identical reply to a later identical command; uncertain sessions are retired conservatively.
|
|
16
|
+
|
|
17
|
+
## Install and check
|
|
18
|
+
|
|
19
|
+
Follow [the installation/rollback guide](https://github.com/davehocking/PyLoxone-Audio/blob/v0.1.6/preview-build/README.md). In the existing Loxone entry, set **Audioserver host** and enable **Use Audio Server player play/pause (experimental; off by default)**. Diagnostics remains separate and optional. Keep the matching library/adapter pair and the unchanged r13 frontend; the library alone does not update HA integration files.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Concrete PyLoxone-Audio API, independent of Home Assistant.
|
|
3
3
|
|
|
4
|
-
Apache-2.0. Version 0.1.
|
|
4
|
+
Apache-2.0. Version 0.1.6.
|
|
5
5
|
The historical fake-backed facade contract is outside this distribution.
|
|
6
6
|
"""
|
|
7
|
-
__version__ = "0.1.
|
|
7
|
+
__version__ = "0.1.6"
|
|
8
8
|
|
|
9
9
|
from .announcement import async_send_prepared_announcement
|
|
10
10
|
from .catalogue import AudioCatalogue, CatalogueTarget, ConfiguredSource
|
|
@@ -99,6 +99,8 @@ class AudioMetadataCoordinator:
|
|
|
99
99
|
for task in tuple(self._recoveries.values()):
|
|
100
100
|
task.cancel()
|
|
101
101
|
await asyncio.gather(*tuple(self._recoveries.values()), return_exceptions=True)
|
|
102
|
+
for player, binding in self._bindings.items():
|
|
103
|
+
binding[0].observe_playback(player, False)
|
|
102
104
|
self._bindings.clear()
|
|
103
105
|
self._playing.clear()
|
|
104
106
|
self._active_since.clear()
|
|
@@ -179,6 +181,7 @@ class AudioMetadataCoordinator:
|
|
|
179
181
|
def remove() -> None:
|
|
180
182
|
if self._bindings.get(player_id) is binding:
|
|
181
183
|
del self._bindings[player_id]
|
|
184
|
+
commands.observe_playback(player_id, False)
|
|
182
185
|
self.set_playing(player_id, False)
|
|
183
186
|
|
|
184
187
|
return remove
|
|
@@ -455,6 +458,17 @@ class AudioMetadataCoordinator:
|
|
|
455
458
|
|
|
456
459
|
def _on_update(self, updates: tuple[AudioZoneMetadata, ...]) -> None:
|
|
457
460
|
"""Notify affected players; an empty update invalidates every snapshot."""
|
|
461
|
+
# Only exact opted-in mapped bindings qualify retention. This does not
|
|
462
|
+
# alter content/permission freshness, source proof or recovery policy.
|
|
463
|
+
if not updates:
|
|
464
|
+
for player, binding in self._bindings.items():
|
|
465
|
+
binding[0].observe_playback(player, False)
|
|
466
|
+
for row in updates:
|
|
467
|
+
if binding := self._bindings.get(row.player_id):
|
|
468
|
+
# Reconciler eligibility includes source/group/operation fences;
|
|
469
|
+
# those do not make a mapped room's positive playback unknown.
|
|
470
|
+
# Binding removal/stop owns retention invalidation separately.
|
|
471
|
+
binding[0].observe_playback(row.player_id, row.native_mode == "play")
|
|
458
472
|
if diagnostics_enabled(self.diagnostics):
|
|
459
473
|
if not updates:
|
|
460
474
|
diagnostic_event(
|
|
@@ -15,7 +15,7 @@ import base64
|
|
|
15
15
|
import json
|
|
16
16
|
import logging
|
|
17
17
|
import re
|
|
18
|
-
from contextlib import suppress
|
|
18
|
+
from contextlib import asynccontextmanager, suppress
|
|
19
19
|
from dataclasses import dataclass, field, replace
|
|
20
20
|
from datetime import UTC, datetime
|
|
21
21
|
from enum import IntEnum
|
|
@@ -30,6 +30,8 @@ from uuid import uuid4
|
|
|
30
30
|
from weakref import WeakSet
|
|
31
31
|
|
|
32
32
|
from .diagnostic_events import diagnostic_event, diagnostics_enabled
|
|
33
|
+
from .session import CommandSession
|
|
34
|
+
from . import session as session_policy
|
|
33
35
|
|
|
34
36
|
from Crypto.Cipher import AES, PKCS1_v1_5
|
|
35
37
|
from Crypto.PublicKey import RSA
|
|
@@ -389,6 +391,11 @@ class AudioServerCommands:
|
|
|
389
391
|
self._lock = asyncio.Lock()
|
|
390
392
|
self._closed = False
|
|
391
393
|
self._socket: Any = None
|
|
394
|
+
# The HA entry opts in explicitly; direct 0.1.x callers retain the
|
|
395
|
+
# original one-shot lifecycle unless they select reusable sessions.
|
|
396
|
+
self.reuse_session = False
|
|
397
|
+
self._session: CommandSession | None = None
|
|
398
|
+
self._playback_until: dict[int, float] = {}
|
|
392
399
|
self.diagnostics = diagnostics
|
|
393
400
|
self.announcement_fences: dict[int, Callable[[], None]] = {}
|
|
394
401
|
self.source_fences: dict[int, Callable[[], None]] = {}
|
|
@@ -424,15 +431,70 @@ class AudioServerCommands:
|
|
|
424
431
|
"""Latch published revocation without retaining token publication data."""
|
|
425
432
|
for current in tuple(self._authentication_guards):
|
|
426
433
|
current()
|
|
434
|
+
if self._session is not None and not self._session.valid():
|
|
435
|
+
self._session.invalidate()
|
|
436
|
+
|
|
437
|
+
def observe_playback(self, player_id: int, playing: bool) -> None:
|
|
438
|
+
"""Receive already-mapped native observations; silence expires in 30s."""
|
|
439
|
+
now = session_policy.monotonic()
|
|
440
|
+
self._playback_until = {p: end for p, end in self._playback_until.items() if end > now}
|
|
441
|
+
if playing is True and not self._closed:
|
|
442
|
+
self._playback_until[player_id] = now + 30
|
|
443
|
+
else:
|
|
444
|
+
self._playback_until.pop(player_id, None)
|
|
445
|
+
if self._session is not None:
|
|
446
|
+
self._session.observe_playing(max(self._playback_until.values(), default=0))
|
|
427
447
|
|
|
428
448
|
async def async_close(self) -> None:
|
|
429
449
|
"""Reject queued/future requests and close an in-flight owned socket."""
|
|
430
450
|
self._closed = True
|
|
451
|
+
self._playback_until.clear()
|
|
431
452
|
for release in (*tuple(self.announcement_fences.values()), *tuple(self.source_fences.values())):
|
|
432
453
|
release()
|
|
433
|
-
if self.
|
|
454
|
+
if self._session is not None:
|
|
455
|
+
await self._session.close()
|
|
456
|
+
self._session = None
|
|
457
|
+
elif self._socket is not None:
|
|
434
458
|
await self._socket.close()
|
|
435
459
|
|
|
460
|
+
@asynccontextmanager
|
|
461
|
+
async def _connection(self):
|
|
462
|
+
"""Lease one session under _lock; uncertain requests never remain warm."""
|
|
463
|
+
def context():
|
|
464
|
+
return connect(
|
|
465
|
+
self._uri, subprotocols=[Subprotocol("remotecontrol")],
|
|
466
|
+
open_timeout=self._timeout, close_timeout=2, ping_interval=None,
|
|
467
|
+
max_size=1024 * 1024, **_DIRECT_CONNECT,
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
if not self.reuse_session:
|
|
471
|
+
async with context() as socket:
|
|
472
|
+
yield socket
|
|
473
|
+
return
|
|
474
|
+
session = self._session
|
|
475
|
+
if session is not None and not session.valid():
|
|
476
|
+
await session.close()
|
|
477
|
+
if self._session is session:
|
|
478
|
+
self._session = None
|
|
479
|
+
session = None
|
|
480
|
+
if session is None:
|
|
481
|
+
current = self.authentication_guard()
|
|
482
|
+
manager = context()
|
|
483
|
+
socket = await manager.__aenter__()
|
|
484
|
+
session = self._session = CommandSession(socket, manager, current, AudioCommandError)
|
|
485
|
+
session.observe_playing(max(self._playback_until.values(), default=0))
|
|
486
|
+
try:
|
|
487
|
+
session.begin()
|
|
488
|
+
yield session
|
|
489
|
+
except BaseException:
|
|
490
|
+
session.invalidate()
|
|
491
|
+
raise
|
|
492
|
+
finally:
|
|
493
|
+
if not session.finish():
|
|
494
|
+
await session.close()
|
|
495
|
+
if self._session is session:
|
|
496
|
+
self._session = None
|
|
497
|
+
|
|
436
498
|
async def async_execute(
|
|
437
499
|
self, player_id: object, action: str, *, is_current: Callable[[], bool] | None = None,
|
|
438
500
|
on_send: Callable[[], None] | None = None, guard_cleanup: bool = False,
|
|
@@ -1083,8 +1145,14 @@ class AudioServerCommands:
|
|
|
1083
1145
|
# waiting for the existing shared lock or handshake. Other native
|
|
1084
1146
|
# routes retain their established transport/ownership behaviour.
|
|
1085
1147
|
status_credentials = self._credentials() if reply_key in ("status_result", "dgroup_update_result", "grouped_play_result", "grouped_pause_result") else None
|
|
1148
|
+
# A reusable-session request owns the authentication lifetime from
|
|
1149
|
+
# admission, including time spent queued behind another room. A
|
|
1150
|
+
# published A→B→A must not create a fresh authority for that intent.
|
|
1151
|
+
request_authentication = self.authentication_guard() if self.reuse_session else None
|
|
1086
1152
|
async with asyncio.timeout(self._timeout), self._lock:
|
|
1087
1153
|
record("lock_acquired")
|
|
1154
|
+
if request_authentication is not None and not request_authentication():
|
|
1155
|
+
raise AudioCommandError("Native command authentication changed while queued")
|
|
1088
1156
|
if self._closed:
|
|
1089
1157
|
message = "Audio playback connection is closed"
|
|
1090
1158
|
raise AudioCommandError(message)
|
|
@@ -1092,23 +1160,23 @@ class AudioServerCommands:
|
|
|
1092
1160
|
if not isinstance(username, str) or not username.strip() or not isinstance(token, str) or not token:
|
|
1093
1161
|
message = "Audio playback credentials are unavailable"
|
|
1094
1162
|
raise AudioCommandError(message)
|
|
1095
|
-
async with
|
|
1096
|
-
self._uri,
|
|
1097
|
-
subprotocols=[Subprotocol("remotecontrol")],
|
|
1098
|
-
open_timeout=self._timeout,
|
|
1099
|
-
close_timeout=2,
|
|
1100
|
-
ping_interval=None,
|
|
1101
|
-
max_size=1024 * 1024,
|
|
1102
|
-
**_DIRECT_CONNECT,
|
|
1103
|
-
) as socket:
|
|
1163
|
+
async with self._connection() as socket:
|
|
1104
1164
|
owned_socket = self._socket = socket
|
|
1105
|
-
|
|
1165
|
+
reused = isinstance(socket, CommandSession) and socket.authenticated
|
|
1166
|
+
if not reused:
|
|
1167
|
+
record("connection_opened")
|
|
1106
1168
|
if self._closed:
|
|
1107
1169
|
message = "Audio playback connection is closed"
|
|
1108
1170
|
raise AudioCommandError(message)
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
record("
|
|
1171
|
+
if reused:
|
|
1172
|
+
shuffle_switch = socket.shuffle_switch
|
|
1173
|
+
record("session_reused")
|
|
1174
|
+
else:
|
|
1175
|
+
shuffle_switch = await self._authenticate(socket, username, token)
|
|
1176
|
+
if isinstance(socket, CommandSession):
|
|
1177
|
+
socket.start_reader(shuffle_switch)
|
|
1178
|
+
if diagnostics_enabled(observer):
|
|
1179
|
+
record("authenticated")
|
|
1112
1180
|
|
|
1113
1181
|
if self._closed:
|
|
1114
1182
|
message = "Audio playback connection is closed"
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""Private single-reader native command session; no retries or metadata authority."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
import json
|
|
6
|
+
from contextlib import suppress
|
|
7
|
+
from typing import Any
|
|
8
|
+
from time import monotonic
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def call_later(delay, callback, *args):
|
|
12
|
+
"""Use the owning event loop; separate seam for controlled-clock policy tests."""
|
|
13
|
+
return asyncio.get_running_loop().call_later(delay, callback, *args)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CommandSession:
|
|
17
|
+
"""One authenticated socket, leased by the native owner's existing lock.
|
|
18
|
+
|
|
19
|
+
Authentication uses the raw recv path before start_reader. Afterwards only
|
|
20
|
+
the reader touches raw recv; callers receive from a bounded request inbox.
|
|
21
|
+
A lease without an exact command-bearing response is never kept warm.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, socket: Any, context: Any, current, error_type) -> None:
|
|
25
|
+
self.socket = socket
|
|
26
|
+
self.context = context
|
|
27
|
+
self.current = current
|
|
28
|
+
self.error_type = error_type
|
|
29
|
+
self.authenticated = False
|
|
30
|
+
self.shuffle_switch = None
|
|
31
|
+
self.reader: asyncio.Task | None = None
|
|
32
|
+
self.command: str | None = None
|
|
33
|
+
self._busy = False
|
|
34
|
+
self.confirmed = False
|
|
35
|
+
self.tainted = False
|
|
36
|
+
self.failed = False
|
|
37
|
+
self.inbox: asyncio.Queue = asyncio.Queue(maxsize=64)
|
|
38
|
+
self._close_task: asyncio.Task | None = None
|
|
39
|
+
self._close_cancel_reported = False
|
|
40
|
+
self._activity = monotonic()
|
|
41
|
+
self._last_play = 0.0
|
|
42
|
+
self._playing_until = 0.0
|
|
43
|
+
self._idle_timer = None
|
|
44
|
+
|
|
45
|
+
def observe_playing(self, until: float) -> None:
|
|
46
|
+
"""Retain only a bounded positive observation, not a source or send."""
|
|
47
|
+
now = monotonic()
|
|
48
|
+
if self._playing_until > now and until <= now:
|
|
49
|
+
self._last_play = now
|
|
50
|
+
elif until > now:
|
|
51
|
+
self._last_play = until
|
|
52
|
+
self._playing_until = until
|
|
53
|
+
self._arm_idle()
|
|
54
|
+
|
|
55
|
+
def _idle_deadline(self) -> float:
|
|
56
|
+
return max(self._activity, self._last_play) + 300
|
|
57
|
+
|
|
58
|
+
def _arm_idle(self) -> None:
|
|
59
|
+
if self._idle_timer is not None:
|
|
60
|
+
self._idle_timer.cancel()
|
|
61
|
+
self._idle_timer = None
|
|
62
|
+
if self.valid() and not self._busy:
|
|
63
|
+
self._idle_timer = call_later(max(0, self._idle_deadline() - monotonic()), self._expire)
|
|
64
|
+
|
|
65
|
+
def _expire(self) -> None:
|
|
66
|
+
self._idle_timer = None
|
|
67
|
+
if self._busy or not self.valid():
|
|
68
|
+
return
|
|
69
|
+
if monotonic() < self._idle_deadline():
|
|
70
|
+
self._arm_idle()
|
|
71
|
+
return
|
|
72
|
+
self.invalidate()
|
|
73
|
+
self._start_close()
|
|
74
|
+
|
|
75
|
+
def _start_close(self) -> None:
|
|
76
|
+
if self._close_task is None:
|
|
77
|
+
self._close_task = asyncio.create_task(self._close(), name='audio command close')
|
|
78
|
+
# Idle/read failure cleanup may have no waiting request. Retrieve a
|
|
79
|
+
# close exception so task errors never leak credentials to the loop.
|
|
80
|
+
self._close_task.add_done_callback(lambda task: None if task.cancelled() else task.exception())
|
|
81
|
+
|
|
82
|
+
def valid(self) -> bool:
|
|
83
|
+
return not self.failed and self.current()
|
|
84
|
+
|
|
85
|
+
def begin(self) -> None:
|
|
86
|
+
if not self.valid() or self._busy or not self.inbox.empty():
|
|
87
|
+
raise self.error_type('Native command session is no longer reusable')
|
|
88
|
+
self._busy = True
|
|
89
|
+
if self._idle_timer is not None:
|
|
90
|
+
self._idle_timer.cancel()
|
|
91
|
+
self._idle_timer = None
|
|
92
|
+
self.confirmed = False
|
|
93
|
+
|
|
94
|
+
def start_reader(self, shuffle_switch) -> None:
|
|
95
|
+
self.authenticated = True
|
|
96
|
+
self.shuffle_switch = shuffle_switch
|
|
97
|
+
self.reader = asyncio.create_task(self._read(), name='audio command replies')
|
|
98
|
+
|
|
99
|
+
def invalidate(self) -> None:
|
|
100
|
+
self.failed = True
|
|
101
|
+
if self._idle_timer is not None:
|
|
102
|
+
self._idle_timer.cancel()
|
|
103
|
+
self._idle_timer = None
|
|
104
|
+
if self.inbox.empty():
|
|
105
|
+
self.inbox.put_nowait(None)
|
|
106
|
+
self._start_close()
|
|
107
|
+
|
|
108
|
+
async def send(self, command: str) -> None:
|
|
109
|
+
if not self.valid():
|
|
110
|
+
raise self.error_type('Native command session authority changed')
|
|
111
|
+
if self.authenticated:
|
|
112
|
+
self.command = command
|
|
113
|
+
if command.split('/')[2] not in ('status', 'getstatus'):
|
|
114
|
+
self._activity = monotonic()
|
|
115
|
+
await self.socket.send(command)
|
|
116
|
+
|
|
117
|
+
async def recv(self):
|
|
118
|
+
if not self.authenticated:
|
|
119
|
+
return await self.socket.recv()
|
|
120
|
+
if not self.valid():
|
|
121
|
+
raise self.error_type('Native command session was lost or superseded')
|
|
122
|
+
message = await self.inbox.get()
|
|
123
|
+
if message is None or not self.valid():
|
|
124
|
+
raise self.error_type('Native command session was lost or superseded')
|
|
125
|
+
return message
|
|
126
|
+
|
|
127
|
+
@staticmethod
|
|
128
|
+
def _object(pairs):
|
|
129
|
+
result = {}
|
|
130
|
+
for key, value in pairs:
|
|
131
|
+
if key in result:
|
|
132
|
+
raise ValueError('duplicate native field')
|
|
133
|
+
result[key] = value
|
|
134
|
+
return result
|
|
135
|
+
|
|
136
|
+
async def _read(self) -> None:
|
|
137
|
+
try:
|
|
138
|
+
while self.valid():
|
|
139
|
+
# Buffered traffic must not starve the deadline/cancellation.
|
|
140
|
+
await asyncio.sleep(0)
|
|
141
|
+
message = await self.socket.recv()
|
|
142
|
+
try:
|
|
143
|
+
payload = json.loads(message, object_pairs_hook=self._object) if isinstance(message, str) else None
|
|
144
|
+
except ValueError as error:
|
|
145
|
+
if str(error) != 'duplicate native field' and self.command is not None:
|
|
146
|
+
# Preserve the owning proof parser's tolerance of
|
|
147
|
+
# unrelated malformed frames, never warm reuse.
|
|
148
|
+
self.tainted = True
|
|
149
|
+
self.inbox.put_nowait(message)
|
|
150
|
+
continue
|
|
151
|
+
self.invalidate()
|
|
152
|
+
break
|
|
153
|
+
except (TypeError, RecursionError):
|
|
154
|
+
self.invalidate()
|
|
155
|
+
break
|
|
156
|
+
if not isinstance(payload, dict):
|
|
157
|
+
continue
|
|
158
|
+
# Only known unsolicited envelopes can be drained while idle.
|
|
159
|
+
# Never let an event envelope carrying a result/error bypass
|
|
160
|
+
# command qualification.
|
|
161
|
+
if (not payload.get('error') and 'command' not in payload
|
|
162
|
+
and not any(k.endswith(('_result', '_error')) for k in payload)
|
|
163
|
+
and any(isinstance(payload.get(k), list) for k in ('audio_event', 'audio_sync_event'))):
|
|
164
|
+
if self.command is None:
|
|
165
|
+
continue
|
|
166
|
+
if self.command is None:
|
|
167
|
+
self.invalidate()
|
|
168
|
+
break
|
|
169
|
+
echo = payload.get('command')
|
|
170
|
+
expected = self.command.split('/?q&', 1)[0]
|
|
171
|
+
if echo is not None and echo != expected:
|
|
172
|
+
# Foreign results cannot settle _reply. Let the existing
|
|
173
|
+
# source-proof race inspect a neutral frame instead of
|
|
174
|
+
# failing independently qualified playback.
|
|
175
|
+
self.tainted = True
|
|
176
|
+
self.inbox.put_nowait('{}')
|
|
177
|
+
continue
|
|
178
|
+
if echo == expected:
|
|
179
|
+
self.confirmed = True
|
|
180
|
+
# Keep old command-less response compatibility for this request,
|
|
181
|
+
# but no subsequent lease may trust that uncorrelated stream.
|
|
182
|
+
self.inbox.put_nowait(message)
|
|
183
|
+
except asyncio.CancelledError:
|
|
184
|
+
raise
|
|
185
|
+
except Exception:
|
|
186
|
+
# A receive/decode/buffer failure is not a playable success. Error
|
|
187
|
+
# text can contain endpoints/authentication, so never retain it.
|
|
188
|
+
self.invalidate()
|
|
189
|
+
finally:
|
|
190
|
+
self.invalidate()
|
|
191
|
+
|
|
192
|
+
def finish(self) -> bool:
|
|
193
|
+
keep = self.valid() and self.confirmed and not self.tainted and self.inbox.empty()
|
|
194
|
+
self.command = None
|
|
195
|
+
self._busy = False
|
|
196
|
+
if keep:
|
|
197
|
+
self._arm_idle()
|
|
198
|
+
return keep
|
|
199
|
+
|
|
200
|
+
async def close(self) -> None:
|
|
201
|
+
"""Idempotent bounded cleanup, shared by request/unload/revocation."""
|
|
202
|
+
self.invalidate()
|
|
203
|
+
self._start_close()
|
|
204
|
+
try:
|
|
205
|
+
await asyncio.shield(self._close_task)
|
|
206
|
+
except asyncio.CancelledError:
|
|
207
|
+
# A cancelled context exit is an outcome of that owned request,
|
|
208
|
+
# not a fresh cancellation of every later unload/reconciliation.
|
|
209
|
+
# Never swallow cancellation directed at the current caller.
|
|
210
|
+
caller = asyncio.current_task()
|
|
211
|
+
if self._close_task.cancelled() and caller is not None and not caller.cancelling():
|
|
212
|
+
if self._close_cancel_reported:
|
|
213
|
+
return
|
|
214
|
+
self._close_cancel_reported = True
|
|
215
|
+
raise
|
|
216
|
+
|
|
217
|
+
async def _close(self) -> None:
|
|
218
|
+
if self.reader is not None:
|
|
219
|
+
self.reader.cancel()
|
|
220
|
+
with suppress(asyncio.CancelledError):
|
|
221
|
+
await self.reader
|
|
222
|
+
# websockets itself has close_timeout=2. Bound even external contexts;
|
|
223
|
+
# the transport abort prevents a cancelled close leaving native IO live.
|
|
224
|
+
try:
|
|
225
|
+
async with asyncio.timeout(3):
|
|
226
|
+
await self.context.__aexit__(None, None, None)
|
|
227
|
+
except TimeoutError:
|
|
228
|
+
transport = getattr(self.socket, 'transport', None)
|
|
229
|
+
if transport is not None:
|
|
230
|
+
transport.abort()
|