python-homely 0.1.9__py3-none-any.whl → 0.1.11__py3-none-any.whl
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.
- homely/client.py +12 -19
- homely/websocket.py +15 -5
- {python_homely-0.1.9.dist-info → python_homely-0.1.11.dist-info}/METADATA +1 -1
- python_homely-0.1.11.dist-info/RECORD +11 -0
- {python_homely-0.1.9.dist-info → python_homely-0.1.11.dist-info}/WHEEL +1 -1
- python_homely-0.1.9.dist-info/RECORD +0 -11
- {python_homely-0.1.9.dist-info → python_homely-0.1.11.dist-info}/licenses/LICENSE +0 -0
- {python_homely-0.1.9.dist-info → python_homely-0.1.11.dist-info}/top_level.txt +0 -0
homely/client.py
CHANGED
|
@@ -39,7 +39,7 @@ def auth_header_value(token: str | None) -> str:
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
def _response_preview(payload: Any) -> str:
|
|
42
|
-
"""Return a short
|
|
42
|
+
"""Return a short preview of a response payload for exceptions."""
|
|
43
43
|
text = repr(payload)
|
|
44
44
|
if len(text) <= 200:
|
|
45
45
|
return text
|
|
@@ -61,10 +61,7 @@ def _text_preview(text: str | None) -> str | None:
|
|
|
61
61
|
|
|
62
62
|
def _error_detail(err: BaseException) -> str:
|
|
63
63
|
"""Return a compact detail string for logs and typed results."""
|
|
64
|
-
|
|
65
|
-
if detail:
|
|
66
|
-
return detail
|
|
67
|
-
return err.__class__.__name__
|
|
64
|
+
return type(err).__name__
|
|
68
65
|
|
|
69
66
|
|
|
70
67
|
def _coarse_token_reason(reason: TokenFailureReason | None) -> str | None:
|
|
@@ -317,7 +314,11 @@ class HomelyClient:
|
|
|
317
314
|
try:
|
|
318
315
|
return _text_preview(await response.text())
|
|
319
316
|
except (TypeError, ValueError, UnicodeDecodeError) as err:
|
|
320
|
-
_LOGGER.debug(
|
|
317
|
+
_LOGGER.debug(
|
|
318
|
+
"Could not read response text status=%s: %s",
|
|
319
|
+
response.status,
|
|
320
|
+
_error_detail(err),
|
|
321
|
+
)
|
|
321
322
|
return None
|
|
322
323
|
|
|
323
324
|
def _raise_token_endpoint_failure(
|
|
@@ -366,7 +367,7 @@ class HomelyClient:
|
|
|
366
367
|
_LOGGER.debug(
|
|
367
368
|
"Locations fetch returned invalid JSON status=%s: %s",
|
|
368
369
|
response.status,
|
|
369
|
-
err,
|
|
370
|
+
_error_detail(err),
|
|
370
371
|
)
|
|
371
372
|
return None, response.status
|
|
372
373
|
if not isinstance(parsed, list):
|
|
@@ -382,7 +383,7 @@ class HomelyClient:
|
|
|
382
383
|
_LOGGER.debug("Locations fetch failed with status=%s", response.status)
|
|
383
384
|
return None, response.status
|
|
384
385
|
except (aiohttp.ClientError, TimeoutError) as err:
|
|
385
|
-
_LOGGER.debug("Locations fetch network error: %s", err)
|
|
386
|
+
_LOGGER.debug("Locations fetch network error: %s", _error_detail(err))
|
|
386
387
|
return None, None
|
|
387
388
|
|
|
388
389
|
async def get_locations(self, token: str) -> list[dict[str, Any]] | None:
|
|
@@ -433,7 +434,7 @@ class HomelyClient:
|
|
|
433
434
|
"status=%s location_id=%s: %s",
|
|
434
435
|
response.status,
|
|
435
436
|
_log_identifier(location_id),
|
|
436
|
-
err,
|
|
437
|
+
_error_detail(err),
|
|
437
438
|
)
|
|
438
439
|
return None, response.status
|
|
439
440
|
if not isinstance(parsed, dict):
|
|
@@ -446,25 +447,17 @@ class HomelyClient:
|
|
|
446
447
|
)
|
|
447
448
|
return None, response.status
|
|
448
449
|
return parsed, response.status
|
|
449
|
-
retry_after = response.headers.get("Retry-After")
|
|
450
|
-
try:
|
|
451
|
-
body = await response.text()
|
|
452
|
-
except Exception:
|
|
453
|
-
body = "<unreadable>"
|
|
454
450
|
_LOGGER.debug(
|
|
455
|
-
"Location data fetch failed with status=%s location_id=%s
|
|
456
|
-
"retry_after=%s body=%s",
|
|
451
|
+
"Location data fetch failed with status=%s location_id=%s",
|
|
457
452
|
response.status,
|
|
458
453
|
_log_identifier(location_id),
|
|
459
|
-
retry_after,
|
|
460
|
-
body[:500] if body else None,
|
|
461
454
|
)
|
|
462
455
|
return None, response.status
|
|
463
456
|
except (aiohttp.ClientError, TimeoutError) as err:
|
|
464
457
|
_LOGGER.debug(
|
|
465
458
|
"Location data fetch network error location_id=%s: %s",
|
|
466
459
|
_log_identifier(location_id),
|
|
467
|
-
err,
|
|
460
|
+
_error_detail(err),
|
|
468
461
|
)
|
|
469
462
|
return None, None
|
|
470
463
|
|
homely/websocket.py
CHANGED
|
@@ -101,6 +101,7 @@ class HomelyWebSocket:
|
|
|
101
101
|
self.socket: Any | None = None
|
|
102
102
|
self._is_closing = False
|
|
103
103
|
self._cleaning_up_socket = False
|
|
104
|
+
self._connect_lock = asyncio.Lock()
|
|
104
105
|
self._reconnect_task: asyncio.Task[None] | None = None
|
|
105
106
|
self._reconnect_interval = self._reconnect_interval_for_attempt(1)
|
|
106
107
|
self._reconnect_warn_every = 12
|
|
@@ -337,6 +338,11 @@ class HomelyWebSocket:
|
|
|
337
338
|
|
|
338
339
|
async def connect(self, from_reconnect_loop: bool = False) -> bool:
|
|
339
340
|
"""Connect to websocket server."""
|
|
341
|
+
async with self._connect_lock:
|
|
342
|
+
return await self._connect_unlocked(from_reconnect_loop)
|
|
343
|
+
|
|
344
|
+
async def _connect_unlocked(self, from_reconnect_loop: bool) -> bool:
|
|
345
|
+
"""Run one connection attempt at a time, including socket cleanup."""
|
|
340
346
|
if self._is_closing:
|
|
341
347
|
_LOGGER.debug("Skipping websocket connect during shutdown %s", self._ctx())
|
|
342
348
|
return False
|
|
@@ -410,15 +416,19 @@ class HomelyWebSocket:
|
|
|
410
416
|
self.socket.on("connect_error", connect_error)
|
|
411
417
|
|
|
412
418
|
bearer_token = self._bearer_value(self.token)
|
|
419
|
+
# The token MUST be in the query string: Homely's server replies
|
|
420
|
+
# {"message":"Invalid JWT"} and disconnects if it is sent only via the
|
|
421
|
+
# Authorization header (verified live). It is therefore unavoidable in
|
|
422
|
+
# the URL, which is why the Engine.IO logger must stay off (it would
|
|
423
|
+
# log this URL with the token).
|
|
424
|
+
# NOTE: do NOT send a "partner" query parameter. Homely rejects it
|
|
425
|
+
# ("Partner <code> is not supported") and closes the connection,
|
|
426
|
+
# causing a connect/disconnect loop. partner_code is accepted for API
|
|
427
|
+
# compatibility but intentionally unused here.
|
|
413
428
|
query_params: dict[str, str] = {
|
|
414
429
|
"locationId": str(self.location_id),
|
|
415
430
|
"token": bearer_token,
|
|
416
431
|
}
|
|
417
|
-
# NOTE: do NOT send a "partner" query parameter. Homely's websocket
|
|
418
|
-
# server rejects it ("Partner <code> is not supported") and closes
|
|
419
|
-
# the connection immediately, causing a connect/disconnect loop.
|
|
420
|
-
# partner_code is accepted for API compatibility but intentionally
|
|
421
|
-
# unused here.
|
|
422
432
|
query = urlencode(query_params)
|
|
423
433
|
url = f"{self.websocket_url}?{query}"
|
|
424
434
|
_LOGGER.debug("WebSocket connecting %s to %s", self._ctx(), self.websocket_url)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
homely/__init__.py,sha256=TK4sclUiHqDewtsOenxS9KNLkprZxqbiYkh__JeNmMA,1023
|
|
2
|
+
homely/client.py,sha256=y3wDLMAunhkRFCBQu8EdHWgTu0qqHLdaILI4Jf0tASg,18502
|
|
3
|
+
homely/exceptions.py,sha256=w6y5MC8yjPe5QtI-YEKUsbAPF1D0ARWx6ZkRsLTjrgQ,1040
|
|
4
|
+
homely/models.py,sha256=8chNpjo1SF4TGww7XPWFUK3kXILH3bSmUnjNteyfsys,1842
|
|
5
|
+
homely/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
6
|
+
homely/websocket.py,sha256=nv9tg4UFaBSi2SgVz74LF_C-8m8XLlSiRgqU1frvCs0,20890
|
|
7
|
+
python_homely-0.1.11.dist-info/licenses/LICENSE,sha256=nNVHKvQjryAonWsz5TbhzLd6M2kZaoNUvhxz92MgeAA,1079
|
|
8
|
+
python_homely-0.1.11.dist-info/METADATA,sha256=lUn7exAZ28CJQbT74GKcQjJP2WPspMsz0r1nrXhYMkw,5240
|
|
9
|
+
python_homely-0.1.11.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
python_homely-0.1.11.dist-info/top_level.txt,sha256=auE-j6ghVMdT_jAw04jiXthgbuLpi-jYBU0fCkKvREQ,7
|
|
11
|
+
python_homely-0.1.11.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
homely/__init__.py,sha256=TK4sclUiHqDewtsOenxS9KNLkprZxqbiYkh__JeNmMA,1023
|
|
2
|
-
homely/client.py,sha256=4kDsZkj3P7z6iNlWZJX9De5GiRATD3GdY_beEXC_ZAg,18781
|
|
3
|
-
homely/exceptions.py,sha256=w6y5MC8yjPe5QtI-YEKUsbAPF1D0ARWx6ZkRsLTjrgQ,1040
|
|
4
|
-
homely/models.py,sha256=8chNpjo1SF4TGww7XPWFUK3kXILH3bSmUnjNteyfsys,1842
|
|
5
|
-
homely/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
6
|
-
homely/websocket.py,sha256=Zf-NcRO_pEqb9A2LEPVyeqYbMaAeUVFL_qBrLuJI9OI,20262
|
|
7
|
-
python_homely-0.1.9.dist-info/licenses/LICENSE,sha256=nNVHKvQjryAonWsz5TbhzLd6M2kZaoNUvhxz92MgeAA,1079
|
|
8
|
-
python_homely-0.1.9.dist-info/METADATA,sha256=nAPt3MWkZThc8lpYyqJXWzNBSMNkr5ZzNJiKfuT0mX8,5239
|
|
9
|
-
python_homely-0.1.9.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
10
|
-
python_homely-0.1.9.dist-info/top_level.txt,sha256=auE-j6ghVMdT_jAw04jiXthgbuLpi-jYBU0fCkKvREQ,7
|
|
11
|
-
python_homely-0.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|