socketry 0.2.1__tar.gz → 0.2.2__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.
- {socketry-0.2.1 → socketry-0.2.2}/PKG-INFO +1 -1
- {socketry-0.2.1 → socketry-0.2.2}/pyproject.toml +1 -1
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/__init__.py +9 -1
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/client.py +9 -5
- {socketry-0.2.1 → socketry-0.2.2}/README.md +0 -0
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/__main__.py +0 -0
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/_constants.py +0 -0
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/_crypto.py +0 -0
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/cli.py +0 -0
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/properties.py +0 -0
- {socketry-0.2.1 → socketry-0.2.2}/src/socketry/py.typed +0 -0
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"""Python API and CLI for controlling Jackery portable power stations."""
|
|
2
2
|
|
|
3
|
-
from socketry.client import
|
|
3
|
+
from socketry.client import (
|
|
4
|
+
AuthenticationError,
|
|
5
|
+
Client,
|
|
6
|
+
Device,
|
|
7
|
+
MqttError,
|
|
8
|
+
SocketryError,
|
|
9
|
+
Subscription,
|
|
10
|
+
)
|
|
4
11
|
from socketry.properties import MODEL_NAMES, PROPERTIES, Setting
|
|
5
12
|
|
|
6
13
|
__all__ = [
|
|
@@ -11,5 +18,6 @@ __all__ = [
|
|
|
11
18
|
"MqttError",
|
|
12
19
|
"PROPERTIES",
|
|
13
20
|
"Setting",
|
|
21
|
+
"SocketryError",
|
|
14
22
|
"Subscription",
|
|
15
23
|
]
|
|
@@ -55,11 +55,15 @@ from socketry.properties import Setting, resolve
|
|
|
55
55
|
_TOKEN_EXPIRY_BUFFER = 3600 # seconds before expiry to trigger proactive refresh
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
class
|
|
58
|
+
class SocketryError(Exception):
|
|
59
|
+
"""Base exception for all socketry errors."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class TokenExpiredError(SocketryError):
|
|
59
63
|
"""Raised when the Jackery API returns error code 10402 (token expired)."""
|
|
60
64
|
|
|
61
65
|
|
|
62
|
-
class AuthenticationError(
|
|
66
|
+
class AuthenticationError(SocketryError):
|
|
63
67
|
"""Raised when login fails after an automatic re-authentication attempt.
|
|
64
68
|
|
|
65
69
|
Triggered when the Jackery API returns an auth error (session invalidated
|
|
@@ -68,7 +72,7 @@ class AuthenticationError(Exception):
|
|
|
68
72
|
"""
|
|
69
73
|
|
|
70
74
|
|
|
71
|
-
class _SessionInvalidatedError(
|
|
75
|
+
class _SessionInvalidatedError(SocketryError):
|
|
72
76
|
"""Internal sentinel: API returned a non-token-expiry auth/API error.
|
|
73
77
|
|
|
74
78
|
Raised by HTTP helpers to signal that the current session is rejected by
|
|
@@ -77,7 +81,7 @@ class _SessionInvalidatedError(RuntimeError):
|
|
|
77
81
|
"""
|
|
78
82
|
|
|
79
83
|
|
|
80
|
-
class MqttError(ConnectionError):
|
|
84
|
+
class MqttError(SocketryError, ConnectionError):
|
|
81
85
|
"""Raised when an MQTT operation fails.
|
|
82
86
|
|
|
83
87
|
Wraps :class:`aiomqtt.MqttError` so callers do not need to import
|
|
@@ -854,7 +858,7 @@ async def _http_login(
|
|
|
854
858
|
|
|
855
859
|
if body.get("code") != 0:
|
|
856
860
|
msg = body.get("msg", "unknown error")
|
|
857
|
-
raise
|
|
861
|
+
raise AuthenticationError(f"Login failed: {msg}")
|
|
858
862
|
|
|
859
863
|
data = body["data"]
|
|
860
864
|
token = body["token"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|