pysmarlaapi 0.6.0__tar.gz → 0.6.1__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.
Potentially problematic release.
This version of pysmarlaapi might be problematic. Click here for more details.
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/PKG-INFO +1 -1
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/__init__.py +1 -1
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/classes/auth_token.py +6 -5
- pysmarlaapi-0.6.1/pysmarlaapi/classes/connection.py +41 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/connection_hub/__init__.py +4 -5
- pysmarlaapi-0.6.0/pysmarlaapi/classes/connection.py +0 -40
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/LICENSE +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/README.md +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pyproject.toml +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/classes/__init__.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/__init__.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/classes/__init__.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/classes/property.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/classes/service.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/services/__init__.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/services/analyser_service.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/services/babywiege_service.py +0 -0
- {pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/services/info_service.py +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import base64
|
|
2
|
+
import json
|
|
2
3
|
from dataclasses import dataclass
|
|
3
4
|
from typing import Self
|
|
4
5
|
|
|
@@ -16,16 +17,16 @@ class AuthToken:
|
|
|
16
17
|
appCulture: str
|
|
17
18
|
|
|
18
19
|
@classmethod
|
|
19
|
-
def from_json(cls, value) -> Self:
|
|
20
|
+
def from_json(cls, value: dict) -> Self:
|
|
20
21
|
value["py/object"] = "pysmarlaapi.classes.auth_token.AuthToken"
|
|
21
|
-
return jsonpickle.decode(
|
|
22
|
+
return jsonpickle.decode(json.dumps(value))
|
|
22
23
|
|
|
23
24
|
@classmethod
|
|
24
|
-
def from_string(cls, value) -> Self:
|
|
25
|
-
return AuthToken.from_json(
|
|
25
|
+
def from_string(cls, value: str) -> Self:
|
|
26
|
+
return AuthToken.from_json(json.loads(value))
|
|
26
27
|
|
|
27
28
|
@classmethod
|
|
28
|
-
def from_base64(cls, value) -> Self:
|
|
29
|
+
def from_base64(cls, value: str) -> Self:
|
|
29
30
|
token = base64.b64decode(value.encode()).decode()
|
|
30
31
|
return AuthToken.from_string(token)
|
|
31
32
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
import jsonpickle
|
|
3
|
+
|
|
4
|
+
from . import AuthToken
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Connection:
|
|
8
|
+
|
|
9
|
+
def __init__(self, url: str, token: AuthToken = None, token_str=None, token_json=None, token_b64=None):
|
|
10
|
+
self.url = url
|
|
11
|
+
if token is not None:
|
|
12
|
+
self.token = token
|
|
13
|
+
elif token_json is not None:
|
|
14
|
+
self.token = AuthToken.from_json(token_json)
|
|
15
|
+
elif token_str is not None:
|
|
16
|
+
self.token = AuthToken.from_string(token_str)
|
|
17
|
+
elif token_b64 is not None:
|
|
18
|
+
self.token = AuthToken.from_base64(token_b64)
|
|
19
|
+
else:
|
|
20
|
+
self.token = None
|
|
21
|
+
|
|
22
|
+
def get_token(self) -> str:
|
|
23
|
+
return self.token.token
|
|
24
|
+
|
|
25
|
+
async def refresh_token(self) -> bool:
|
|
26
|
+
async with aiohttp.ClientSession(self.url) as session:
|
|
27
|
+
async with session.post(
|
|
28
|
+
"/api/AppParing/getToken",
|
|
29
|
+
headers={"accept": "*/*", "Content-Type": "application/json"},
|
|
30
|
+
data=jsonpickle.encode(self.token, unpicklable=False),
|
|
31
|
+
) as response:
|
|
32
|
+
if response.status != 200:
|
|
33
|
+
return False
|
|
34
|
+
json_body = await response.json()
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
self.token = AuthToken.from_json(json_body)
|
|
38
|
+
except ValueError:
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
return True
|
|
@@ -123,9 +123,8 @@ class ConnectionHub:
|
|
|
123
123
|
asyncio.run_coroutine_threadsafe(self.client._transport._ws.close(), self._loop)
|
|
124
124
|
|
|
125
125
|
async def refresh_token(self):
|
|
126
|
-
await self.connection.
|
|
127
|
-
|
|
128
|
-
self.client._transport._headers["Authorization"] = f"Bearer {auth_token}"
|
|
126
|
+
await self.connection.refresh_token()
|
|
127
|
+
self.client._transport._headers["Authorization"] = f"Bearer {self.connection.get_token()}"
|
|
129
128
|
self.logger.info("Auth token refreshed")
|
|
130
129
|
|
|
131
130
|
def send_serialized_data(self, event, value=None):
|
|
@@ -139,9 +138,9 @@ class ConnectionHub:
|
|
|
139
138
|
|
|
140
139
|
self.logger.debug(f"Sending data, Event: {event}, Payload: {str(serialized_result)}")
|
|
141
140
|
|
|
142
|
-
asyncio.run_coroutine_threadsafe(self.
|
|
141
|
+
asyncio.run_coroutine_threadsafe(self.async_send_data(event, [serialized_result]), self._loop)
|
|
143
142
|
|
|
144
|
-
async def
|
|
143
|
+
async def async_send_data(self, event, data):
|
|
145
144
|
try:
|
|
146
145
|
await self.client.send(event, data)
|
|
147
146
|
except Exception:
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import aiohttp
|
|
2
|
-
import jsonpickle
|
|
3
|
-
|
|
4
|
-
from . import AuthToken
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class Connection:
|
|
8
|
-
|
|
9
|
-
def __init__(self, url: str, token: AuthToken = None, token_str=None, token_json=None, token_b64=None):
|
|
10
|
-
self.url = url
|
|
11
|
-
if token is not None:
|
|
12
|
-
self.token = token
|
|
13
|
-
elif token_json is not None:
|
|
14
|
-
self.token = AuthToken.from_json(token_json)
|
|
15
|
-
elif token_str is not None:
|
|
16
|
-
self.token = AuthToken.from_string(token_str)
|
|
17
|
-
elif token_b64 is not None:
|
|
18
|
-
self.token = AuthToken.from_base64(token_b64)
|
|
19
|
-
else:
|
|
20
|
-
self.token = None
|
|
21
|
-
|
|
22
|
-
async def get_token(self) -> AuthToken:
|
|
23
|
-
try:
|
|
24
|
-
async with aiohttp.ClientSession(self.url) as session:
|
|
25
|
-
async with session.post(
|
|
26
|
-
"/api/AppParing/getToken",
|
|
27
|
-
headers={"accept": "*/*", "Content-Type": "application/json"},
|
|
28
|
-
data=jsonpickle.encode(self.token, unpicklable=False),
|
|
29
|
-
) as response:
|
|
30
|
-
if response.status != 200:
|
|
31
|
-
return None
|
|
32
|
-
json_body = await response.json()
|
|
33
|
-
except ValueError:
|
|
34
|
-
return None
|
|
35
|
-
try:
|
|
36
|
-
new_token = AuthToken.from_json(json_body)
|
|
37
|
-
except ValueError:
|
|
38
|
-
return None
|
|
39
|
-
self.token = new_token
|
|
40
|
-
return self.token
|
|
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
|
{pysmarlaapi-0.6.0 → pysmarlaapi-0.6.1}/pysmarlaapi/federwiege/services/babywiege_service.py
RENAMED
|
File without changes
|
|
File without changes
|