pysmarlaapi 0.10.1__py3-none-any.whl → 0.10.3__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/connection_hub/__init__.py +6 -49
- pysmarlaapi/federwiege/__init__.py +4 -5
- {pysmarlaapi-0.10.1.dist-info → pysmarlaapi-0.10.3.dist-info}/METADATA +1 -1
- {pysmarlaapi-0.10.1.dist-info → pysmarlaapi-0.10.3.dist-info}/RECORD +7 -7
- {pysmarlaapi-0.10.1.dist-info → pysmarlaapi-0.10.3.dist-info}/WHEEL +0 -0
- {pysmarlaapi-0.10.1.dist-info → pysmarlaapi-0.10.3.dist-info}/licenses/LICENSE +0 -0
pysmarlaapi/__init__.py
CHANGED
|
@@ -38,35 +38,32 @@ class ConnectionHub:
|
|
|
38
38
|
self,
|
|
39
39
|
event_loop: asyncio.AbstractEventLoop,
|
|
40
40
|
connection: Connection,
|
|
41
|
+
listener,
|
|
41
42
|
max_delay: int = 256,
|
|
42
|
-
forced_reconnect_interval: int = 86400,
|
|
43
43
|
):
|
|
44
44
|
self.connection: Connection = connection
|
|
45
45
|
self._loop = event_loop
|
|
46
46
|
self._retry_delay = 1 # Initial connection retry delay
|
|
47
47
|
self._max_delay = max_delay
|
|
48
|
-
self._forced_reconnect_interval = forced_reconnect_interval
|
|
49
48
|
|
|
50
49
|
self.logger = logging.getLogger(f"{__package__}[{self.connection.token.serialNumber}]")
|
|
51
50
|
|
|
52
|
-
self.
|
|
51
|
+
self.connection_callback = listener
|
|
53
52
|
|
|
54
53
|
self._running = False
|
|
55
54
|
self._wake = asyncio.Event()
|
|
56
55
|
|
|
57
|
-
self._reconnect_future: asyncio.Future = None
|
|
58
|
-
self._reconnect_lock = asyncio.Lock()
|
|
59
|
-
self._reconnect_cancel_event = asyncio.Event()
|
|
60
|
-
|
|
61
56
|
self.client = None
|
|
62
57
|
self.setup()
|
|
63
58
|
|
|
64
59
|
async def notifycontrollerconnection(self, args):
|
|
65
60
|
value = args[0]
|
|
66
61
|
if value == "ControllerConnected":
|
|
67
|
-
|
|
62
|
+
self.logger.info("Controller connected")
|
|
63
|
+
await self.connection_callback(True)
|
|
68
64
|
else:
|
|
69
|
-
|
|
65
|
+
self.logger.info("Controller disconnected")
|
|
66
|
+
await self.connection_callback(False)
|
|
70
67
|
|
|
71
68
|
def setup(self):
|
|
72
69
|
self.client = SignalRClient(self.connection.url + "/MobileAppHub", retry_count=1)
|
|
@@ -75,28 +72,12 @@ class ConnectionHub:
|
|
|
75
72
|
self.client.on_error(self.on_error)
|
|
76
73
|
self.client.on("SetNotifyAppConnectionCallback", self.notifycontrollerconnection)
|
|
77
74
|
|
|
78
|
-
def add_listener(self, listener):
|
|
79
|
-
if self.running:
|
|
80
|
-
return
|
|
81
|
-
self.listeners.add(listener)
|
|
82
|
-
|
|
83
|
-
def remove_listener(self, listener):
|
|
84
|
-
if self.running:
|
|
85
|
-
return
|
|
86
|
-
self.listeners.remove(listener)
|
|
87
|
-
|
|
88
|
-
async def notify_listeners(self, value):
|
|
89
|
-
for listener in self.listeners:
|
|
90
|
-
await listener(value)
|
|
91
|
-
|
|
92
75
|
async def on_open_function(self):
|
|
93
76
|
self._retry_delay = 1
|
|
94
77
|
self.logger.info("Connection to server established")
|
|
95
|
-
await self.start_reconnect_job()
|
|
96
78
|
|
|
97
79
|
async def on_close_function(self):
|
|
98
80
|
self.logger.info("Connection to server closed")
|
|
99
|
-
await self.cancel_reconnect_job()
|
|
100
81
|
|
|
101
82
|
async def on_error(self, message):
|
|
102
83
|
self.logger.error("Connection error occurred: %s", str(message))
|
|
@@ -138,30 +119,6 @@ class ConnectionHub:
|
|
|
138
119
|
async def close_connection(self):
|
|
139
120
|
if not self.connected:
|
|
140
121
|
return
|
|
141
|
-
await self.cancel_reconnect_job()
|
|
142
|
-
await self.client._transport._ws.close()
|
|
143
|
-
|
|
144
|
-
async def start_reconnect_job(self):
|
|
145
|
-
async with self._reconnect_lock:
|
|
146
|
-
if self._reconnect_future and not self._reconnect_future.done():
|
|
147
|
-
return
|
|
148
|
-
self._reconnect_cancel_event.clear()
|
|
149
|
-
self._reconnect_future = asyncio.create_task(self.reconnect_job())
|
|
150
|
-
|
|
151
|
-
async def cancel_reconnect_job(self):
|
|
152
|
-
async with self._reconnect_lock:
|
|
153
|
-
if not self._reconnect_future or self._reconnect_future.done():
|
|
154
|
-
return
|
|
155
|
-
self._reconnect_cancel_event.set()
|
|
156
|
-
await self._reconnect_future
|
|
157
|
-
|
|
158
|
-
async def reconnect_job(self):
|
|
159
|
-
cancelled = await event_wait(self._reconnect_cancel_event, self._forced_reconnect_interval)
|
|
160
|
-
if cancelled:
|
|
161
|
-
return
|
|
162
|
-
|
|
163
|
-
# Close connection to trigger a reconnection
|
|
164
|
-
# Make sure that connection stays healthy
|
|
165
122
|
await self.client._transport._ws.close()
|
|
166
123
|
|
|
167
124
|
async def refresh_token(self):
|
|
@@ -18,14 +18,14 @@ class Federwiege:
|
|
|
18
18
|
def connected(self):
|
|
19
19
|
return self.hub.connected
|
|
20
20
|
|
|
21
|
-
async def
|
|
21
|
+
async def on_connection_change(self, value):
|
|
22
22
|
self.available = value
|
|
23
|
-
if
|
|
23
|
+
if self.available:
|
|
24
24
|
self.sync()
|
|
25
25
|
|
|
26
26
|
def __init__(self, event_loop: asyncio.AbstractEventLoop, connection: Connection):
|
|
27
27
|
self.serial_number = connection.token.serialNumber
|
|
28
|
-
self.hub = ConnectionHub(event_loop, connection)
|
|
28
|
+
self.hub = ConnectionHub(event_loop, connection, self.on_connection_change)
|
|
29
29
|
self.services: dict[str, Service] = {
|
|
30
30
|
"babywiege": BabywiegeService(self.hub),
|
|
31
31
|
"analyser": AnalyserService(self.hub),
|
|
@@ -66,7 +66,6 @@ class Federwiege:
|
|
|
66
66
|
with self._lock:
|
|
67
67
|
if self.registered:
|
|
68
68
|
return
|
|
69
|
-
self.registered = True
|
|
70
|
-
self.hub.add_listener(self.on_controller_connection_change)
|
|
71
69
|
for service in self.services.values():
|
|
72
70
|
service.register()
|
|
71
|
+
self.registered = True
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
pysmarlaapi/__init__.py,sha256=
|
|
1
|
+
pysmarlaapi/__init__.py,sha256=8RGaOyUGbyQ_K8qBXrePMnucfknkt0WORdJ3M1d6DBw,91
|
|
2
2
|
pysmarlaapi/classes/__init__.py,sha256=N-ZV3Id_t5ciovUlPUGCk5SLLiMUonRoQZWpfOU4ZsM,69
|
|
3
3
|
pysmarlaapi/classes/auth_token.py,sha256=dpo0lBT9Advm3Iyxu-fT9sq078U2OxgXXBuF5gbBZkM,942
|
|
4
4
|
pysmarlaapi/classes/connection.py,sha256=vVC0Ur0KQUb4pNDVuCYnfk-JXs-O-FwYVO-2y1E2g6g,1551
|
|
5
|
-
pysmarlaapi/connection_hub/__init__.py,sha256=
|
|
6
|
-
pysmarlaapi/federwiege/__init__.py,sha256=
|
|
5
|
+
pysmarlaapi/connection_hub/__init__.py,sha256=QUwB7j5BdF5dwal1_uFPUC7hqOMojLUeGlKHcd_32HQ,4624
|
|
6
|
+
pysmarlaapi/federwiege/__init__.py,sha256=LH3Uw9AjO4OAYcMQAIIJ8_i95l50YqcwDWai0E28UJA,1973
|
|
7
7
|
pysmarlaapi/federwiege/classes/__init__.py,sha256=DFJJVOKpra40S4ZX_oq2RyMazg6Nx0c8hoPggmj1bXA,60
|
|
8
8
|
pysmarlaapi/federwiege/classes/property.py,sha256=S5Zzo9cXDJMFcQG1vCw1eO-oqeSpQs2YjxWouN_KRkU,1032
|
|
9
9
|
pysmarlaapi/federwiege/classes/service.py,sha256=Y0OQxtQLaHp4qY8Vthj0zRroPoYTiD2WA9ZR96teZTo,632
|
|
@@ -16,7 +16,7 @@ pysmarlaapi/federwiege/types/__init__.py,sha256=XWB_IrNYbIyQjyR_oKAOvHAjGGRLSQqZ
|
|
|
16
16
|
pysmarlaapi/federwiege/types/send_diag_status.py,sha256=hxpfNQmZs1YOztxLVnN3Bu50fXwf-hfV6K8GiQlBvkk,120
|
|
17
17
|
pysmarlaapi/federwiege/types/spring_status.py,sha256=cJsWFf2ZG-NvnT3l_CxVJfMFB3Ruv_juTy7Lpb-YEsA,227
|
|
18
18
|
pysmarlaapi/federwiege/types/update_status.py,sha256=YkajOEJ09pY9u4EBxw8ePEjPjYOLdK0i2l41cXbjb8Y,123
|
|
19
|
-
pysmarlaapi-0.10.
|
|
20
|
-
pysmarlaapi-0.10.
|
|
21
|
-
pysmarlaapi-0.10.
|
|
22
|
-
pysmarlaapi-0.10.
|
|
19
|
+
pysmarlaapi-0.10.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
20
|
+
pysmarlaapi-0.10.3.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
21
|
+
pysmarlaapi-0.10.3.dist-info/METADATA,sha256=SoziHBuB2_oZZHDlt1hsszyzMStlrGXhVUeie-hMoWM,1104
|
|
22
|
+
pysmarlaapi-0.10.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|