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

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pysmarlaapi
3
- Version: 0.6.2
3
+ Version: 0.7.1
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.6.2"
1
+ __version__ = "0.7.1"
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,18 +25,23 @@ 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
+ response = await session.post(
31
+ "/api/AppParing/getToken",
32
+ headers={"accept": "*/*", "Content-Type": "application/json"},
33
+ data=jsonpickle.encode(self.token, unpicklable=False),
34
+ )
35
+ except (aiohttp.ClientError, asyncio.TimeoutError):
36
+ return False
37
+
38
+ if response.status != 200:
39
+ return False
40
+
41
+ content = await response.json()
35
42
 
36
43
  try:
37
- self.token = AuthToken.from_json(json_body)
44
+ self.token = AuthToken.from_json(content)
38
45
  except ValueError:
39
46
  return False
40
47
 
@@ -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