CK-InoDrive-API 0.2.9__tar.gz → 1.0.0__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.
Files changed (25) hide show
  1. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CK_InoDrive_API.egg-info/PKG-INFO +3 -3
  2. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CK_InoDrive_API.egg-info/SOURCES.txt +1 -0
  3. ck_inodrive_api-1.0.0/CK_InoDrive_API.egg-info/requires.txt +3 -0
  4. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/IO.py +16 -13
  5. ck_inodrive_api-1.0.0/CkInoDriveAPI/ck_ca.crt +15 -0
  6. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/discoverLan.py +9 -120
  7. ck_inodrive_api-1.0.0/CkInoDriveAPI/discoverWs.py +42 -0
  8. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/file.py +20 -17
  9. ck_inodrive_api-1.0.0/CkInoDriveAPI/inoDrive.py +133 -0
  10. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/sysControl.py +5 -2
  11. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/userApp.py +187 -181
  12. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/utils.py +168 -38
  13. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/wsHandle.py +164 -122
  14. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/PKG-INFO +3 -3
  15. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/README.txt +42 -36
  16. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/setup.py +3 -2
  17. CK-InoDrive-API-0.2.9/CK_InoDrive_API.egg-info/requires.txt +0 -3
  18. CK-InoDrive-API-0.2.9/CkInoDriveAPI/discoverWs.py +0 -152
  19. CK-InoDrive-API-0.2.9/CkInoDriveAPI/inoDrive.py +0 -56
  20. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CK_InoDrive_API.egg-info/dependency_links.txt +0 -0
  21. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CK_InoDrive_API.egg-info/top_level.txt +0 -0
  22. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/__init__.py +0 -0
  23. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/CkInoDriveAPI/defines.py +0 -0
  24. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/LICENSE.txt +0 -0
  25. {CK-InoDrive-API-0.2.9 → ck_inodrive_api-1.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CK-InoDrive-API
3
- Version: 0.2.9
3
+ Version: 1.0.0
4
4
  Summary: InoDrive API Library
5
5
  Home-page: https://cardinalkinetic.com
6
6
  Author: Cardinal Kinetic
@@ -18,9 +18,9 @@ Classifier: Programming Language :: Python :: 3.12
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE.txt
20
20
  License-File: README.txt
21
- Requires-Dist: websocket-client==1.6.4
21
+ Requires-Dist: websocket-client==1.8.0
22
22
  Requires-Dist: ifaddr==0.2.0
23
- Requires-Dist: msgpack==1.0.7
23
+ Requires-Dist: msgpack==1.0.8
24
24
 
25
25
  #### **Installation**
26
26
 
@@ -8,6 +8,7 @@ CK_InoDrive_API.egg-info/requires.txt
8
8
  CK_InoDrive_API.egg-info/top_level.txt
9
9
  CkInoDriveAPI/IO.py
10
10
  CkInoDriveAPI/__init__.py
11
+ CkInoDriveAPI/ck_ca.crt
11
12
  CkInoDriveAPI/defines.py
12
13
  CkInoDriveAPI/discoverLan.py
13
14
  CkInoDriveAPI/discoverWs.py
@@ -0,0 +1,3 @@
1
+ websocket-client==1.8.0
2
+ ifaddr==0.2.0
3
+ msgpack==1.0.8
@@ -1,13 +1,16 @@
1
1
  import logging
2
2
 
3
- from .wsHandle import InoDriveWS
4
3
  from .defines import CK
5
4
  from .defines import OP_STATE
6
5
 
7
6
 
8
7
  class IO(object):
9
8
  def __init__(self, **kwargs):
10
- self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
9
+ self._get_connection_handle = kwargs.get('get_connection_handle')
10
+
11
+ @property
12
+ def _connection_handle(self):
13
+ return self._get_connection_handle()
11
14
 
12
15
  def dispose(self):
13
16
  return
@@ -130,7 +133,7 @@ class IO(object):
130
133
  logging.error(data['error'])
131
134
  return None
132
135
 
133
- if type(input) == int and input >= 0 and input <= 3:
136
+ if type(input) is int and 0 <= input <= 3:
134
137
  return 1 if (data['digital'] >> input) & 0x1 else 0
135
138
  else:
136
139
  return data['digital']
@@ -146,7 +149,7 @@ class IO(object):
146
149
  logging.error(data['error'])
147
150
  return None
148
151
 
149
- if type(input) == int and input >= 0 and input <= 1:
152
+ if type(input) is int and 0 <= input <= 1:
150
153
  return 1 if (data['safety'] >> input) & 0x1 else 0
151
154
  else:
152
155
  return data['safety']
@@ -173,14 +176,14 @@ class IO(object):
173
176
 
174
177
  if target == 'all' and state is not None:
175
178
  target = -1
176
- if type(state) == str:
179
+ if type(state) is str:
177
180
  state = 0xf if state.upper() == 'NPN' else 0x0
178
181
  else:
179
182
  state = 0xf if state else 0x0
180
- elif target == 'val' and type(state) == int:
183
+ elif target == 'val' and type(state) is int:
181
184
  target = -1
182
- elif type(target) == int and target >= 0 and target <= 3 and state is not None:
183
- if type(state) == str:
185
+ elif type(target) is int and 0 <= target <= 3 and state is not None:
186
+ if type(state) is str:
184
187
  state = 0x1 if state.upper() == 'NPN' else 0x0
185
188
  else:
186
189
  state = 0x1 if state else 0x0
@@ -207,7 +210,7 @@ class IO(object):
207
210
  logging.error(data['error'])
208
211
  return None
209
212
 
210
- if type(input) == int and input >= 0 and input <= 3:
213
+ if type(input) is int and 0 <= input <= 3:
211
214
  return 'NPN' if (data['polarity'] >> input) & 0x1 else 'PNP'
212
215
  else:
213
216
  return data['polarity']
@@ -235,9 +238,9 @@ class IO(object):
235
238
  if target == 'all' and state is not None:
236
239
  target = -1
237
240
  state = 0x7 if state else 0x0
238
- elif target == 'val' and type(state) == int:
241
+ elif target == 'val' and type(state) is int:
239
242
  target = -1
240
- elif type(target) == int and target >= 0 and target <= 2 and state is not None:
243
+ elif type(target) is int and 0 <= target <= 2 and state is not None:
241
244
  state = 0x1 if state else 0x0
242
245
  else:
243
246
  logging.error(f'InoDrive SetOutput Error: target os state not supported...')
@@ -263,7 +266,7 @@ class IO(object):
263
266
  logging.error(data['error'])
264
267
  return None
265
268
 
266
- if type(output) == int and output >= 0 and output <= 2:
269
+ if type(output) is int and 0 <= output <= 2:
267
270
  return 1 if (data['digital'] >> output) & 0x1 else 0
268
271
  else:
269
272
  return data['digital']
@@ -281,7 +284,7 @@ class IO(object):
281
284
  logging.error(data['error'])
282
285
  return None
283
286
 
284
- if type(output) == int and output >= 0 and output <= 2:
287
+ if type(output) is int and 0 <= output <= 2:
285
288
  return 1 if (data['digital_faults'] >> output) & 0x1 else 0
286
289
  else:
287
290
  return data['digital_faults']
@@ -0,0 +1,15 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICUTCCAdigAwIBAgIUKSVqbARTYaxckTUEA7Gby+uWD8IwCgYIKoZIzj0EAwIw
3
+ VzELMAkGA1UEBhMCVVMxETAPBgNVBAgMCEtlbnR1Y2t5MRgwFgYDVQQKDA9DYXJk
4
+ aW5hbEtpbmV0aWMxGzAZBgNVBAMMEkNhcmRpbmFsS2luZXRpYy1DQTAgFw0yNDA3
5
+ MTUxODM1NTVaGA8yMDk5MDQxMzE4MzU1NVowVzELMAkGA1UEBhMCVVMxETAPBgNV
6
+ BAgMCEtlbnR1Y2t5MRgwFgYDVQQKDA9DYXJkaW5hbEtpbmV0aWMxGzAZBgNVBAMM
7
+ EkNhcmRpbmFsS2luZXRpYy1DQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABGvtdcSO
8
+ PH4qPKdA/wSbraw88KgoiBmJMaD3ko4Gaix6iZSBTEK1TU+Oxp0XwVuaQxa0J7hp
9
+ xcjuy3BLYDhfF5e5Fp/Tjc4qaQNDZs9Z0MbVytZeNtrm7u4lwKWsjIjhUqNjMGEw
10
+ HQYDVR0OBBYEFOQ3kaz6Bd2kAHicNWlIoWdSYclMMB8GA1UdIwQYMBaAFOQ3kaz6
11
+ Bd2kAHicNWlIoWdSYclMMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGG
12
+ MAoGCCqGSM49BAMCA2cAMGQCMFhAt55Z+O88sJ60Z2FcGmYztu6QF18tdj04YlQX
13
+ SBWZ8tdpWofMsJi6yHwKlhqqQgIwVEpeh5RSuVSGmZAfYNFLLSnAYV0LnkKEAmuZ
14
+ 2YwmOc7BTjgjgnZrhb9538baKIaG
15
+ -----END CERTIFICATE-----
@@ -174,105 +174,12 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
174
174
  # Remove 9 bytes header
175
175
  data = resp[9:]
176
176
 
177
- # Discover version
178
- # =======================================================================
179
- item_size = 1
180
- discover_version = Utils.get_typed_value(data[0:item_size], 'uint8')
181
- data = data[item_size:]
182
- # =======================================================================
177
+ module_object = Utils.decode_discover_data(data)
178
+ sn = None
183
179
 
184
- # SN
185
- # =======================================================================
186
- item_size = 25
187
- sn = Utils.get_typed_value(data[0:item_size], 'string')
188
- data = data[item_size:]
189
- # =======================================================================
190
-
191
- # PN
192
- # =======================================================================
193
- item_size = 25
194
- pn = Utils.get_typed_value(data[0:item_size], 'string')
195
- data = data[item_size:]
196
- # =======================================================================
197
-
198
- # Name
199
- # =======================================================================
200
- item_size = 33
201
- name = Utils.get_typed_value(data[0:item_size], 'string')
202
- data = data[item_size:]
203
- # =======================================================================
204
-
205
- # Firmware version
206
- # =======================================================================
207
- item_size = 1
208
- fw_major = Utils.get_typed_value(data[0:item_size], 'uint8')
209
- data = data[item_size:]
210
-
211
- item_size = 1
212
- fw_minor = Utils.get_typed_value(data[0:item_size], 'uint8')
213
- data = data[item_size:]
214
-
215
- item_size = 1
216
- fw_build = Utils.get_typed_value(data[0:item_size], 'uint8')
217
- data = data[item_size:]
218
-
219
- item_size = 1
220
- fw_type = Utils.get_typed_value(data[0:item_size], 'uint8')
221
- data = data[item_size:]
222
-
223
- firmware_flags = Utils.get_firmware_flags(fw_type)
224
- # =======================================================================
225
-
226
- # Networking
227
- # =======================================================================
228
- item_size = 6
229
- mac_address = Utils.get_typed_value(data[0:item_size], 'macAddress')
230
- data = data[item_size:]
231
-
232
- item_size = 4
233
- ip_address = Utils.get_typed_value(data[0:item_size], 'ipV4')
234
- data = data[item_size:]
235
-
236
- item_size = 4
237
- net_mask = Utils.get_typed_value(data[0:item_size], 'ipV4')
238
- data = data[item_size:]
239
-
240
- item_size = 4
241
- gateway = Utils.get_typed_value(data[0:item_size], 'ipV4')
242
- data = data[item_size:]
243
-
244
- item_size = 4
245
- dns = Utils.get_typed_value(data[0:item_size], 'ipV4')
246
- data = data[item_size:]
247
- # =======================================================================
248
-
249
- # PCB Version
250
- # =======================================================================
251
- pcb_major = 1
252
- pcb_minor = 1
253
- pcb_build = 1
254
- pcb_type = 0
255
-
256
- if discover_version >= 2:
257
- item_size = 1
258
- pcb_major = Utils.get_typed_value(data[0:item_size], 'uint8')
259
- data = data[item_size:]
260
-
261
- item_size = 1
262
- pcb_minor = Utils.get_typed_value(data[0:item_size], 'uint8')
263
- data = data[item_size:]
264
-
265
- item_size = 1
266
- pcb_build = Utils.get_typed_value(data[0:item_size], 'uint8')
267
- data = data[item_size:]
268
-
269
- if discover_version >= 3:
270
- item_size = 1
271
- pcb_type = Utils.get_typed_value(data[0:item_size], 'uint8')
272
- data = data[item_size:]
273
-
274
- pcb_flags = Utils.get_pcb_flags(pcb_type)
275
- # =======================================================================
180
+ if module_object is not None:
181
+ module_object['netif'] = netif_ip_tuple[0]
182
+ sn = module_object['sn']
276
183
 
277
184
  except struct.error:
278
185
  continue
@@ -281,25 +188,7 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
281
188
  continue
282
189
 
283
190
  if sn not in modules_found:
284
- new_module_d = {
285
- 'discoverVersion': discover_version,
286
- 'sn': sn,
287
- 'pn': pn,
288
- 'name': name,
289
- 'firmware': '.'.join([str(fw_major), str(fw_minor), str(fw_build)]),
290
- 'firmwareFlags': firmware_flags,
291
- 'network': {
292
- 'ip': ip_address,
293
- 'mask': net_mask,
294
- 'gw': gateway,
295
- 'dns': dns,
296
- 'mac': mac_address,
297
- },
298
- 'pcb': '.'.join([str(pcb_major), str(pcb_minor), str(pcb_build)]),
299
- 'pcbFlags': pcb_flags,
300
- "netif": netif_ip_tuple[0]
301
- }
302
- modules_found[sn] = new_module_d
191
+ modules_found[sn] = module_object
303
192
  # for resp in response_list:
304
193
  # for iteration in range(num_attempts):
305
194
 
@@ -338,6 +227,6 @@ def id_discover_lan(net_adapter_ip=None, num_attempts=2):
338
227
  pass
339
228
 
340
229
  # Return a stripped down version of the dictionary because the serial number key is no longer needed.
341
- results_list = list(all_modules_on_all_ifs.values())
342
- logging.info(f'Total modules found: {len(results_list)}')
343
- return results_list
230
+ results = list(all_modules_on_all_ifs.values())
231
+ logging.info(f'Total modules found: {len(results)}')
232
+ return results
@@ -0,0 +1,42 @@
1
+ import logging
2
+
3
+ from .defines import CK
4
+ from .utils import Utils
5
+
6
+
7
+ class DiscoverWs(object):
8
+ def __init__(self, **kwargs):
9
+ self._get_connection_handle = kwargs.get('get_connection_handle')
10
+
11
+ @property
12
+ def _connection_handle(self):
13
+ return self._get_connection_handle()
14
+
15
+ def dispose(self):
16
+ return
17
+
18
+ def get_info(self):
19
+ try:
20
+ # Send request and wait for response
21
+ resp = self._connection_handle.request(Utils.get_tlv(CK.SPECIAL.GET_DISCOVER_INFO))
22
+
23
+ if resp.get('error'):
24
+ logging.error(f'Retrieving discover info failed...')
25
+ return None
26
+
27
+ result = None
28
+
29
+ resp_items = resp.get('items')
30
+ if resp_items and len(resp_items) > 0:
31
+ data = resp_items[0].get('data')
32
+ result = Utils.decode_discover_data(data)
33
+
34
+ if result is None:
35
+ logging.exception("Message decoding error")
36
+ return None
37
+
38
+ return result
39
+ except Exception as ex:
40
+ logging.exception(ex)
41
+
42
+ return None
@@ -1,14 +1,17 @@
1
1
  import json
2
2
  import logging
3
3
 
4
- from .wsHandle import InoDriveWS
5
4
  from .defines import CK
6
5
  from .utils import Utils
7
6
 
8
7
 
9
8
  class File(object):
10
9
  def __init__(self, **kwargs):
11
- self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
10
+ self._get_connection_handle = kwargs.get('get_connection_handle')
11
+
12
+ @property
13
+ def _connection_handle(self):
14
+ return self._get_connection_handle()
12
15
 
13
16
  def dispose(self):
14
17
  return
@@ -19,23 +22,23 @@ class File(object):
19
22
  logging.error(f'Files is None...')
20
23
  return None
21
24
 
22
- if type(files) != list:
25
+ if type(files) is not list:
23
26
  files = [files]
24
27
 
25
28
  files_content = []
26
29
 
27
30
  # Upload uApp and firmware are specifying different types
28
- transfer_type = transfer_type if type(transfer_type) == int else CK.FILE.TRANSFER
31
+ transfer_type = transfer_type if type(transfer_type) is int else CK.FILE.TRANSFER
29
32
 
30
33
  for file in files:
31
- if type(file) != dict:
34
+ if type(file) is not dict:
32
35
  logging.error(f'File is not a dict...')
33
36
  return None
34
37
 
35
38
  file_path = file.get('path')
36
39
  content = file.get('content', 'bytes')
37
40
 
38
- if type(file_path) != str:
41
+ if type(file_path) is not str:
39
42
  logging.error(f'File path is not a string...')
40
43
  return None
41
44
 
@@ -80,17 +83,17 @@ class File(object):
80
83
  def write(self, files=None, transfer_type=None):
81
84
  try:
82
85
  if files is None:
83
- logging.error(f'Files is None...')
86
+ logging.error(f'Files not provided...')
84
87
  return False
85
88
 
86
- if type(files) != list:
89
+ if type(files) is not list:
87
90
  files = [files]
88
91
 
89
92
  # Upload uApp and firmware are specifying different types
90
- transfer_type = transfer_type if type(transfer_type) == int else CK.FILE.TRANSFER
93
+ transfer_type = transfer_type if type(transfer_type) is int else CK.FILE.TRANSFER
91
94
 
92
95
  for file in files:
93
- if type(file) != dict:
96
+ if type(file) is not dict:
94
97
  logging.error(f'File is not a dict...')
95
98
  return False
96
99
 
@@ -108,13 +111,13 @@ class File(object):
108
111
 
109
112
  file_content = file.get('content')
110
113
 
111
- if type(file_content) == dict:
114
+ if type(file_content) is dict:
112
115
  file_content = json.dumps(file_content)
113
116
 
114
- if type(file_content) == str:
117
+ if type(file_content) is str:
115
118
  file_content = bytes(file_content, 'utf-8')
116
119
 
117
- if file_content is None or type(file_content) != bytes:
120
+ if file_content is None or type(file_content) is not bytes:
118
121
  logging.error(f'File content is not bytes...')
119
122
  return False
120
123
 
@@ -156,19 +159,19 @@ class File(object):
156
159
 
157
160
  def upload_user_app(self, content=None):
158
161
  try:
159
- return self.write({'path': "/uapp/application.idsol", 'content': content}, CK.FILE.UAPP_TRANSFER)
162
+ return self.write([{'path': "/uapp/application.idsol", 'content': content}], CK.FILE.UAPP_TRANSFER)
160
163
  except Exception as ex:
161
164
  logging.exception(ex)
162
165
 
163
166
  def upload_firmware(self, content=None):
164
167
  try:
165
- return self.write({'path': "/firmware/firmware.ckfw", 'content': content}, CK.FILE.FIRMWARE_TRANSFER)
168
+ return self.write([{'path': "/firmware/firmware.ckfw", 'content': content}], CK.FILE.FIRMWARE_TRANSFER)
166
169
  except Exception as ex:
167
170
  logging.exception(ex)
168
171
 
169
172
  def upload_webpage(self, content=None):
170
173
  try:
171
- return self.write({'path': "web.bfb", 'content': content}, CK.FILE.WEBPAGE_TRANSFER)
174
+ return self.write([{'path': "web.bfb", 'content': content}], CK.FILE.WEBPAGE_TRANSFER)
172
175
  except Exception as ex:
173
176
  logging.exception(ex)
174
177
 
@@ -180,7 +183,7 @@ class File(object):
180
183
 
181
184
  def write_module_config(self, content=None):
182
185
  try:
183
- if type(content) != dict:
186
+ if type(content) is not dict:
184
187
  logging.error('Content type is not dictionary')
185
188
  return False
186
189
 
@@ -0,0 +1,133 @@
1
+ import logging
2
+ import weakref
3
+
4
+ from .wsHandle import InoDriveWS
5
+ from .file import File
6
+ from .discoverWs import DiscoverWs
7
+ from .IO import IO
8
+ from .userApp import UserApp
9
+ from .sysControl import SysControl
10
+
11
+
12
+ class InoDrive(object):
13
+ _kwargs = None
14
+ _callbacks = {}
15
+ _connection_handle_instance = None
16
+
17
+ def __init__(self, **kwargs):
18
+ self._kwargs = kwargs
19
+ logging.debug('Create InoDrive instance...')
20
+ self._auto_connect = kwargs.get('autoConnect', False)
21
+
22
+ # ==============================================================================================================
23
+ # MODULES BEGIN
24
+ # ==============================================================================================================
25
+ self.File = File(**kwargs, get_connection_handle=self._get_connection_handle)
26
+ self.Discover = DiscoverWs(**kwargs, get_connection_handle=self._get_connection_handle)
27
+ self.IO = IO(**kwargs, get_connection_handle=self._get_connection_handle)
28
+ self.UserApp = UserApp(**kwargs, get_connection_handle=self._get_connection_handle)
29
+ self.SysControl = SysControl(**kwargs, get_connection_handle=self._get_connection_handle)
30
+ # ==============================================================================================================
31
+ # MODULES END
32
+ # ==============================================================================================================
33
+
34
+ # ==============================================================================================================
35
+ # CONNECTION
36
+ # ==============================================================================================================
37
+ if "useFallback" in self._kwargs:
38
+ self._use_fallback = False if self._kwargs["useFallback"] == False else True
39
+ else:
40
+ self._use_fallback = True
41
+
42
+ if "secureConnection" in self._kwargs:
43
+ False if self._kwargs["secureConnection"] == False else True
44
+ else:
45
+ self._kwargs["secureConnection"] = True
46
+
47
+ if self._auto_connect:
48
+ self.connect()
49
+ # ==============================================================================================================
50
+ # CONNECTION END
51
+ # ==============================================================================================================
52
+
53
+ # Finalizer weak reference to ensure InoDrive Object is cleaned up on code exit
54
+ self._finalizer = weakref.finalize(self, self.dispose)
55
+
56
+ def __del__(self):
57
+ self._finalizer()
58
+
59
+ def dispose(self):
60
+ try:
61
+ if self.UserApp:
62
+ self.UserApp.dispose()
63
+
64
+ if self._connection_handle_instance is not None:
65
+ self._connection_handle_instance = self._connection_handle_instance.dispose()
66
+ except Exception as ex:
67
+ logging.exception(ex)
68
+
69
+ def connect(self):
70
+ try:
71
+ if self._connection_handle_instance is None:
72
+ # Connection handle is not created yet
73
+ if self._kwargs["secureConnection"]:
74
+ try:
75
+ connection_handle = InoDriveWS(**self._kwargs, callbacks=self._callbacks, secure=True)
76
+ connection_handle.connect()
77
+ self._connection_handle_instance = connection_handle
78
+ except Exception as ex:
79
+ logging.exception(ex)
80
+ if connection_handle:
81
+ connection_handle = connection_handle.dispose()
82
+
83
+ if not self._use_fallback:
84
+ return
85
+ else:
86
+ connection_handle = InoDriveWS(**self._kwargs, callbacks=self._callbacks, secure=False)
87
+ connection_handle.connect()
88
+ self._connection_handle_instance = connection_handle
89
+ else:
90
+ self._connection_handle_instance.connect()
91
+ except Exception as ex:
92
+ logging.exception(ex)
93
+
94
+ def disconnect(self):
95
+ try:
96
+ if self._connection_handle_instance is not None:
97
+ self._connection_handle_instance.disconnect()
98
+ except Exception as ex:
99
+ logging.exception(ex)
100
+
101
+ def set_target(self, target):
102
+ if type(target) is not str:
103
+ return
104
+
105
+ if self._connection_handle_instance is not None:
106
+ return self._connection_handle_instance.set_target(target)
107
+
108
+ self._kwargs.host = target
109
+
110
+ def on(self, evt, func):
111
+ try:
112
+ match evt:
113
+ case "connect":
114
+ self._callbacks['onConnect'] = func if callable(func) else None
115
+ case "disconnect":
116
+ self._callbacks['onDisconnect'] = func if callable(func) else None
117
+ case "error":
118
+ self._callbacks['onError'] = func if callable(func) else None
119
+ case "message":
120
+ self._callbacks['onMessage'] = func if callable(func) else None
121
+ except Exception as ex:
122
+ logging.exception(ex)
123
+
124
+ @property
125
+ def connected(self):
126
+ if self._connection_handle_instance is not None:
127
+ return self._connection_handle_instance.connected
128
+
129
+ return False
130
+
131
+ def _get_connection_handle(self):
132
+ if self._connection_handle_instance is not None:
133
+ return self._connection_handle_instance
@@ -1,13 +1,16 @@
1
1
  import logging
2
2
 
3
- from .wsHandle import InoDriveWS
4
3
  from .defines import CK
5
4
  from .utils import Utils
6
5
 
7
6
 
8
7
  class SysControl(object):
9
8
  def __init__(self, **kwargs):
10
- self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
9
+ self._get_connection_handle = kwargs.get('get_connection_handle')
10
+
11
+ @property
12
+ def _connection_handle(self):
13
+ return self._get_connection_handle()
11
14
 
12
15
  def dispose(self):
13
16
  return