pybluetti 0.2.6__tar.gz → 0.2.7__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.
- {pybluetti-0.2.6 → pybluetti-0.2.7}/CHANGELOG.md +4 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/PKG-INFO +1 -1
- {pybluetti-0.2.6 → pybluetti-0.2.7}/pyproject.toml +1 -1
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/client.py +10 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/tests/test_product_client.py +51 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/.github/workflows/publish.yml +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/.github/workflows/tests.yml +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/.gitignore +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/LICENSE +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/README.md +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/scripts/lint +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/scripts/setup +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/scripts/test +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/scripts/typecheck +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/__init__.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/const.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/exceptions.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/models.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/product_client.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/py.typed +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/unify_response.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/src/pybluetti/websocket.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/tests/__init__.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/tests/test_const.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/tests/test_exceptions.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/tests/test_package.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/tests/test_unify_response.py +0 -0
- {pybluetti-0.2.6 → pybluetti-0.2.7}/tests/test_websocket.py +0 -0
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# 0.2.7
|
|
2
|
+
|
|
3
|
+
- Every request now has a timeout of 10 seconds (`REQUEST_TIMEOUT` in `client.py`), set in `Bluetti._request()` and so on all four calls of `ProductClient`. There was none, so the session's own applied, and aiohttp's default for that is five minutes: when the gateway accepted a status request and never answered it, each `get_device_status()` held its caller for 300 s. In `bluetti-home-assistant`, which retries a timeout once and keeps the last values through two failed polls, that made one poll take ten minutes and left the entities on values up to half an hour old before they went unavailable (bluetti-community/bluetti-home-assistant#78). A request that runs out of time raises `TimeoutError`, as it did before after the five minutes, so a caller that already handles it needs no change. A caller that set a longer limit on its own session no longer gets it for these requests.
|
|
4
|
+
|
|
1
5
|
# 0.2.6
|
|
2
6
|
|
|
3
7
|
- Fixed `StompClient.connect()` never returning while the cloud is unreachable: a failed attempt awaited `reconnect()`, which slept and called `connect()` again, so every retry nested inside the caller's own await instead of running behind it. A caller that connects during its start-up - `bluetti-home-assistant` awaits this inside `async_setup_entry` - then stayed in start-up for the whole outage: the config entry sat on "initialising" for three hours, with no reload offered in its menu and nothing but a Home Assistant restart to clear it (bluetti-community/bluetti-home-assistant#65). `connect()` now makes a single attempt and schedules the retry loop in the background, and `reconnect()` loops instead of recursing, so the stack no longer grows by a frame per attempt either.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pybluetti
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Async Python client for the BLUETTI cloud API - device discovery, state, and control.
|
|
5
5
|
Project-URL: Homepage, https://github.com/bluetti-community/pybluetti
|
|
6
6
|
Project-URL: Used by, https://github.com/bluetti-community/bluetti-home-assistant
|
|
@@ -13,6 +13,12 @@ from .const import Method
|
|
|
13
13
|
from .exceptions import HttpStatusException
|
|
14
14
|
from .unify_response import UnifyResponse
|
|
15
15
|
|
|
16
|
+
# Set on every request, since without it the session's own limit applies, and
|
|
17
|
+
# aiohttp's default for that is five minutes: a request the gateway accepts
|
|
18
|
+
# and never answers held its caller that long
|
|
19
|
+
# (bluetti-community/bluetti-home-assistant#78). An answer takes about a second.
|
|
20
|
+
REQUEST_TIMEOUT = aiohttp.ClientTimeout(total=10)
|
|
21
|
+
|
|
16
22
|
|
|
17
23
|
class Bluetti:
|
|
18
24
|
"""Base class describing interactions with the BLUETTI cloud service."""
|
|
@@ -76,6 +82,9 @@ class Bluetti:
|
|
|
76
82
|
callers restore a precise type at the boundary with typing.cast,
|
|
77
83
|
matching what responseType actually validated.
|
|
78
84
|
|
|
85
|
+
Raises TimeoutError when the answer has not arrived in full within
|
|
86
|
+
REQUEST_TIMEOUT.
|
|
87
|
+
|
|
79
88
|
- responseType: the type of response data, without the UnifyResponse wrapper.
|
|
80
89
|
- method: the HTTP method.
|
|
81
90
|
"""
|
|
@@ -102,6 +111,7 @@ class Bluetti:
|
|
|
102
111
|
headers=headers,
|
|
103
112
|
json=body,
|
|
104
113
|
params=params,
|
|
114
|
+
timeout=REQUEST_TIMEOUT,
|
|
105
115
|
) as response:
|
|
106
116
|
self.logger.debug("<====== Server response status %s from %s", response.status, response.url)
|
|
107
117
|
self.logger.debug("<====== Server response type is: %s", response.content_type)
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"""Tests for the Bluetti base API client (client.py) via ProductClient."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
from unittest.mock import MagicMock
|
|
4
5
|
|
|
6
|
+
import aiohttp
|
|
5
7
|
import pytest
|
|
8
|
+
from aiohttp import web
|
|
9
|
+
from aiohttp.test_utils import TestServer
|
|
6
10
|
|
|
11
|
+
from pybluetti import client as client_module
|
|
12
|
+
from pybluetti.client import REQUEST_TIMEOUT
|
|
7
13
|
from pybluetti.exceptions import ApplicationRuntimeException, HttpStatusException
|
|
8
14
|
from pybluetti.product_client import ProductClient
|
|
9
15
|
|
|
@@ -169,3 +175,48 @@ async def test_bind_devices_posts_payload():
|
|
|
169
175
|
_method, url, kwargs = session.calls[0]
|
|
170
176
|
assert url.endswith("/api/bluiotdata/ha/v1/bindDevices")
|
|
171
177
|
assert kwargs["json"] == {"bindSnList": ["SN1"]}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
async def test_every_request_carries_the_timeout():
|
|
181
|
+
response = _FakeResponse(json_data={"msgId": "1", "msgCode": 0, "data": None})
|
|
182
|
+
session = _FakeSession(response)
|
|
183
|
+
client, _on_auth_expired = _client(session)
|
|
184
|
+
|
|
185
|
+
await client.get_user_products()
|
|
186
|
+
await client.get_device_status("SN1")
|
|
187
|
+
await client.control_device({"sn": "SN1", "fnCode": "AC", "fnValue": "1"})
|
|
188
|
+
await client.bind_devices({"bindSnList": ["SN1"]})
|
|
189
|
+
|
|
190
|
+
assert [kwargs["timeout"] for _method, _url, kwargs in session.calls] == [REQUEST_TIMEOUT] * 4
|
|
191
|
+
assert REQUEST_TIMEOUT.total == 10
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
async def test_request_the_cloud_never_answers_times_out(monkeypatch):
|
|
195
|
+
# The gateway accepted a status request and sent nothing back, and the
|
|
196
|
+
# request waited out the session's five minutes
|
|
197
|
+
# (bluetti-community/bluetti-home-assistant#78). A real session against a
|
|
198
|
+
# server that does the same, with the limit cut down to keep the test short.
|
|
199
|
+
monkeypatch.setattr(client_module, "REQUEST_TIMEOUT", aiohttp.ClientTimeout(total=0.2))
|
|
200
|
+
release = asyncio.Event()
|
|
201
|
+
|
|
202
|
+
async def never_answers(_request):
|
|
203
|
+
await release.wait()
|
|
204
|
+
return web.Response()
|
|
205
|
+
|
|
206
|
+
app = web.Application()
|
|
207
|
+
app.router.add_get("/api/bluiotdata/ha/v1/deviceStates", never_answers)
|
|
208
|
+
|
|
209
|
+
async with TestServer(app) as server, aiohttp.ClientSession() as session:
|
|
210
|
+
client = ProductClient(session, str(server.make_url("")).rstrip("/"), "test-token")
|
|
211
|
+
loop = asyncio.get_running_loop()
|
|
212
|
+
started = loop.time()
|
|
213
|
+
try:
|
|
214
|
+
# The outer limit only stops a client without a timeout from
|
|
215
|
+
# holding the test for five minutes; the elapsed time tells the two apart.
|
|
216
|
+
with pytest.raises(TimeoutError):
|
|
217
|
+
await asyncio.wait_for(client.get_device_status("SN1"), 5)
|
|
218
|
+
elapsed = loop.time() - started
|
|
219
|
+
finally:
|
|
220
|
+
release.set()
|
|
221
|
+
|
|
222
|
+
assert elapsed < 2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|