CK-InoDrive-API 1.0.2__tar.gz → 1.0.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.
Files changed (25) hide show
  1. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CK_InoDrive_API.egg-info/PKG-INFO +4 -4
  2. ck_inodrive_api-1.0.3/CK_InoDrive_API.egg-info/requires.txt +4 -0
  3. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/__init__.py +1 -1
  4. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/defines.py +5 -9
  5. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/file.py +71 -0
  6. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/inoDrive.py +9 -10
  7. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/userApp.py +138 -50
  8. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/utils.py +3 -3
  9. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/wsHandle.py +51 -39
  10. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/PKG-INFO +4 -4
  11. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/README.txt +14 -11
  12. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/setup.py +4 -4
  13. ck_inodrive_api-1.0.2/CK_InoDrive_API.egg-info/requires.txt +0 -4
  14. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CK_InoDrive_API.egg-info/SOURCES.txt +0 -0
  15. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CK_InoDrive_API.egg-info/dependency_links.txt +0 -0
  16. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CK_InoDrive_API.egg-info/top_level.txt +0 -0
  17. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/IO.py +0 -0
  18. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/_version.py +0 -0
  19. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/callback.py +0 -0
  20. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/ck_ca.crt +0 -0
  21. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/discoverLan.py +0 -0
  22. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/discoverWs.py +0 -0
  23. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/CkInoDriveAPI/sysControl.py +0 -0
  24. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/LICENSE.txt +0 -0
  25. {ck_inodrive_api-1.0.2 → ck_inodrive_api-1.0.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: CK-InoDrive-API
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: InoDrive API Library
5
5
  Home-page: https://cardinalkinetic.com
6
6
  Author: Cardinal Kinetic
@@ -19,10 +19,10 @@ Classifier: Programming Language :: Python :: 3.14
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE.txt
21
21
  License-File: README.txt
22
- Requires-Dist: websocket-client==1.9.0
22
+ Requires-Dist: websocket-client==1.9.2
23
23
  Requires-Dist: ifaddr==0.2.0
24
- Requires-Dist: msgpack==1.1.2
25
- Requires-Dist: getmac==0.9.5
24
+ Requires-Dist: msgpack==1.2.4
25
+ Requires-Dist: getmac==0.9.6
26
26
  Dynamic: author
27
27
  Dynamic: author-email
28
28
  Dynamic: classifier
@@ -0,0 +1,4 @@
1
+ websocket-client==1.9.2
2
+ ifaddr==0.2.0
3
+ msgpack==1.2.4
4
+ getmac==0.9.6
@@ -2,4 +2,4 @@ from .inoDrive import InoDrive
2
2
  from .discoverLan import id_discover_lan
3
3
 
4
4
  discover = id_discover_lan
5
- __version__ = '1.0.2'
5
+ __version__ = '1.0.3'
@@ -159,15 +159,11 @@ class _CkDefines(object):
159
159
  MSG_PACK = _MsgPack()
160
160
  MSG_PACK_ERRORS = _MsgPackErrors()
161
161
 
162
- API_VAR_ACCESS = {
163
- 'none': 0,
164
- 'read': 1,
165
- 'write': 2,
166
- 'readWrite': 3,
167
- 0: "none",
168
- 1: "read",
169
- 2: "write",
170
- 3: "readWrite",
162
+ API_VAR_FLAGS = {
163
+ 'accessRead': 1 << 0,
164
+ 'accessWrite': 1 << 1,
165
+ 'accessFull': 1 << 2,
166
+ 'nonVolatile': 1 << 7,
171
167
  }
172
168
  API_C_TYPES = {
173
169
  'bool': {'type': 0, 'size': 1},
@@ -5,10 +5,44 @@ import logging
5
5
  from .defines import CK
6
6
  from .utils import Utils
7
7
 
8
+ GZIP_EXTENSIONS = [
9
+ ".html",
10
+ ".htm ",
11
+ ".xhtml",
12
+ ".xml",
13
+ ".svg ",
14
+ ".txt",
15
+ ".css",
16
+ ".js",
17
+ ".json",
18
+ ".md",
19
+ ".jpg",
20
+ ".jpeg",
21
+ ".png",
22
+ ".gif",
23
+ ".webp",
24
+ ".avif",
25
+ ".bmp",
26
+ ".ico",
27
+ ".pdf",
28
+ ".mp4",
29
+ ".webm",
30
+ ".ogg",
31
+ ".ogv",
32
+ ".oga",
33
+ ".mp3",
34
+ ".wav",
35
+ ".m4a",
36
+ ".ttf",
37
+ ".woff2",
38
+ ]
8
39
 
9
40
  class File(object):
10
41
  def __init__(self, **kwargs):
11
42
  self._get_connection_handle = kwargs.get('getConnectionHandle')
43
+ self._gzip_compress = kwargs.get('gZipCompress')
44
+ self._gzip_decompress = kwargs.get('gZipDecompress')
45
+
12
46
 
13
47
  @property
14
48
  def _connection_handle(self):
@@ -65,6 +99,10 @@ class File(object):
65
99
  return None
66
100
 
67
101
  file_content = response['items'][0]['data']
102
+
103
+ if self._is_gzip(file_path, file_content):
104
+ file_content = self._gzip_decompress(file_content)
105
+
68
106
  if content == 'json' or content == 'string':
69
107
  file_content = file_content.decode('utf-8')
70
108
  if content == 'json':
@@ -83,6 +121,8 @@ class File(object):
83
121
 
84
122
  def write(self, files=None, transfer_type=None, props={}):
85
123
  try:
124
+ no_compression = props.get('noCompression', False)
125
+
86
126
  if files is None:
87
127
  logging.error("Files not provided...")
88
128
  return False
@@ -122,6 +162,14 @@ class File(object):
122
162
  logging.error(f"File data is not bytes...")
123
163
  return False
124
164
 
165
+ compressed = None
166
+ if not no_compression and self._can_be_gzip(file_path):
167
+ # Gzip content
168
+ compressed = self._gzip_compress(file_content)
169
+
170
+ if compressed is not None and (len(compressed) < len(file_content)):
171
+ file_content = compressed
172
+
125
173
  msg = b''
126
174
  # file transfer first
127
175
  msg += Utils.get_tlv(transfer_type, CK.COMMAND.FILE_WRITE)
@@ -203,3 +251,26 @@ class File(object):
203
251
  return self.write({'path': '/config/module_cfg.json', 'content': content}, CK.FILE.TRANSFER, props)
204
252
  except Exception as ex:
205
253
  logging.exception(ex)
254
+
255
+ def _get_extension(self, file_path):
256
+ clean_path = file_path.split("?")[0].split("#")[0]
257
+ last_dot = clean_path.rfind(".")
258
+ last_slash = max(clean_path.rfind("/"), clean_path.rfind("\\"))
259
+
260
+ if last_dot == -1 or last_dot < last_slash:
261
+ return ""
262
+
263
+ return clean_path[last_dot:]
264
+
265
+ def _can_be_gzip(self, file_path):
266
+ extension = self._get_extension(file_path)
267
+ return extension in GZIP_EXTENSIONS
268
+
269
+ def _is_gzip(self, file_path, file_data):
270
+ if type(file_data) is not bytes:
271
+ return False
272
+
273
+ if self._can_be_gzip(file_path) and file_data[0] == 0x1f and file_data[1] == 0x8b and file_data[2] and 0x08:
274
+ return True
275
+
276
+ return False
@@ -1,6 +1,8 @@
1
1
  import logging
2
2
  import weakref
3
3
  import sys
4
+ import gzip
5
+
4
6
  from ._version import get_version_number
5
7
  from .callback import Callback
6
8
 
@@ -22,15 +24,6 @@ class InoDrive(object):
22
24
  self.version = get_version_number()
23
25
  self._kwargs = kwargs
24
26
 
25
- if (sys.platform == "win32") or (sys.platform == "win64"):
26
- self._os = "windows"
27
- elif sys.platform == "darwin":
28
- self._os = "mac"
29
- elif sys.platform == "linux":
30
- self._os = "linux"
31
- else:
32
- self._os = "unknown"
33
-
34
27
  logging.debug('Create InoDrive instance...')
35
28
  self._auto_connect = kwargs.get('autoConnect', False)
36
29
 
@@ -49,7 +42,7 @@ class InoDrive(object):
49
42
  # ==============================================================================================================
50
43
  # MODULES BEGIN
51
44
  # ==============================================================================================================
52
- self.File = File(**kwargs, getConnectionHandle=self._get_connection_handle, callback=self._callback)
45
+ self.File = File(**kwargs, gZipCompress=self._gzip_compress, gZipDecompress=self._gzip_decompress, getConnectionHandle=self._get_connection_handle, callback=self._callback)
53
46
  self.Discover = DiscoverWs(**kwargs, getConnectionHandle=self._get_connection_handle, callback=self._callback)
54
47
  self.IO = IO(**kwargs, getConnectionHandle=self._get_connection_handle, callback=self._callback)
55
48
  self.UserApp = UserApp(**kwargs, getConnectionHandle=self._get_connection_handle, callback=self._callback)
@@ -149,3 +142,9 @@ class InoDrive(object):
149
142
  def _get_connection_handle(self):
150
143
  if self._connection_handle_instance is not None:
151
144
  return self._connection_handle_instance
145
+
146
+ def _gzip_decompress(self, data):
147
+ return gzip.decompress(data)
148
+
149
+ def _gzip_compress(self, data):
150
+ return gzip.compress(data)
@@ -124,14 +124,17 @@ class UserApp(object):
124
124
  try:
125
125
  var_list = []
126
126
 
127
- if access is None:
128
- access = [CK.API_VAR_ACCESS['read'], CK.API_VAR_ACCESS['readWrite']]
129
-
130
127
  if type(access) is not list:
131
128
  access = list(access)
132
129
 
133
130
  for var_name, var_props in self._variable_values.items():
134
- if access and var_props['access'] in access:
131
+ if access is not None:
132
+ for access_item in access:
133
+ if var_props['flags'][access_item] is True:
134
+ # Variable has at least one access rights satisfied
135
+ var_list.append(var_name)
136
+ break
137
+ else:
135
138
  var_list.append(var_name)
136
139
 
137
140
  return var_list
@@ -150,9 +153,9 @@ class UserApp(object):
150
153
  for var_name, var_props in self._variable_values.items():
151
154
  result['items'].update({var_name: {
152
155
  'id': var_props['id'],
153
- 'access': CK.API_VAR_ACCESS[var_props['access']],
154
156
  'type': var_props['type'],
155
157
  'value': var_props['value'],
158
+ 'flags': var_props['flags'],
156
159
  }})
157
160
 
158
161
  return result
@@ -185,11 +188,11 @@ class UserApp(object):
185
188
  resp = self._connection_handle.request(msg)
186
189
 
187
190
  if resp.get('error'):
188
- logging.error(f"Retrieving variables list failed...")
191
+ logging.error(resp['error'])
189
192
  return False
190
193
 
191
194
  if len(resp['items']) == 0:
192
- logging.error(f"Missing data.")
195
+ logging.error("Missing data.")
193
196
  return False
194
197
 
195
198
  if resp['items'][0]['ctpType'] != CK.TYPE.STRING:
@@ -237,7 +240,7 @@ class UserApp(object):
237
240
  for var_name in var_list:
238
241
  variable = self.get_variable(var_name)
239
242
  if not variable:
240
- logging.error(f"Variable < {var_name} > not found...")
243
+ logging.error(f"Variable < {var_name} > not found in the variables list...")
241
244
  return None
242
245
 
243
246
  if self._protocol == PROTOCOL_MSG_PACK:
@@ -263,17 +266,24 @@ class UserApp(object):
263
266
  for item in resp['data']:
264
267
  variable = self.get_variable(item[0])
265
268
  if variable:
269
+ variable['value'] = item[1]
270
+
266
271
  var_name = self._get_variable_name_by_id(variable['id'])
267
272
 
268
273
  precision = kwargs.get('floatPrecision')
269
- if (variable['type'] == 'float' or variable['type'] == 'double') and type(precision) is int:
270
- var_value = round(item[1], precision)
274
+ if variable['value'] is not None and (variable['type'] == 'float' or variable['type'] == 'double') and type(precision) is int:
275
+ if type(variable['value']) is list:
276
+ list_value = []
277
+ for row in variable['value']:
278
+ cur_column = []
279
+ for column in row:
280
+ cur_column.append(round(column, precision))
281
+ list_value.append(cur_column)
282
+ result.update({var_name: list_value})
283
+ else:
284
+ result.update({var_name: round(variable['value'], precision)})
271
285
  else:
272
- var_value = item[1]
273
-
274
- variable['value'] = var_value
275
-
276
- result.update({var_name: var_value})
286
+ result.update({var_name: variable['value']})
277
287
 
278
288
  if len(result) > 0:
279
289
  if type(argv) is list:
@@ -292,14 +302,15 @@ class UserApp(object):
292
302
 
293
303
  var_dict = {}
294
304
  request_data = []
305
+ val_is_list = type(value) is list
295
306
 
296
- if type(argv) is str or type(argv) is int:
307
+ if (type(argv) is str) or (type(argv) is int) and (not isinstance(value, (int, float)) or val_is_list):
297
308
  if value is None:
298
309
  logging.error("Missing new value for argument...")
299
310
  return False
300
311
 
301
312
  var_dict.update({argv: value})
302
- elif type(argv) is dict:
313
+ elif (argv is not list) and (type(argv) is dict):
303
314
  var_dict = argv
304
315
  else:
305
316
  logging.error("Unsupported argument type...")
@@ -307,24 +318,42 @@ class UserApp(object):
307
318
 
308
319
  for var_name, var_value in var_dict.items():
309
320
  variable = self.get_variable(var_name)
310
- if variable:
321
+
322
+ if not variable:
323
+ logging.error(f"Variable < {var_name} > not found in the variables list...")
324
+ return False
325
+
326
+ if val_is_list:
327
+ list_value = []
328
+ for row in var_value:
329
+ cur_column = []
330
+ for column in row:
331
+ # Message Pack protocol enforces true/false values for boolean variables.
332
+ # We make sure for boolean type we always send true/false
333
+ if variable['type'] == 'bool' and self._protocol == PROTOCOL_MSG_PACK:
334
+ cur_column.append(True if column else False)
335
+ else:
336
+ is_c_type = Utils.is_proper_c_type(column, variable['type'])
337
+ if is_c_type:
338
+ cur_column.append(column)
339
+ list_value.append(cur_column)
340
+ variable['value'] = list_value
341
+ else:
311
342
  is_c_type = Utils.is_proper_c_type(var_value, variable['type'])
312
343
  if is_c_type:
313
344
  # Message Pack protocol enforces true/false values for boolean variables.
314
345
  # We make sure for boolean type we always send true/false
315
- if variable['type'] == 'bool':
316
- var_value = True if var_value else False
317
-
318
- variable['value'] = var_value
319
- if self._protocol == PROTOCOL_MSG_PACK:
320
- request_data.append([variable['id'], True, var_value])
321
- elif self._protocol == PROTOCOL_JSON_API:
322
- request_data.append({'id': variable['id'], 'val': var_value})
346
+ if variable['type'] == 'bool' and self._protocol == PROTOCOL_MSG_PACK:
347
+ variable['value'] = True if var_value else False
323
348
  else:
324
- logging.error("Unsupported protocol...")
325
- return False
349
+ variable['value'] = var_value
350
+
351
+ if self._protocol == PROTOCOL_MSG_PACK:
352
+ request_data.append([variable['id'], True, variable['value']])
353
+ elif self._protocol == PROTOCOL_JSON_API:
354
+ request_data.append({'id': variable['id'], 'val': variable['value']})
326
355
  else:
327
- logging.error(f"Variable < {var_name} > not found...")
356
+ logging.error("Unsupported protocol...")
328
357
  return False
329
358
 
330
359
  resp = self._var_access_request(request_data)
@@ -350,19 +379,28 @@ class UserApp(object):
350
379
  var_list = argv
351
380
  else:
352
381
  logging.error("Unsupported argument type...")
353
- return None
382
+ return False
354
383
 
355
384
  for var_name in var_list:
356
385
  variable = self.get_variable(var_name)
357
386
 
358
387
  if not variable:
359
- logging.error(f"Variable < {var_name} > not found...")
388
+ logging.error(f"Variable < {var_name} > not found in the variables list...")
360
389
  return False
361
390
 
362
391
  variable_name = self._get_variable_name_by_id(variable['id'])
363
392
  precision = kwargs.get('floatPrecision')
364
393
  if (variable['type'] == 'float' or variable['type'] == 'double') and type(precision) is int:
365
- result.update({variable_name: round(variable['value'], precision)})
394
+ if type(variable['value']) is list:
395
+ list_value = []
396
+ for row in variable['value']:
397
+ cur_column = []
398
+ for column in row:
399
+ cur_column.append(round(column, precision))
400
+ list_value.append(cur_column)
401
+ result.update({variable_name: list_value})
402
+ else:
403
+ result.update({variable_name: round(variable['value'], precision)})
366
404
  else:
367
405
  result.update({variable_name: variable['value']})
368
406
 
@@ -379,14 +417,15 @@ class UserApp(object):
379
417
  def set_var(self, argv=None, value=None, **kwargs):
380
418
  try:
381
419
  var_dict = {}
420
+ val_is_list = type(value) is list
382
421
 
383
- if type(argv) is str or type(argv) is int:
422
+ if (type(argv) is str or type(argv) is int) and (not isinstance(value, (int, float)) or val_is_list):
384
423
  if value is None:
385
424
  logging.error("Missing new value for argument...")
386
425
  return False
387
426
 
388
427
  var_dict.update({argv: value})
389
- elif type(argv) is dict:
428
+ elif not type(argv) is list and type(argv) is dict:
390
429
  var_dict = argv
391
430
  else:
392
431
  logging.error("Unsupported argument type...")
@@ -395,20 +434,36 @@ class UserApp(object):
395
434
  for var_name, var_value in var_dict.items():
396
435
  variable = self.get_variable(var_name)
397
436
  if not variable:
398
- logging.error(f"Variable < {var_name} > not found...")
437
+ logging.error(f"Variable < {var_name} > not found in the variables list...")
399
438
  return False
400
439
 
401
- is_c_type = Utils.is_proper_c_type(var_value, variable['type'])
402
- if is_c_type:
403
- # Message Pack protocol enforces true/false values for boolean variables.
404
- # We make sure for boolean type we always send true/false
405
- if variable['type'] == 'bool':
406
- var_value = True if var_value else False
440
+ if val_is_list:
441
+ list_value = []
442
+ for row in var_value:
443
+ cur_column = []
444
+ for column in row:
445
+ # Message Pack protocol enforces true/false values for boolean variables.
446
+ # We make sure for boolean type we always send true/false
447
+ if variable['type'] == 'bool' and self._protocol == PROTOCOL_MSG_PACK:
448
+ cur_column.append(True if column else False)
449
+ else:
450
+ is_c_type = Utils.is_proper_c_type(column, variable['type'])
451
+ if is_c_type:
452
+ cur_column.append(column)
453
+ list_value.append(cur_column)
454
+ variable['value'] = list_value
455
+ else:
456
+ is_c_type = Utils.is_proper_c_type(var_value, variable['type'])
457
+ if is_c_type:
458
+ # Message Pack protocol enforces true/false values for boolean variables.
459
+ # We make sure for boolean type we always send true/false
460
+ if variable['type'] == 'bool' and self._protocol == PROTOCOL_MSG_PACK:
461
+ variable['value'] = True if var_value else False
462
+ else:
463
+ variable['value'] = var_value
407
464
 
408
- variable.update({
409
- 'value': var_value,
410
- 'write': True,
411
- })
465
+ # Flag variable for writing
466
+ variable['write'] = True
412
467
 
413
468
  return True
414
469
  except Exception as ex:
@@ -416,6 +471,39 @@ class UserApp(object):
416
471
 
417
472
  return False
418
473
 
474
+ def _get_var_flags(self, item):
475
+ access_read = False
476
+ access_write = False
477
+ access_full = False
478
+ non_volatile = False
479
+
480
+ if type(item) is dict:
481
+ if 'flags' in item and 'access' not in item:
482
+ access_read = True if item['flags'] & CK.API_VAR_FLAGS['accessRead'] else False
483
+ access_write = True if item['flags'] & CK.API_VAR_FLAGS['accessWrite'] else False
484
+ access_full = True if item['flags'] & CK.API_VAR_FLAGS['accessFull'] else False
485
+ non_volatile = True if item['flags'] & CK.API_VAR_FLAGS['nonVolatile'] else False
486
+ elif 'access' in item:
487
+ match item['access']:
488
+ case 0:
489
+ pass
490
+ case 1:
491
+ access_read = True
492
+ case 2:
493
+ access_read = True
494
+ access_write = True
495
+ case 3:
496
+ access_read = True
497
+ access_write = True
498
+ case 4:
499
+ access_full = True
500
+ return {
501
+ 'accessRead': access_read,
502
+ 'accessWrite': access_write,
503
+ 'accessFull': access_full,
504
+ 'nonVolatile': non_volatile
505
+ }
506
+
419
507
  def _on_connect(self, wsapp):
420
508
  try:
421
509
  if not self._connected:
@@ -508,16 +596,16 @@ class UserApp(object):
508
596
  self._variable_values.update({item['name']: {
509
597
  'id': item['id'],
510
598
  'type': Utils.get_var_c_type(item['type']),
511
- 'access': item['access'],
512
599
  'value': None,
513
600
  'write': False,
601
+ 'flags': self._get_var_flags(item),
514
602
  }})
515
603
  else:
516
604
  variable.update({
517
605
  'id': item['id'],
518
606
  'type': Utils.get_var_c_type(item['type']),
519
- 'access': item['access'],
520
- 'value': variable['value'],
607
+ 'value': variable['value'],
608
+ 'flags': self._get_var_flags(item),
521
609
  })
522
610
 
523
611
  self._initialized = True
@@ -595,7 +683,7 @@ class UserApp(object):
595
683
 
596
684
  # Write Variables
597
685
  # ===========================================================================================
598
- for var_name in self.get_variables_list([CK.API_VAR_ACCESS['write'], CK.API_VAR_ACCESS['readWrite']]):
686
+ for var_name in self.get_variables_list(["accessWrite", "accessFull"]):
599
687
  variable = self.get_variable(var_name)
600
688
  if variable and variable['write']:
601
689
  if self._protocol == PROTOCOL_MSG_PACK:
@@ -611,7 +699,7 @@ class UserApp(object):
611
699
 
612
700
  # Read Variables
613
701
  # ===========================================================================================
614
- for var_name in self.get_variables_list([CK.API_VAR_ACCESS['read'], CK.API_VAR_ACCESS['readWrite']]):
702
+ for var_name in self.get_variables_list(["accessRead", "accessFull"]):
615
703
  variable = self.get_variable(var_name)
616
704
  if variable:
617
705
  if self._protocol == PROTOCOL_MSG_PACK:
@@ -26,7 +26,7 @@ class CkUtils(object):
26
26
  logging.warning("InoDriveApi: Timestamp is deprecated due to SSL Certificate compatibility issues...")
27
27
 
28
28
  protocol_type = props.get('protocolType', "")
29
- if len([key for key in ['ws', 'http'] if key in protocol_type]) == 0:
29
+ if not (protocol_type in ['ws', 'http']):
30
30
  protocol_type = "ws"
31
31
 
32
32
  if target.find('.local') >= 0:
@@ -322,8 +322,8 @@ class CkUtils(object):
322
322
 
323
323
  if item['ctpType'] == CK.TYPE.INT_NUM:
324
324
  if idx == 0:
325
- msgType = consoleMsgTypes.TYPES[item['data'][0]]
326
- result['type'] = msgType if msgType else consoleMsgTypes[0]
325
+ msg_type = consoleMsgTypes.TYPES[item['data'][0]]
326
+ result['type'] = msg_type if msg_type else consoleMsgTypes[0]
327
327
  if item['ctpType'] == CK.TYPE.STRING:
328
328
  if "text" not in result:
329
329
  result['text'] = ""
@@ -20,9 +20,6 @@ class InoDriveWS(object):
20
20
 
21
21
  self._type = kwargs.get("type")
22
22
 
23
- # OS Type
24
- self._os = kwargs.get('os')
25
-
26
23
  self._key = kwargs.get("key")
27
24
 
28
25
  # Connection Properties
@@ -40,7 +37,7 @@ class InoDriveWS(object):
40
37
  self._secure = kwargs.get('secure', False)
41
38
 
42
39
  # Other
43
- self._reconnect_attempts = kwargs.get('reconnectAttempts', 2)
40
+ self.reconnect_attempts = kwargs.get('reconnectAttempts', 3)
44
41
 
45
42
  # Timeouts
46
43
  # connectTimeout should be 3 - 15 seconds. Low values like 3-5 should be good, even over the internet.
@@ -48,17 +45,18 @@ class InoDriveWS(object):
48
45
  # filesystem overhead and the transfer of 300k+ firmware file takes 2+ seconds.
49
46
  # Maybe we need separate file transfer and variable API timeouts.
50
47
  self._create_timeout = kwargs.get('createTimeout', 15)
51
- self._connect_timeout = kwargs.get('connectTimeout', (15 * self._reconnect_attempts))
48
+ self._connect_timeout = kwargs.get('connectTimeout', (15 * self.reconnect_attempts))
49
+ self._disconnect_timeout = kwargs.get('disconnectTimeout', 5)
52
50
  self._socket_timeout = kwargs.get('socketTimeout', 10)
53
51
  self._request_timeout = kwargs.get('requestTimeout', 30)
54
52
  self._keep_alive_timeout = kwargs.get('keepAliveTimeout', 5)
55
- self._reconnect_timeout = int(self._connect_timeout / self._reconnect_attempts - (self._connect_timeout / 10))
56
53
 
57
54
  if self._connect_timeout < 5:
58
55
  self._connect_timeout = 5
59
56
 
60
- if self._reconnect_attempts > 4:
61
- self._reconnect_attempts = 4
57
+ if self.reconnect_attempts > 4:
58
+ self.reconnect_attempts = 4
59
+ self.reconnect_timeout = int(self._connect_timeout / self.reconnect_attempts - (self._connect_timeout / 10))
62
60
 
63
61
  self._ws_input_buff_size = kwargs.get('wsInputBuffer', None)
64
62
 
@@ -73,7 +71,7 @@ class InoDriveWS(object):
73
71
 
74
72
  self._target_url = self.get_target()
75
73
 
76
- self._reconnect_count = self._reconnect_attempts
74
+ self._reconnect_count = self.reconnect_attempts
77
75
 
78
76
  self._last_request_time = int(time.time())
79
77
 
@@ -125,7 +123,7 @@ class InoDriveWS(object):
125
123
  def get_target(self, **kwargs):
126
124
  if not isinstance(kwargs, dict):
127
125
  kwargs = {}
128
- url = Utils.get_target_url(self._target, {'os': self._os, 'port': self._port, 'path': self._path, 'secure': self._secure, **kwargs})
126
+ url = Utils.get_target_url(self._target, {'port': self._port, 'path': self._path, 'secure': self._secure, **kwargs})
129
127
 
130
128
  search_props = []
131
129
 
@@ -165,19 +163,18 @@ class InoDriveWS(object):
165
163
 
166
164
  timeout = False
167
165
 
166
+ # ----------------------------------------------------------------------------------------------------#
168
167
  attempt = 1
169
- while attempt <= self._reconnect_attempts:
170
- self._state = "connecting"
171
- self._cmd_state = "connect"
172
-
173
- if self._connection_guard_timer is None:
174
- self._guard_start()
168
+ time_begin = int(time.time())
169
+ while (int(time.time()) - time_begin) < self._connect_timeout:
170
+ # Alternate between .local and without
171
+ url = self.get_target(dotLocal=(True if attempt & 0x1 else False))
175
172
 
176
173
  if not getattr(self, "_wsapp", None):
177
- logging.warning(f"Connect to: ---> {self._target_url}")
178
- timestamp = True if attempt == self._reconnect_attempts else False
179
- # Alternate between .local and without
180
- url = self.get_target(dotLocal=(True if attempt & 0x1 else False))
174
+ self._state = "connecting"
175
+ self._cmd_state = "connect"
176
+
177
+ logging.warning(f"Attempt {attempt}: Connect to: ---> {self._target_url}")
181
178
  # WebSocket instance
182
179
  self._wsapp = websocket.WebSocketApp(
183
180
  url,
@@ -187,6 +184,8 @@ class InoDriveWS(object):
187
184
  on_message=self.on_message
188
185
  )
189
186
 
187
+ self.set_binary(self._binary)
188
+
190
189
  # Secure Socket Options
191
190
  sslopt = None
192
191
  if self._secure:
@@ -208,29 +207,37 @@ class InoDriveWS(object):
208
207
  self._ws_thread_running = True
209
208
  self._ws_thread.start()
210
209
 
211
- time_begin = int(time.time())
212
- while (int(time.time()) - time_begin) < self._reconnect_timeout:
213
- if timeout or self._state != "connecting":
214
- break
215
- time.sleep(1)
216
-
217
- if not self.connected():
210
+ if self._state != "connecting":
218
211
  if self._wsapp is not None:
212
+ self._wsapp.on_open = None
213
+ self._wsapp.on_close = None
214
+ self._wsapp.on_error = None
215
+ self._wsapp.on_message = None
216
+
219
217
  self._wsapp.close()
220
- self._dispose_ws()
218
+ self._wsapp = None
219
+
220
+ attempt += 1
221
221
 
222
- if timeout:
222
+ if attempt > self.reconnect_attempts:
223
+ logging.warning(f"Connect reconnect count reached :---> {url}")
223
224
  break
224
225
 
225
- attempt += 1
226
- continue
226
+ time.sleep(0.1)
227
+
228
+ if self.connected():
229
+ break
230
+
231
+ if timeout:
232
+ logging.warning(f"Connect timeout :---> {url}")
233
+ break
227
234
 
228
- break
235
+ # ----------------------------------------------------------------------------------------------------#
229
236
 
230
237
  timeout_interval = self._connect_timeout
231
238
  while not self.connected() and timeout_interval > 0:
232
239
  timeout_interval -= 1
233
- time.sleep(1)
240
+ time.sleep(0.1)
234
241
 
235
242
  if not self.connected():
236
243
  timeout = True
@@ -241,7 +248,7 @@ class InoDriveWS(object):
241
248
  else:
242
249
  if timeout:
243
250
  logging.error(f"Connecting to: {self._target} timeout...")
244
- elif attempt >= self._reconnect_attempts:
251
+ elif attempt >= self.reconnect_attempts:
245
252
  logging.error(f"Connecting to: {self._target} reconnect...")
246
253
  else:
247
254
  logging.error(f"Connecting to: {self._target} failed...")
@@ -269,7 +276,7 @@ class InoDriveWS(object):
269
276
  self._wsapp.close()
270
277
 
271
278
  timeout = False
272
- timeout_interval = self._connect_timeout
279
+ timeout_interval = self._disconnect_timeout
273
280
  while not self.disconnected() and timeout_interval > 0:
274
281
  timeout_interval -= 1
275
282
  time.sleep(1)
@@ -296,7 +303,8 @@ class InoDriveWS(object):
296
303
  return True if self._state == "disconnected" else False
297
304
 
298
305
  def set_binary(self, flag):
299
- return {}
306
+ if self._wsapp:
307
+ self._wsapp.binary_type = "arraybuffer" if flag else "blob"
300
308
 
301
309
  def send(self, data):
302
310
  logging.exception("Method not implemented")
@@ -469,13 +477,17 @@ class InoDriveWS(object):
469
477
  def on_error(self, wsapp, evt):
470
478
  logging.exception(f"Connection error: {self._target_url}")
471
479
 
472
- if "errno" in evt:
480
+ error_msg = str(evt)
481
+
482
+ if "CERTIFICATE_VERIFY_FAILED" in error_msg:
473
483
  errno = evt.errno
474
484
  if errno == 10061:
475
485
  if self._secure:
476
486
  # Tried secure websocket connection and got active connection refusal, try unsecure websocket connection
477
487
  self._secure = False
478
488
  self._target_url = self.get_target()
489
+ else:
490
+ logging.exception(error_msg)
479
491
 
480
492
  self._state = "error"
481
493
 
@@ -570,10 +582,10 @@ class InoDriveWS(object):
570
582
  expire_list.append(token)
571
583
 
572
584
  for token in expire_list:
573
- logging.warning(f"Connection {self._target_url} token [ {token} ] timeout -> Garbage collected...")
574
585
  if self._msg_queue[token]['error']:
575
586
  logging.error(f"Request ID:{token} timeout...")
576
587
  del self._msg_queue[token]
588
+ logging.warning(f"Connection {self._target_url} token [ {token} ] timeout < Queue: {len(self._msg_queue)} -> Garbage collected...")
577
589
 
578
590
  # Keep Alive
579
591
  # =====================================================================================================
@@ -590,7 +602,7 @@ class InoDriveWS(object):
590
602
  # =====================================================================================================
591
603
  if self._reconnect and self._cmd_state == "connect" and not self.connected():
592
604
  if getattr(self, "_reconnect_time", 0):
593
- if (int(time.time()) - self._reconnect_time) >= self._reconnect_timeout:
605
+ if (int(time.time()) - self._reconnect_time) >= self.reconnect_timeout:
594
606
  self._reconnect_time = None
595
607
  if not self._connecting:
596
608
  self.connect()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: CK-InoDrive-API
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: InoDrive API Library
5
5
  Home-page: https://cardinalkinetic.com
6
6
  Author: Cardinal Kinetic
@@ -19,10 +19,10 @@ Classifier: Programming Language :: Python :: 3.14
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE.txt
21
21
  License-File: README.txt
22
- Requires-Dist: websocket-client==1.9.0
22
+ Requires-Dist: websocket-client==1.9.2
23
23
  Requires-Dist: ifaddr==0.2.0
24
- Requires-Dist: msgpack==1.1.2
25
- Requires-Dist: getmac==0.9.5
24
+ Requires-Dist: msgpack==1.2.4
25
+ Requires-Dist: getmac==0.9.6
26
26
  Dynamic: author
27
27
  Dynamic: author-email
28
28
  Dynamic: classifier
@@ -20,14 +20,14 @@ SECTION 1: Apache License, V2.0
20
20
 
21
21
  >>> bleach-5.0.1
22
22
  >>> id-1.6.1
23
- >>> msgpack-1.1.2
23
+ >>> msgpack-1.2.4
24
24
  >>> packaging-26.2
25
25
  >>> readme-renderer-44.0
26
26
  >>> requests-2.34.2
27
27
  >>> requests-toolbelt-1.0.0
28
28
  >>> rfc3986-2.0.0
29
- >>> twine-6.2.0
30
- >>> websocket-client-1.9.0
29
+ >>> twine-7.0.0
30
+ >>> websocket-client-1.9.2
31
31
 
32
32
  SECTION 2: BSD-STYLE, MIT-STYLE, OR SIMILAR STYLE LICENSES
33
33
 
@@ -38,7 +38,7 @@ SECTION 2: BSD-STYLE, MIT-STYLE, OR SIMILAR STYLE LICENSES
38
38
  >>> commonmark-0.9.1
39
39
  >>> docutils-0.23
40
40
  >>> flask-3.0.0
41
- >>> getmac-0.9.5
41
+ >>> getmac-0.9.6
42
42
  >>> greenlet-3.0.1
43
43
  >>> idna-3.17
44
44
  >>> ifaddr-0.2.0
@@ -58,10 +58,10 @@ SECTION 2: BSD-STYLE, MIT-STYLE, OR SIMILAR STYLE LICENSES
58
58
  >>> pycryptodome-3.19.0
59
59
  >>> pywin32-ctypes-0.2.3
60
60
  >>> rich-15.0.0
61
- >>> setuptools-82.0.1
61
+ >>> setuptools-84.2.1
62
62
  >>> six-1.16.0
63
63
  >>> sqlalchemy-2.0.23
64
- >>> urllib3-2.7.0
64
+ >>> urllib3-2.8.0
65
65
  >>> webencodings-0.5.1
66
66
  >>> werkzeug-3.0.1
67
67
  >>> zipp-3.21.0
@@ -77,6 +77,7 @@ SECTION 4: Mozilla Public License, V2.0
77
77
  SECTION 5: Python License, V2.0
78
78
 
79
79
  >>> base64
80
+ >>> gzip
80
81
  >>> ipaddress-1.0
81
82
  >>> json-2.0.9
82
83
  >>> logging-0.5.1.2
@@ -129,7 +130,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129
130
  See the License for the specific language governing permissions and
130
131
  limitations under the License.
131
132
 
132
- >>> msgpack-1.1.2
133
+ >>> msgpack-1.2.4
133
134
 
134
135
  Found in: msgpack-python/COPYING
135
136
 
@@ -188,8 +189,8 @@ Copyright 2014 Ian Cordasco, Rackspace
188
189
  >>> packaging-26.2
189
190
  >>> readme-renderer-44.0
190
191
  >>> requests-2.34.2
191
- >>> twine-6.2.0
192
- >>> websocket-client-1.9.0
192
+ >>> twine-7.0.0
193
+ >>> websocket-client-1.9.2
193
194
 
194
195
  Apache License
195
196
  Version 2.0, January 2004
@@ -706,7 +707,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
706
707
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
707
708
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
708
709
 
709
- >>> getmac-0.9.5
710
+ >>> getmac-0.9.6
710
711
 
711
712
  MIT License
712
713
 
@@ -1364,7 +1365,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1364
1365
  >>> jaraco.context-6.1.2
1365
1366
  >>> jaraco.functools-4.5.0
1366
1367
  >>> keyring-25.7.0
1367
- >>> setuptools-82.0.1
1368
+ >>> setuptools-84.2.1
1368
1369
  >>> zipp-3.21.0
1369
1370
 
1370
1371
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1761,6 +1762,8 @@ one at http://mozilla.org/MPL/2.0/.
1761
1762
 
1762
1763
  =============== SECTION 5. Python License, V2.0 ===============
1763
1764
 
1765
+ >>> base64
1766
+ >>> gzip
1764
1767
  >>> ipaddress-1.0
1765
1768
  >>> json-2.0.9
1766
1769
  >>> logging-0.5.1.2
@@ -13,10 +13,10 @@ except FileNotFoundError:
13
13
 
14
14
  # specify requirements of your package here
15
15
  REQUIREMENTS = [
16
- 'websocket-client==1.9.0',
17
- 'ifaddr==0.2.0',
18
- 'msgpack==1.1.2',
19
- 'getmac==0.9.5'
16
+ 'websocket-client==1.9.2',
17
+ 'ifaddr==0.2.0',
18
+ 'msgpack==1.2.4',
19
+ 'getmac==0.9.6'
20
20
  ]
21
21
 
22
22
  # some more details
@@ -1,4 +0,0 @@
1
- websocket-client==1.9.0
2
- ifaddr==0.2.0
3
- msgpack==1.1.2
4
- getmac==0.9.5