s2-python 0.2.0__tar.gz → 0.2.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.
- {s2_python-0.2.0 → s2_python-0.2.1}/PKG-INFO +1 -1
- {s2_python-0.2.0 → s2_python-0.2.1}/setup.cfg +1 -1
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2_python.egg-info/PKG-INFO +1 -1
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/s2_connection.py +38 -25
- {s2_python-0.2.0 → s2_python-0.2.1}/README.rst +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/pyproject.toml +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/setup.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2_python.egg-info/SOURCES.txt +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2_python.egg-info/dependency_links.txt +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2_python.egg-info/entry_points.txt +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2_python.egg-info/not-zip-safe +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2_python.egg-info/requires.txt +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2_python.egg-info/top_level.txt +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/__init__.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/__init__.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/duration.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/handshake.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/handshake_response.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/instruction_status_update.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/number_range.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/power_forecast.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/power_forecast_element.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/power_forecast_value.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/power_measurement.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/power_range.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/power_value.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/reception_status.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/resource_manager_details.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/revoke_object.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/role.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/select_control_type.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/session_request.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/support.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/timer.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/common/transition.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/__init__.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_actuator_description.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_actuator_status.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_fill_level_target_profile.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_fill_level_target_profile_element.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_instruction.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_leakage_behaviour.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_leakage_behaviour_element.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_operation_mode.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_operation_mode_element.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_storage_description.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_storage_status.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_system_description.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_timer_status.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_usage_forecast.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_usage_forecast_element.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/rm.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/generated/__init__.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/generated/gen_s2.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/reception_status_awaiter.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/s2_control_type.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/s2_parser.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/s2_validation_error.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/utils.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/validate_values_mixin.py +0 -0
- {s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/version.py +0 -0
@@ -8,7 +8,7 @@ license_files = LICENSE.txt
|
|
8
8
|
long_description = file: README.rst
|
9
9
|
long_description_content_type = text/x-rst; charset=UTF-8
|
10
10
|
url = https://github.com/flexiblepower/s2-ws-json-python
|
11
|
-
version = 0.2.
|
11
|
+
version = 0.2.1
|
12
12
|
platforms = Linux
|
13
13
|
classifiers =
|
14
14
|
Development Status :: 4 - Beta
|
@@ -6,6 +6,7 @@ import uuid
|
|
6
6
|
from dataclasses import dataclass
|
7
7
|
from typing import Optional, List, Type, Dict, Callable, Awaitable, Union
|
8
8
|
|
9
|
+
import websockets
|
9
10
|
from websockets.asyncio.client import ClientConnection as WSConnection, connect as ws_connect
|
10
11
|
|
11
12
|
from s2python.common import (
|
@@ -193,7 +194,6 @@ class S2Connection: # pylint: disable=too-many-instance-attributes
|
|
193
194
|
_received_messages: asyncio.Queue
|
194
195
|
|
195
196
|
_eventloop: asyncio.AbstractEventLoop
|
196
|
-
_background_tasks: Optional[asyncio.Task]
|
197
197
|
_stop_event: asyncio.Event
|
198
198
|
|
199
199
|
def __init__(
|
@@ -211,7 +211,6 @@ class S2Connection: # pylint: disable=too-many-instance-attributes
|
|
211
211
|
self._current_control_type = None
|
212
212
|
|
213
213
|
self._eventloop = asyncio.new_event_loop()
|
214
|
-
self._background_tasks = None
|
215
214
|
|
216
215
|
self.control_types = control_types
|
217
216
|
self.role = role
|
@@ -222,13 +221,17 @@ class S2Connection: # pylint: disable=too-many-instance-attributes
|
|
222
221
|
self._handlers.register_handler(HandshakeResponse, self.handle_handshake_response_as_rm)
|
223
222
|
|
224
223
|
def start_as_rm(self) -> None:
|
225
|
-
self._thread = threading.Thread(target=self._run_eventloop)
|
224
|
+
self._thread = threading.Thread(target=self._run_eventloop, daemon=False)
|
226
225
|
self._thread.start()
|
227
226
|
logger.debug("Started eventloop thread!")
|
228
227
|
|
229
228
|
def _run_eventloop(self) -> None:
|
230
229
|
logger.debug("Starting eventloop")
|
231
|
-
|
230
|
+
try:
|
231
|
+
self._eventloop.run_until_complete(self._run_as_rm())
|
232
|
+
except asyncio.CancelledError:
|
233
|
+
pass
|
234
|
+
logger.debug("S2 connection thread has stopped.")
|
232
235
|
|
233
236
|
def stop(self) -> None:
|
234
237
|
"""Stops the S2 connection.
|
@@ -242,41 +245,51 @@ class S2Connection: # pylint: disable=too-many-instance-attributes
|
|
242
245
|
"Do not call stop from the thread running the S2 connection. This results in an "
|
243
246
|
"infinite block!"
|
244
247
|
)
|
245
|
-
|
246
|
-
|
248
|
+
if self._eventloop.is_running():
|
249
|
+
asyncio.run_coroutine_threadsafe(self._do_stop(), self._eventloop).result()
|
250
|
+
self._thread.join()
|
251
|
+
logger.info("Stopped the S2 connection.")
|
247
252
|
|
248
253
|
async def _do_stop(self) -> None:
|
249
254
|
logger.info("Will stop the S2 connection.")
|
250
|
-
|
251
|
-
self._background_tasks.cancel()
|
252
|
-
self._background_tasks = None
|
253
|
-
|
254
|
-
if self.ws:
|
255
|
-
await self.ws.close()
|
256
|
-
await self.ws.wait_closed()
|
255
|
+
self._stop_event.set()
|
257
256
|
|
258
257
|
async def _run_as_rm(self) -> None:
|
259
258
|
logger.debug("Connecting as S2 resource manager.")
|
260
259
|
self._received_messages = asyncio.Queue()
|
260
|
+
self._stop_event = asyncio.Event()
|
261
261
|
await self.connect_ws()
|
262
262
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
return_when=asyncio.FIRST_EXCEPTION,
|
267
|
-
)
|
268
|
-
)
|
263
|
+
background_tasks = []
|
264
|
+
background_tasks.append(self._eventloop.create_task(self._receive_messages()))
|
265
|
+
background_tasks.append(self._eventloop.create_task(self._handle_received_messages()))
|
269
266
|
|
270
|
-
|
271
|
-
|
272
|
-
pending: List[asyncio.Task]
|
273
|
-
(done, pending) = await self._background_tasks
|
267
|
+
async def wait_till_stop() -> None:
|
268
|
+
await self._stop_event.wait()
|
274
269
|
|
270
|
+
background_tasks.append(self._eventloop.create_task(wait_till_stop()))
|
271
|
+
|
272
|
+
await self.connect_as_rm()
|
273
|
+
(done, pending) = await asyncio.wait(background_tasks, return_when=asyncio.FIRST_COMPLETED)
|
275
274
|
for task in done:
|
276
|
-
|
275
|
+
try:
|
276
|
+
await task
|
277
|
+
except asyncio.CancelledError:
|
278
|
+
pass
|
279
|
+
except websockets.ConnectionClosedError:
|
280
|
+
logger.info("The other party closed the websocket connection.c")
|
277
281
|
|
278
282
|
for task in pending:
|
279
|
-
|
283
|
+
try:
|
284
|
+
task.cancel()
|
285
|
+
await task
|
286
|
+
except asyncio.CancelledError:
|
287
|
+
pass
|
288
|
+
|
289
|
+
if self.ws:
|
290
|
+
await self.ws.close()
|
291
|
+
await self.ws.wait_closed()
|
292
|
+
logger.debug("Finished S2 connection eventloop.")
|
280
293
|
|
281
294
|
async def connect_ws(self) -> None:
|
282
295
|
self.ws = await ws_connect(uri=self.url)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{s2_python-0.2.0 → s2_python-0.2.1}/src/s2python/frbc/frbc_fill_level_target_profile_element.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|