pysmarlaapi 0.7.0__tar.gz → 0.7.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.

Potentially problematic release.


This version of pysmarlaapi might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pysmarlaapi
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: Swing2Sleep Smarla API
5
5
  Author-email: Robin Lintermann <robin.lintermann@explicatis.com>
6
6
  Requires-Python: >=3.11
@@ -1,4 +1,4 @@
1
- __version__ = "0.7.0"
1
+ __version__ = "0.7.2"
2
2
 
3
3
  from .classes import Connection
4
4
  from .federwiege import Federwiege
@@ -1,3 +1,5 @@
1
+ import asyncio
2
+
1
3
  import aiohttp
2
4
  import jsonpickle
3
5
 
@@ -23,19 +25,28 @@ class Connection:
23
25
  return self.token.token
24
26
 
25
27
  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()
28
+ try:
29
+ async with aiohttp.ClientSession(self.url) as session:
30
+ content = await self._get_token(session)
31
+ except (aiohttp.ClientError, asyncio.TimeoutError):
32
+ return False
33
+
34
+ if not content:
35
+ return False
35
36
 
36
37
  try:
37
- self.token = AuthToken.from_json(json_body)
38
+ self.token = AuthToken.from_json(content)
38
39
  except ValueError:
39
40
  return False
40
41
 
41
42
  return True
43
+
44
+ async def _get_token(self, session: aiohttp.ClientSession):
45
+ async with await session.post(
46
+ "/api/AppParing/getToken",
47
+ headers={"accept": "*/*", "Content-Type": "application/json"},
48
+ data=jsonpickle.encode(self.token, unpicklable=False),
49
+ ) as response:
50
+ if response.status != 200:
51
+ return None
52
+ return await response.json()
@@ -86,7 +86,7 @@ class ConnectionHub:
86
86
  self.logger.info("Connection to server closed")
87
87
 
88
88
  async def on_error(self, message):
89
- self.logger.error("Connection error occurred: " + str(message))
89
+ self.logger.error("Connection error occurred: %s", str(message))
90
90
 
91
91
  def start(self):
92
92
  if self.running:
@@ -107,7 +107,7 @@ class ConnectionHub:
107
107
  try:
108
108
  await self.client.run()
109
109
  except Exception as e:
110
- self.logger.warning(f"Error during connection: {type(e).__name__}: {str(e)}")
110
+ self.logger.warning("Error during connection: %s: %s", type(e).__name__, str(e))
111
111
 
112
112
  # Random backoff to avoid simultaneous connection attempts
113
113
  backoff = random.randint(0, self._backoff)
@@ -136,7 +136,7 @@ class ConnectionHub:
136
136
  if value is not None:
137
137
  serialized_result["value"] = value
138
138
 
139
- self.logger.debug(f"Sending data, Event: {event}, Payload: {str(serialized_result)}")
139
+ self.logger.debug("Sending data, Event: %s, Payload: %s", event, str(serialized_result))
140
140
 
141
141
  asyncio.run_coroutine_threadsafe(self.async_send_data(event, [serialized_result]), self._loop)
142
142
 
File without changes
File without changes
File without changes