pysmarlaapi 0.9.1__tar.gz → 0.9.3__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.9.1
3
+ Version: 0.9.3
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.9.1"
1
+ __version__ = "0.9.3"
2
2
 
3
3
  from .classes import Connection
4
4
  from .federwiege import Federwiege
@@ -16,6 +16,10 @@ async def event_wait(event, timeout):
16
16
  return
17
17
 
18
18
 
19
+ # suppress warnings from pysignalr (to avoid missing client method warnings)
20
+ logging.getLogger('pysignalr.client').setLevel(logging.ERROR)
21
+
22
+
19
23
  class ConnectionHub:
20
24
  """SignalRCore Hub
21
25
  Provides interface via websocket for the controller using the SignalRCore protocol.
@@ -33,13 +37,12 @@ class ConnectionHub:
33
37
  self,
34
38
  event_loop: asyncio.AbstractEventLoop,
35
39
  connection: Connection,
36
- interval: int = 60,
37
- backoff: int = 300,
40
+ max_delay: int = 256,
38
41
  ):
39
42
  self.connection: Connection = connection
40
43
  self._loop = event_loop
41
- self._interval = interval
42
- self._backoff = backoff
44
+ self._retry_delay = 1 # Initial connection retry delay
45
+ self._max_delay = max_delay
43
46
 
44
47
  self.logger = logging.getLogger(f"{__package__}[{self.connection.token.serialNumber}]")
45
48
 
@@ -80,6 +83,7 @@ class ConnectionHub:
80
83
  await listener(value)
81
84
 
82
85
  async def on_open_function(self):
86
+ self._retry_delay = 1
83
87
  self.logger.info("Connection to server established")
84
88
 
85
89
  async def on_close_function(self):
@@ -110,10 +114,14 @@ class ConnectionHub:
110
114
  self.logger.warning("Error during connection: %s: %s", type(e).__name__, str(e))
111
115
 
112
116
  # Random backoff to avoid simultaneous connection attempts
113
- backoff = random.randint(0, self._backoff)
114
- await event_wait(self._wake, self._interval + backoff)
117
+ jitter = random.uniform(0, 0.5) * self._retry_delay
118
+ await event_wait(self._wake, self._retry_delay + jitter)
115
119
  self._wake.clear()
116
120
 
121
+ # Double the delay for the next attempt
122
+ if self._retry_delay < self._max_delay:
123
+ self._retry_delay *= 2
124
+
117
125
  def wake_up(self):
118
126
  self._wake.set()
119
127
 
File without changes
File without changes
File without changes