pysmarlaapi 0.6.0__py3-none-any.whl → 0.6.2__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.
Potentially problematic release.
This version of pysmarlaapi might be problematic. Click here for more details.
- pysmarlaapi/__init__.py +1 -1
- pysmarlaapi/classes/auth_token.py +6 -5
- pysmarlaapi/classes/connection.py +18 -17
- pysmarlaapi/connection_hub/__init__.py +4 -5
- pysmarlaapi/federwiege/__init__.py +9 -3
- {pysmarlaapi-0.6.0.dist-info → pysmarlaapi-0.6.2.dist-info}/METADATA +1 -1
- {pysmarlaapi-0.6.0.dist-info → pysmarlaapi-0.6.2.dist-info}/RECORD +9 -9
- {pysmarlaapi-0.6.0.dist-info → pysmarlaapi-0.6.2.dist-info}/WHEEL +0 -0
- {pysmarlaapi-0.6.0.dist-info → pysmarlaapi-0.6.2.dist-info}/licenses/LICENSE +0 -0
pysmarlaapi/__init__.py
CHANGED
|
@@ -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
|
|
|
@@ -19,22 +19,23 @@ class Connection:
|
|
|
19
19
|
else:
|
|
20
20
|
self.token = None
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
|
|
35
36
|
try:
|
|
36
|
-
|
|
37
|
+
self.token = AuthToken.from_json(json_body)
|
|
37
38
|
except ValueError:
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
return
|
|
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:
|
|
@@ -36,10 +36,16 @@ class Federwiege:
|
|
|
36
36
|
|
|
37
37
|
self.available = False
|
|
38
38
|
|
|
39
|
-
def get_service(self,
|
|
40
|
-
if
|
|
39
|
+
def get_service(self, key: str):
|
|
40
|
+
if key not in self.services:
|
|
41
41
|
return None
|
|
42
|
-
return self.services[
|
|
42
|
+
return self.services[key]
|
|
43
|
+
|
|
44
|
+
def get_property(self, service_key: str, prop_key: str):
|
|
45
|
+
service = self.get_service(service_key)
|
|
46
|
+
if not service:
|
|
47
|
+
return None
|
|
48
|
+
return service.get_property(prop_key)
|
|
43
49
|
|
|
44
50
|
def connect(self):
|
|
45
51
|
with self._lock:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
pysmarlaapi/__init__.py,sha256=
|
|
1
|
+
pysmarlaapi/__init__.py,sha256=Ri9MvYD3A64kxEx0v2t7ziBYvmqud7Fb8Ophky7vvZI,90
|
|
2
2
|
pysmarlaapi/classes/__init__.py,sha256=N-ZV3Id_t5ciovUlPUGCk5SLLiMUonRoQZWpfOU4ZsM,69
|
|
3
|
-
pysmarlaapi/classes/auth_token.py,sha256=
|
|
4
|
-
pysmarlaapi/classes/connection.py,sha256=
|
|
5
|
-
pysmarlaapi/connection_hub/__init__.py,sha256=
|
|
6
|
-
pysmarlaapi/federwiege/__init__.py,sha256=
|
|
3
|
+
pysmarlaapi/classes/auth_token.py,sha256=dpo0lBT9Advm3Iyxu-fT9sq078U2OxgXXBuF5gbBZkM,942
|
|
4
|
+
pysmarlaapi/classes/connection.py,sha256=kFwdZeKqgCV9VgVyvEIaPwLp8zsnbnDJRYbeFWvcxZA,1295
|
|
5
|
+
pysmarlaapi/connection_hub/__init__.py,sha256=4GwcybM2cr5vCfusGy4UhAKz-uwPyRHMOzWc9bP0WRo,4436
|
|
6
|
+
pysmarlaapi/federwiege/__init__.py,sha256=7Fl_GnwN6GbS8fhkHdfMhuYFospKnap40pvUtSGIeoE,1933
|
|
7
7
|
pysmarlaapi/federwiege/classes/__init__.py,sha256=DFJJVOKpra40S4ZX_oq2RyMazg6Nx0c8hoPggmj1bXA,60
|
|
8
8
|
pysmarlaapi/federwiege/classes/property.py,sha256=kTVbaGbWmmku5GmVq0mtWF8uSA7G8oHakyZ_LOO9h3c,1028
|
|
9
9
|
pysmarlaapi/federwiege/classes/service.py,sha256=Y0OQxtQLaHp4qY8Vthj0zRroPoYTiD2WA9ZR96teZTo,632
|
|
@@ -11,7 +11,7 @@ pysmarlaapi/federwiege/services/__init__.py,sha256=bJuOsk0lw9WWxB1NZodRTL8Pm_Ra8
|
|
|
11
11
|
pysmarlaapi/federwiege/services/analyser_service.py,sha256=y02j4cNvRAblBa1pTlJi1u1_7c3vV4xMj9uHe_vwV38,1789
|
|
12
12
|
pysmarlaapi/federwiege/services/babywiege_service.py,sha256=8hCu-uFAcT_G0F5oUD3EqYzb02L2bE5mVF72NrunEpc,2070
|
|
13
13
|
pysmarlaapi/federwiege/services/info_service.py,sha256=03a4eZFAL1zaIaWo1e-a_Zm2wVl0RuFLm2rTS7ABJIQ,1248
|
|
14
|
-
pysmarlaapi-0.6.
|
|
15
|
-
pysmarlaapi-0.6.
|
|
16
|
-
pysmarlaapi-0.6.
|
|
17
|
-
pysmarlaapi-0.6.
|
|
14
|
+
pysmarlaapi-0.6.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
15
|
+
pysmarlaapi-0.6.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
16
|
+
pysmarlaapi-0.6.2.dist-info/METADATA,sha256=yQbezgR-CCxh7D7i0x1X86kszFKdgAV2q-iFSDpTpLY,1106
|
|
17
|
+
pysmarlaapi-0.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|