python-terminusgps 29.1.0__py3-none-any.whl → 30.0.0__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 python-terminusgps might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-terminusgps
3
- Version: 29.1.0
3
+ Version: 30.0.0
4
4
  Summary: Provides abstractions/utilities for working with Wialon API, Authorize.NET API, AWS API, and more.
5
5
  Project-URL: Documentation, https://app.terminusgps.com/docs/apps/python-terminusgps/index.html
6
6
  Project-URL: Repository, https://github.com/terminusgps/python-terminusgps
@@ -1,8 +1,7 @@
1
1
  terminusgps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  terminusgps/mixins.py,sha256=jzs_dH_YDmohH86I3uPnN-66C9OPVXaDPVdRHXA6vdk,940
3
3
  terminusgps/settings.py,sha256=vY5yNjyMu-7Ya0bIPWUvrrSLERtxHGdkfeoY4Ul6cP0,613
4
- terminusgps/utils.py,sha256=aMePBExcaNuipdpFiGvbDMmrNKavJh6BNOHcnHyPRS0,120
5
- terminusgps/validators.py,sha256=KxXw8NlN1-h1WN8RkWz_E8XI2imXb7dIQ6hVhhxctIg,3638
4
+ terminusgps/utils.py,sha256=SYDQyHA5tTuVwdpZGsCtf0LpTTD0ilRKoxa8StfSTpQ,156
6
5
  terminusgps/authorizenet/__init__.py,sha256=LiGLlWNNiqS7RSOP4Apabx-b9EBYyNbxRY_a0mvJoaE,466
7
6
  terminusgps/authorizenet/auth.py,sha256=ICxPPzoUc64VbsIIemEWKrn8xjHGwbNdo2VbtaFCFss,1107
8
7
  terminusgps/authorizenet/errors.py,sha256=HG5NwVxQCtOYidVl30y49PC0Ovw5VYdsy9wTgUFMw9M,949
@@ -20,20 +19,21 @@ terminusgps/twilio/__init__.py,sha256=dYo41F2jft_eHDWSUtSpKGSRG1bewq_qClqilUJZkY
20
19
  terminusgps/twilio/caller.py,sha256=TiQ4f0TDDC35he1M1iSsBM2vutdGriwtV4pc17T--6I,3552
21
20
  terminusgps/twilio/validators.py,sha256=nn7CCBTktNjcln6M4MR0ACxEsClgioSu89LRLgIiBZk,1112
22
21
  terminusgps/wialon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- terminusgps/wialon/constants.py,sha256=TgwQjUEQZXXDewepGCVCDIkL6RELI53GouM8qq2RM_M,1805
24
- terminusgps/wialon/flags.py,sha256=O3oeJ5Thhv5ULnoEFNuvvWhqTf8xb6AtIwRci61UyJI,26098
22
+ terminusgps/wialon/constants.py,sha256=5Yj5YflagDaqIYrF2k8QOqyFgmNkXM05647omBTZeDc,5467
23
+ terminusgps/wialon/flags.py,sha256=M50EdhxQ8IMnJnU0mrHK7-h8Asc6tvNiTOOfd1dBW6A,12815
25
24
  terminusgps/wialon/logger.py,sha256=nUBsaLMaffSaAHGHAM6mFXDzix9hbNecVtA3INVtii8,968
26
- terminusgps/wialon/session.py,sha256=THl88yfVBfRH8daKh1lmLSR8ro8TbyOokHx1Cev-En8,9638
27
- terminusgps/wialon/utils.py,sha256=fGl41EItDxqq9JGDKoU50zfELjfab2XjVfIXy5RvRio,6343
25
+ terminusgps/wialon/session.py,sha256=UUPJFwoN4sUnB9Q7i18pjmBaKFt3wdZ1MZdj68ieO_0,9640
26
+ terminusgps/wialon/utils.py,sha256=E_5OCC9wHhrKEwJv4hkTOqplJ_KmnQ5KlSPOhuXbhcg,8423
27
+ terminusgps/wialon/validators.py,sha256=NNqMhoXn1M_f4Edm6oD8I7lzzXKZSqyZ6n7fR3obWj8,4241
28
28
  terminusgps/wialon/items/__init__.py,sha256=3BVthghekMvhMQSzQgBMlD_phxmKSmp3Zvmo-z0O8Bs,211
29
- terminusgps/wialon/items/base.py,sha256=rwKaXd6vcHPNJ2cwBeeX8VYMJiDig_f4hFThAwkhwZk,7247
29
+ terminusgps/wialon/items/base.py,sha256=EmuTVxI7GdlCCJIwFrw0v55gDuYUWNYZ39O2Yl8K2Mc,7876
30
30
  terminusgps/wialon/items/resource.py,sha256=wfUxACO4OdzT2IdCF9oBmU_7nYiH3Xvs6BripPD5IMI,14622
31
31
  terminusgps/wialon/items/retranslator.py,sha256=sVEWrp8q1I-tO_rMTCH7TeQDDbZryIq8d9KVnhYyhH0,3795
32
32
  terminusgps/wialon/items/route.py,sha256=amNPKZqgl8pEzKA_XJudnvBPzEsfHTmrC7uF15sZVI4,1216
33
- terminusgps/wialon/items/unit.py,sha256=0IjfQSnJqVHVDheVA7x_upDjepsvMIFdE2invmtcXgc,9377
33
+ terminusgps/wialon/items/unit.py,sha256=ChONjm3wlFSlbNz-yEXziNbbs4LJ70F9-MI2c-p905k,10638
34
34
  terminusgps/wialon/items/unit_group.py,sha256=QV2ZZgICaN3n6W1pFIyMLyNKB6KYBsLyKG64i-qXoOg,4113
35
35
  terminusgps/wialon/items/user.py,sha256=N30wdejdG7LXrgafdKZH74YArGkX3xpZfTucn3m3aqM,7155
36
- python_terminusgps-29.1.0.dist-info/METADATA,sha256=YXcaiCL5St9dYusJO9VHKgGEQJqJBC-vmfKUyQr4vUw,1061
37
- python_terminusgps-29.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
- python_terminusgps-29.1.0.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
39
- python_terminusgps-29.1.0.dist-info/RECORD,,
36
+ python_terminusgps-30.0.0.dist-info/METADATA,sha256=vXR-HgsmbNNrCtIUUUVdg-piU6D81zbNRMnL3WSg1Rg,1061
37
+ python_terminusgps-30.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
+ python_terminusgps-30.0.0.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
39
+ python_terminusgps-30.0.0.dist-info/RECORD,,
terminusgps/utils.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import numpy as np
2
+ from PIL.Image import Image
2
3
  from pyzbar.pyzbar import decode
3
4
 
4
5
 
5
- def scan_barcode(img: np.ndarray) -> list:
6
+ def scan_barcode(img: np.ndarray | Image) -> list:
6
7
  return decode(img)
@@ -4,54 +4,156 @@ from . import flags
4
4
 
5
5
 
6
6
  class WialonItemsType(enum.StrEnum):
7
+ """
8
+ Wialon item types for Wialon API calls.
9
+
10
+ `Wialon Item Types Reference <https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/search_items>`_
11
+
12
+ """
13
+
7
14
  HARDWARE = "avl_hw"
15
+ """Hardware type."""
8
16
  RESOURCE = "avl_resource"
17
+ """Resource."""
9
18
  RETRANSLATOR = "avl_retranslator"
19
+ """Retranslator."""
10
20
  ROUTE = "avl_route"
21
+ """Route."""
11
22
  UNIT = "avl_unit"
23
+ """Unit."""
12
24
  UNIT_GROUP = "avl_unit_group"
25
+ """Unit group."""
13
26
  USER = "user"
27
+ """User."""
28
+
29
+
30
+ class WialonItemProperty(enum.StrEnum):
31
+ """
32
+ Wialon item properties for Wialon API calls.
33
+
34
+ `Wialon Item Property Reference <https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/search_items>`_
35
+
36
+ """
37
+
38
+ ACCOUNT_BALANCE = "sys_account_balance"
39
+ """Current account balance."""
40
+ ACCOUNT_BLOCKED = "sys_account_disabled"
41
+ """Whether or not the account is blocked."""
42
+ ACCOUNT_BLOCKED_TIME = "rel_account_disabled_mod_time"
43
+ """Time (UNIX timestamp) the account was last blocked."""
44
+ ACCOUNT_DAYS = "sys_account_days"
45
+ """Number of days on the account."""
46
+ ACCOUNT_DEALER_RIGHTS = "sys_account_enable_parent"
47
+ """Whether or not the account has dealer rights."""
48
+ ACCOUNT_ID = "sys_billing_account_guid"
49
+ """Account id."""
50
+ ACCOUNT_NAME = "rel_billing_account_name"
51
+ """Account name."""
52
+ ACCOUNT_NUM_UNITS = "rel_account_units_usage"
53
+ """Number of units in the account."""
54
+ ACCOUNT_PARENT_NAME = "rel_billing_parent_account_name"
55
+ """Parent account name for the account."""
56
+ ACCOUNT_PLAN_NAME = "rel_billing_plan_name"
57
+ """Billing plan assigned to the account."""
58
+ ADMIN_FIELD_NAME = "rel_adminfield_name"
59
+ """Admin field name."""
60
+ ADMIN_FIELD_NAME_VALUE = "rel_adminfield_name_value"
61
+ """Admin field name/value, format: ``'name:value'``."""
62
+ ADMIN_FIELD_VALUE = "rel_adminfield_value"
63
+ """Admin field value."""
64
+ CREATION_TIME = "rel_creation_time"
65
+ """Time (UNIX timestamp) the object was created."""
66
+ CREATOR_ID = "sys_user_creator"
67
+ """Creator user id."""
68
+ CREATOR_NAME = "rel_user_creator_name"
69
+ """Creator user name."""
70
+ CUSTOM_FIELD_NAME = "rel_customfield_name"
71
+ """Custom field name."""
72
+ CUSTOM_FIELD_NAME_VALUE = "rel_customfield_name_value"
73
+ """Custom field name/value, format: ``'name:value'``."""
74
+ CUSTOM_FIELD_VALUE = "rel_customfield_value"
75
+ """Custom field value."""
76
+ GROUP_NUM_UNITS = "rel_group_unit_count"
77
+ """Number of units in the group."""
78
+ HARDWARE_ID = "rel_hw_type_id"
79
+ """Hardware id."""
80
+ HARDWARE_NAME = "rel_hw_type_name"
81
+ """Hardware name."""
82
+ HARDWARE_STATE = "sys_comm_state"
83
+ """Hardware state."""
84
+ ID = "sys_id"
85
+ """Object id."""
86
+ LAST_LOGIN_TIME = "login_date"
87
+ """Time (UNIX timestamp) the user last logged in."""
88
+ LAST_MESSAGE_TIME = "rel_last_msg_date"
89
+ """Time (UNIX timestamp) of the last message."""
90
+ NAME = "sys_name"
91
+ """Object name."""
92
+ PHONE = "sys_phone_number"
93
+ """Object phone number."""
94
+ PHONE2 = "sys_phone_number2"
95
+ """Secondary (optional) object phone number."""
96
+ PROFILE_FIELD = "profilefield"
97
+ """Profile field."""
98
+ PROFILE_FIELD_NAME = "rel_profilefield_name"
99
+ """Profile field name."""
100
+ PROFILE_FIELD_NAME_VALUE = "rel_profilefield_name_value"
101
+ """Profile field name/value, format: ``'name:value'``"""
102
+ PROFILE_FIELD_VALUE = "rel_profilefield_value"
103
+ """Profile field value."""
104
+ RESOURCE_IS_ACCOUNT = "rel_is_account"
105
+ """Whether or not the resource is an account."""
106
+ RETRANSLATOR_ENABLED = "retranslator_enabled"
107
+ """Whether or not a retranslator is enabled."""
108
+ UNIQUE_ID = "sys_unique_id"
109
+ """Object unique id."""
14
110
 
15
111
 
16
- ACCESSMASK_RESOURCE_BASIC: int = (
17
- flags.AccessFlag.VIEW_ITEM_BASIC
18
- | flags.AccessFlag.VIEW_CUSTOM_FIELDS
19
- | flags.AccessFlag.MANAGE_CUSTOM_FIELDS
20
- | flags.AccessFlag.VIEW_ADMIN_FIELDS
21
- | flags.AccessFlag.RESOURCE_VIEW_NOTIFICATIONS
22
- | flags.AccessFlag.RESOURCE_MANAGE_NOTIFICATIONS
23
- | flags.AccessFlag.RESOURCE_VIEW_POIS
24
- | flags.AccessFlag.RESOURCE_VIEW_GEOFENCES
25
- | flags.AccessFlag.RESOURCE_MANAGE_GEOFENCES
26
- | flags.AccessFlag.RESOURCE_VIEW_DRIVERS
27
- | flags.AccessFlag.RESOURCE_MANAGE_DRIVERS
28
- | flags.AccessFlag.RESOURCE_VIEW_ORDERS
29
- | flags.AccessFlag.RESOURCE_VIEW_TRAILERS
112
+ ACCESSMASK_RESOURCE_BASIC: int = sum(
113
+ [
114
+ flags.AccessFlag.MANAGE_CUSTOM_FIELDS,
115
+ flags.AccessFlag.RESOURCE_MANAGE_DRIVERS,
116
+ flags.AccessFlag.RESOURCE_MANAGE_GEOFENCES,
117
+ flags.AccessFlag.RESOURCE_MANAGE_NOTIFICATIONS,
118
+ flags.AccessFlag.RESOURCE_VIEW_DRIVERS,
119
+ flags.AccessFlag.RESOURCE_VIEW_GEOFENCES,
120
+ flags.AccessFlag.RESOURCE_VIEW_NOTIFICATIONS,
121
+ flags.AccessFlag.RESOURCE_VIEW_ORDERS,
122
+ flags.AccessFlag.RESOURCE_VIEW_POIS,
123
+ flags.AccessFlag.RESOURCE_VIEW_TRAILERS,
124
+ flags.AccessFlag.VIEW_ADMIN_FIELDS,
125
+ flags.AccessFlag.VIEW_CUSTOM_FIELDS,
126
+ flags.AccessFlag.VIEW_ITEM_BASIC,
127
+ ]
30
128
  )
31
129
  """Basic resource permissions"""
32
130
 
33
- ACCESSMASK_UNIT_BASIC: int = (
34
- flags.AccessFlag.VIEW_ITEM_BASIC
35
- | flags.AccessFlag.VIEW_ITEM_DETAILED
36
- | flags.AccessFlag.RENAME_ITEM
37
- | flags.AccessFlag.VIEW_CUSTOM_FIELDS
38
- | flags.AccessFlag.MANAGE_CUSTOM_FIELDS
39
- | flags.AccessFlag.MANAGE_ICON
40
- | flags.AccessFlag.QUERY_REPORTS
41
- | flags.AccessFlag.VIEW_ATTACHED_FILES
42
- | flags.AccessFlag.UNIT_EXECUTE_COMMANDS
43
- | flags.AccessFlag.UNIT_VIEW_SERVICE_INTERVALS
44
- | flags.AccessFlag.UNIT_REGISTER_EVENTS
45
- | flags.AccessFlag.UNIT_IMPORT_MESSAGES
46
- | flags.AccessFlag.UNIT_EXPORT_MESSAGES
131
+ ACCESSMASK_UNIT_BASIC: int = sum(
132
+ [
133
+ flags.AccessFlag.MANAGE_CUSTOM_FIELDS,
134
+ flags.AccessFlag.MANAGE_ICON,
135
+ flags.AccessFlag.QUERY_REPORTS,
136
+ flags.AccessFlag.RENAME_ITEM,
137
+ flags.AccessFlag.UNIT_EXECUTE_COMMANDS,
138
+ flags.AccessFlag.UNIT_EXPORT_MESSAGES,
139
+ flags.AccessFlag.UNIT_IMPORT_MESSAGES,
140
+ flags.AccessFlag.UNIT_REGISTER_EVENTS,
141
+ flags.AccessFlag.UNIT_VIEW_SERVICE_INTERVALS,
142
+ flags.AccessFlag.VIEW_ATTACHED_FILES,
143
+ flags.AccessFlag.VIEW_CUSTOM_FIELDS,
144
+ flags.AccessFlag.VIEW_ITEM_BASIC,
145
+ flags.AccessFlag.VIEW_ITEM_DETAILED,
146
+ ]
47
147
  )
48
148
  """Basic unit permissions"""
49
149
 
50
- ACCESSMASK_UNIT_MIGRATION: int = (
51
- flags.AccessFlag.DELETE_ITEM
52
- | flags.AccessFlag.MANAGE_ITEM_ACCESS
53
- | flags.AccessFlag.UNIT_DELETE_MESSAGES
54
- | flags.AccessFlag.UNIT_MANAGE_CONNECTIVITY
55
- | flags.AccessFlag.VIEW_ITEM_BASIC
150
+ ACCESSMASK_UNIT_MIGRATION: int = sum(
151
+ [
152
+ flags.AccessFlag.DELETE_ITEM,
153
+ flags.AccessFlag.MANAGE_ITEM_ACCESS,
154
+ flags.AccessFlag.UNIT_DELETE_MESSAGES,
155
+ flags.AccessFlag.UNIT_MANAGE_CONNECTIVITY,
156
+ flags.AccessFlag.VIEW_ITEM_BASIC,
157
+ ]
56
158
  )
57
159
  """Unit migration permissions"""
@@ -1,7 +1,14 @@
1
1
  import enum
2
2
 
3
3
 
4
- class AccessFlag(enum.Flag):
4
+ class AccessFlag(enum.IntFlag):
5
+ """
6
+ Access flags for Wialon API calls.
7
+
8
+ `Access Flags Reference <https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing>`_
9
+
10
+ """
11
+
5
12
  VIEW_ITEM_BASIC = 0x0001
6
13
  """View this item's basic properties"""
7
14
  VIEW_ITEM_DETAILED = 0x0002
@@ -118,7 +125,14 @@ class AccessFlag(enum.Flag):
118
125
  """Sets all possible access flags to an item"""
119
126
 
120
127
 
121
- class DataFlag(enum.Flag):
128
+ class DataFlag(enum.IntFlag):
129
+ """
130
+ Data flags for Wialon API calls.
131
+
132
+ `Data Flags Reference <https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/format>`_
133
+
134
+ """
135
+
122
136
  RESOURCE_BASE = 0x00000001
123
137
  """This resource's basic properties"""
124
138
  RESOURCE_CUSTOM_PROPERTIES = 0x00000002
@@ -283,7 +297,14 @@ class DataFlag(enum.Flag):
283
297
  """All possible user data flags"""
284
298
 
285
299
 
286
- class SettingsFlag(enum.Flag):
300
+ class SettingsFlag(enum.IntFlag):
301
+ """
302
+ User settings flags for Wialon API calls.
303
+
304
+ `User Settings Flags Reference <https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/user/update_user_flags>`_
305
+
306
+ """
307
+
287
308
  USER_DISABLED = 0x01
288
309
  """This user is disabled"""
289
310
  USER_CANNOT_CHANGE_PASSWORD = 0x02
@@ -296,7 +317,14 @@ class SettingsFlag(enum.Flag):
296
317
  """This user can send SMS messages"""
297
318
 
298
319
 
299
- class TokenFlag(enum.Flag):
320
+ class TokenFlag(enum.IntFlag):
321
+ """
322
+ Token flags for Wialon API calls.
323
+
324
+ `Token Flags Reference <https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/token/login>`_
325
+
326
+ """
327
+
300
328
  ONLINE_TRACKING = 0x100
301
329
  """Online tracking"""
302
330
  VIEW_ACCESS = 0x200
@@ -311,487 +339,3 @@ class TokenFlag(enum.Flag):
311
339
  """Modification of communication data"""
312
340
  MANAGE_ALL = -1
313
341
  """Unlimited operation as authorized user"""
314
-
315
-
316
- # Access flags
317
- ## General - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing#general
318
- ACCESSFLAG_VIEW_ITEM_BASIC = 0x0001
319
- """View this item's basic properties"""
320
-
321
- ACCESSFLAG_VIEW_ITEM_DETAILED = 0x0002
322
- """View this item's detailed properties"""
323
-
324
- ACCESSFLAG_MANAGE_ITEM_ACCESS = 0x0004
325
- """Manage access to this item"""
326
-
327
- ACCESSFLAG_DELETE_ITEM = 0x0008
328
- """Delete this item"""
329
-
330
- ACCESSFLAG_RENAME_ITEM = 0x0010
331
- """Rename this item"""
332
-
333
- ACCESSFLAG_VIEW_CUSTOM_FIELDS = 0x0020
334
- """View this item's custom fields"""
335
-
336
- ACCESSFLAG_MANAGE_CUSTOM_FIELDS = 0x0040
337
- """Manage this item's custom fields"""
338
-
339
- ACCESSFLAG_MANAGE_UNMENTIONED_FIELDS = 0x0080
340
- """Manage this item's unmentioned properties"""
341
-
342
- ACCESSFLAG_MANAGE_ICON = 0x0100
343
- """Manage this item's icon"""
344
-
345
- ACCESSFLAG_QUERY_REPORTS = 0x0200
346
- """Query this item's reports or messages"""
347
-
348
- ACCESSFLAG_MANAGE_ACL = 0x0400
349
- """Manage this item's ACL propagated objects"""
350
-
351
- ACCESSFLAG_MANAGE_ITEM_LOG = 0x0800
352
- """Manage this item's log"""
353
-
354
- ACCESSFLAG_VIEW_ADMIN_FIELDS = 0x1000
355
- """View this item's administrative fields"""
356
-
357
- ACCESSFLAG_MANAGE_ADMIN_FIELDS = 0x2000
358
- """Manage this item's administrative fields"""
359
-
360
- ACCESSFLAG_VIEW_ATTACHED_FILES = 0x4000
361
- """View this item's attached files"""
362
-
363
- ACCESSFLAG_MANAGE_ATTACHED_FILES = 0x8000
364
- """Manage this item's attached files"""
365
-
366
-
367
- ## Unit/Unit Group - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing#units_and_unit_groups
368
- ACCESSFLAG_UNIT_MANAGE_CONNECTIVITY = 0x0000100000
369
- """Manage this unit/group's connectivity settings"""
370
-
371
- ACCESSFLAG_UNIT_MANAGE_SENSORS = 0x0000200000
372
- """Manage this unit/group's sensors"""
373
-
374
- ACCESSFLAG_UNIT_MANAGE_COUNTERS = 0x0000400000
375
- """Manage this unit/group's counters"""
376
-
377
- ACCESSFLAG_UNIT_DELETE_MESSAGES = 0x0000800000
378
- """Delete this unit/group's messages"""
379
-
380
- ACCESSFLAG_UNIT_EXECUTE_COMMANDS = 0x0001000000
381
- """Execute this unit/group's commands"""
382
-
383
- ACCESSFLAG_UNIT_REGISTER_EVENTS = 0x0002000000
384
- """Register this unit/group's events"""
385
-
386
- ACCESSFLAG_UNIT_VIEW_CONNECTIVITY = 0x0004000000
387
- """View this unit/group's connectivity settings"""
388
-
389
- ACCESSFLAG_UNIT_VIEW_SERVICE_INTERVALS = 0x0010000000
390
- """View this unit/group's service intervals"""
391
-
392
- ACCESSFLAG_UNIT_MANAGE_SERVICE_INTERVALS = 0x0020000000
393
- """Manage this unit/group's service intervals"""
394
-
395
- ACCESSFLAG_UNIT_IMPORT_MESSAGES = 0x0040000000
396
- """Import this unit/group's messages"""
397
-
398
- ACCESSFLAG_UNIT_EXPORT_MESSAGES = 0x0080000000
399
- """Export this unit/group's messages"""
400
-
401
- ACCESSFLAG_UNIT_VIEW_COMMANDS = 0x0400000000
402
- """View this unit/group's commands"""
403
-
404
- ACCESSFLAG_UNIT_MANAGE_COMMANDS = 0x0800000000
405
- """Manage this unit/group's commands"""
406
-
407
- ACCESSFLAG_UNIT_MANAGE_TRIP_DETECTOR = 0x4000000000
408
- """Manage this unit/group's trip detector and fuel consumption"""
409
-
410
- ACCESSFLAG_UNIT_MANAGE_ASSIGNMENTS = 0x8000000000
411
- """Manage this unit/group's job, notification, route, and retranslator assignments"""
412
-
413
-
414
- ## User - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing#users
415
- ACCESSFLAG_USER_MANAGE_ACCESS_RIGHTS = 0x100000
416
- """Manage this user's access rights"""
417
-
418
- ACCESSFLAG_USER_ACT_AS_OTHER = 0x200000
419
- """Can assume the identity of this user (login as)"""
420
-
421
- ACCESSFLAG_USER_MANAGE_FLAGS = 0x400000
422
- """Manage this user's access flags"""
423
-
424
- ACCESSFLAG_USER_VIEW_PUSH_MESSAGES = 0x800000
425
- """View this user's push messages"""
426
-
427
- ACCESSFLAG_USER_MANAGE_PUSH_MESSAGES = 0x1000000
428
- """Manage this user's push messages"""
429
-
430
-
431
- ## Retranslator - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing#retranslators
432
- ACCESSFLAG_RETRANSLATOR_MANAGE_PROPERTIES = 0x100000
433
- """Manage this retranslator's properties (including start/stop)"""
434
-
435
- ACCESSFLAG_RETRANSLATOR_MANAGE_UNITS = 0x2000000
436
- """Manage this retranslator's available units"""
437
-
438
-
439
- ## Resources (Accounts) - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing#resources_accounts
440
- ACCESSFLAG_RESOURCE_VIEW_NOTIFICATIONS = 0x0000000100000
441
- """View this resource's notifications"""
442
-
443
- ACCESSFLAG_RESOURCE_MANAGE_NOTIFICATIONS = 0x0000000200000
444
- """Manage this resource's notifications"""
445
-
446
- ACCESSFLAG_RESOURCE_VIEW_POIS = 0x0000000400000
447
- """View this resource's points of interest"""
448
-
449
- ACCESSFLAG_RESOURCE_MANAGE_POIS = 0x0000000800000
450
- """Manage this resource's points of interest"""
451
-
452
- ACCESSFLAG_RESOURCE_VIEW_GEOFENCES = 0x0000001000000
453
- """View this resource's geofences"""
454
-
455
- ACCESSFLAG_RESOURCE_MANAGE_GEOFENCES = 0x0000002000000
456
- """Manage this resource's geofences"""
457
-
458
- ACCESSFLAG_RESOURCE_VIEW_JOBS = 0x0000004000000
459
- """View this resource's jobs"""
460
-
461
- ACCESSFLAG_RESOURCE_MANAGE_JOBS = 0x0000008000000
462
- """Manage this resource's jobs"""
463
-
464
- ACCESSFLAG_RESOURCE_VIEW_REPORT_TEMPLATES = 0x0000010000000
465
- """View this resource's report templates"""
466
-
467
- ACCESSFLAG_RESOURCE_MANAGE_REPORT_TEMPLATES = 0x0000020000000
468
- """Manage this resource's report templates"""
469
-
470
- ACCESSFLAG_RESOURCE_VIEW_DRIVERS = 0x0000040000000
471
- """View this resource's drivers"""
472
-
473
- ACCESSFLAG_RESOURCE_MANAGE_DRIVERS = 0x0000080000000
474
- """Manage this resource's drivers"""
475
-
476
- ACCESSFLAG_RESOURCE_MANAGE_ACCOUNT = 0x0000100000000
477
- """Manage this resource's account"""
478
-
479
- ACCESSFLAG_RESOURCE_VIEW_ORDERS = 0x0000200000000
480
- """View this resource's orders"""
481
-
482
- ACCESSFLAG_RESOURCE_MANAGE_ORDERS = 0x0000400000000
483
- """Manage this resource's orders"""
484
-
485
- ACCESSFLAG_RESOURCE_VIEW_TRAILERS = 0x0100000000000
486
- """View this resource's trailers"""
487
-
488
- ACCESSFLAG_RESOURCE_MANAGE_TRAILERS = 0x0200000000000
489
- """Manage this resource's trailers"""
490
-
491
-
492
- ## Routes - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing#routes
493
- ACCESSFLAG_ROUTE_MANAGE_ROUTE = 0x0000000100000
494
- """Manage this route's properties"""
495
-
496
-
497
- ## Other - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/core/check_items_billing#other
498
- ACCESSFLAG_FULL_ACCESS = 0xFFFFFFFFFFFFFFF
499
- """Sets all possible access flags to an item"""
500
-
501
-
502
- # Data flags
503
- ## Resource (Accounts) - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/resource
504
- DATAFLAG_RESOURCE_BASE = 0x00000001
505
- """This resource's basic properties"""
506
-
507
- DATAFLAG_RESOURCE_CUSTOM_PROPERTIES = 0x00000002
508
- """This resource's custom properties"""
509
-
510
- DATAFLAG_RESOURCE_BILLING_PROPERTIES = 0x00000004
511
- """This resource's billing properties"""
512
-
513
- DATAFLAG_RESOURCE_CUSTOM_FIELDS = 0x00000008
514
- """This resource's custom fields"""
515
-
516
- DATAFLAG_RESOURCE_MESSAGES = 0x00000020
517
- """This resource's messages"""
518
-
519
- DATAFLAG_RESOURCE_GUID = 0x00000040
520
- """This resource's GUID"""
521
-
522
- DATAFLAG_RESOURCE_ADMIN_FIELDS = 0x00000080
523
- """This resources administrative fields"""
524
-
525
- DATAFLAG_RESOURCE_DRIVERS = 0x00000100
526
- """This resource's drivers"""
527
-
528
- DATAFLAG_RESOURCE_JOBS = 0x00000200
529
- """This resource's jobs"""
530
-
531
- DATAFLAG_RESOURCE_NOTIFICATIONS = 0x00000400
532
- """This resource's notifications"""
533
-
534
- DATAFLAG_RESOURCE_POIS = 0x00000800
535
- """This resouce's points of interest"""
536
-
537
- DATAFLAG_RESOURCE_GEOFENCES = 0x00001000
538
- """This resource's geofences"""
539
-
540
- DATAFLAG_RESOURCE_REPORT_TEMPLATES = 0x00002000
541
- """This resource's report templates"""
542
-
543
- DATAFLAG_RESOURCE_DRIVER_ATTACHABLE_UNITS = 0x00004000
544
- """This resource's units allowed for driver attachment"""
545
-
546
- DATAFLAG_RESOURCE_DRIVER_GROUPS = 0x00008000
547
- """This resource's driver groups"""
548
-
549
- DATAFLAG_RESOURCE_TRAILERS = 0x00010000
550
- """This resource's trailers"""
551
-
552
- DATAFLAG_RESOURCE_TRAILER_GROUPS = 0x00020000
553
- """This resource's trailer groups"""
554
-
555
- DATAFLAG_RESOURCE_TRAILER_ATTACHABLE_UNITS = 0x00040000
556
- """This resource's units allowed for trailer attachment"""
557
-
558
- DATAFLAG_RESOURCE_ORDERS = 0x00080000
559
- """This resource's orders"""
560
-
561
- DATAFLAG_RESOURCE_GEOFENCE_GROUPS = 0x00100000
562
- """This resource's geofence groups"""
563
-
564
- DATAFLAG_RESOURCE_TAGS = 0x00200000
565
- """This resource's tags (passengers)"""
566
-
567
- DATAFLAG_RESOURCE_TAG_ATTACHABLE_UNITS = 0x00400000
568
- """This resource's units allowed for tag attachment"""
569
-
570
- DATAFLAG_RESOURCE_TAG_GROUPS = 0x00800000
571
- """This resource's tag groups (passengers)"""
572
-
573
- DATAFLAG_RESOURCE_ALL = 4611686018427387903
574
- """All possible resource data flags"""
575
-
576
-
577
- ## Retranslator - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/retranslator
578
- DATAFLAG_RETRANSLATOR_BASE = 0x00000001
579
- """This retranslator's basic properties"""
580
-
581
- DATAFLAG_RETRANSLATOR_CUSTOM_PROPERTIES = 0x00000002
582
- """This retranslator's custom properties"""
583
-
584
- DATAFLAG_RETRANSLATOR_BILLING_PROPERTIES = 0x00000004
585
- """This retranslator's billing properties"""
586
-
587
- DATAFLAG_RETRANSLATOR_GUID = 0x00000040
588
- """This retranslator's GUID"""
589
-
590
- DATAFLAG_RETRANSLATOR_ADMIN_FIELDS = 0x00000080
591
- """This retranslator's admin fields"""
592
-
593
- DATAFLAG_RETRANSLATOR_CONFIGURATION = 0x00000100
594
- """This retranslator's state and configuration"""
595
-
596
- DATAFLAG_RETRANSLATOR_UNITS = 0x00000200
597
- """This retranslator's bound units"""
598
-
599
- DATAFLAG_RETRANSLATOR_ALL = 4611686018427387903
600
- """All possible retranslator data flags"""
601
-
602
-
603
- ## Route - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/route
604
- DATAFLAG_ROUTE_BASE = 0x00000001
605
- """This route's basic properties"""
606
-
607
- DATAFLAG_ROUTE_CUSTOM_PROPERTIES = 0x00000002
608
- """This route's custom properties"""
609
-
610
- DATAFLAG_ROUTE_BILLING_PROPERTIES = 0x00000004
611
- """This route's billing properties"""
612
-
613
- DATAFLAG_ROUTE_GUID = 0x00000040
614
- """This route's GUID"""
615
-
616
- DATAFLAG_ROUTE_ADMIN_FIELDS = 0x00000080
617
- """This route's administrative fields"""
618
-
619
- DATAFLAG_ROUTE_CONFIGURATION = 0x00000100
620
- """This route's configuration"""
621
-
622
- DATAFLAG_ROUTE_CHECKPOINTS = 0x00000200
623
- """This route's checkpoints"""
624
-
625
- DATAFLAG_ROUTE_SCHEDULES = 0x00000400
626
- """This route's schedules"""
627
-
628
- DATAFLAG_ROUTE_ROUNDS = 0x00000800
629
- """This route's rounds"""
630
-
631
- DATAFLAG_ROUTE_ALL = 4611686018427387903
632
- """All possible route data flags"""
633
-
634
-
635
- ## Unit - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/unit
636
- DATAFLAG_UNIT_BASE = 0x00000001
637
- """This unit's basic properties"""
638
-
639
- DATAFLAG_UNIT_CUSTOM_PROPERTIES = 0x00000002
640
- """This unit's custom properties"""
641
-
642
- DATAFLAG_UNIT_BILLING_PROPERTIES = 0x00000004
643
- """This unit's billing properties"""
644
-
645
- DATAFLAG_UNIT_CUSTOM_FIELDS = 0x00000008
646
- """This unit's custom fields"""
647
-
648
- DATAFLAG_UNIT_IMAGE = 0x00000010
649
- """This unit's image/icon"""
650
-
651
- DATAFLAG_UNIT_MESSAGES = 0x00000020
652
- """This unit's messages"""
653
-
654
- DATAFLAG_UNIT_GUID = 0x00000040
655
- """This unit's GUID"""
656
-
657
- DATAFLAG_UNIT_ADMIN_FIELDS = 0x00000080
658
- """This unit's administrative fields"""
659
-
660
- DATAFLAG_UNIT_ADVANCED_PROPERTIES = 0x00000100
661
- """This unit's advanced properties"""
662
-
663
- DATAFLAG_UNIT_CURRENT_MOMENT_COMMANDS = 0x00000200
664
- """This unit's available for current moment commands"""
665
-
666
- DATAFLAG_UNIT_LAST_MESSAGE = 0x00000400
667
- """This unit's last message and position"""
668
-
669
- DATAFLAG_UNIT_SENSORS = 0x00001000
670
- """This unit's sensors"""
671
-
672
- DATAFLAG_UNIT_COUNTERS = 0x00002000
673
- """This unit's counters"""
674
-
675
- DATAFLAG_UNIT_MAINTENANCE = 0x00008000
676
- """This unit's maintenance"""
677
-
678
- DATAFLAG_UNIT_REPORT_CONFIGURATION = 0x00020000
679
- """This unit's report configuration, trip detector, and fuel consumption"""
680
-
681
- DATAFLAG_UNIT_AVAILABLE_COMMANDS = 0x00080000
682
- """This unit's available commands"""
683
-
684
- DATAFLAG_UNIT_MESSAGE_PARAMETERS = 0x00100000
685
- """This unit's message parameters"""
686
-
687
- DATAFLAG_UNIT_CONNECTION_STATUS = 0x00200000
688
- """This unit's connection status"""
689
-
690
- DATAFLAG_UNIT_POSITION = 0x00400000
691
- """This unit's position"""
692
-
693
- DATAFLAG_UNIT_PROFILE_FIELDS = 0x00800000
694
- """This unit's profile files"""
695
-
696
- DATAFLAG_UNIT_ALL = 4611686018427387903
697
- """All possible unit data flags"""
698
-
699
-
700
- ## Unit Groups - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/group
701
- DATAFLAG_GROUP_BASE = 0x00000001
702
- """This group's basic properties"""
703
-
704
- DATAFLAG_GROUP_CUSTOM_PROPERTIES = 0x00000002
705
- """This group's custom properties"""
706
-
707
- DATAFLAG_GROUP_BILLING_PROPERTIES = 0x00000004
708
- """This group's billing properties"""
709
-
710
- DATAFLAG_GROUP_CUSTOM_FIELDS = 0x00000008
711
- """This group's custom fields"""
712
-
713
- DATAFLAG_GROUP_IMAGE = 0x00000010
714
- """This group's image/icon"""
715
-
716
- DATAFLAG_GROUP_GUID = 0x00000040
717
- """This group's GUID"""
718
-
719
- DATAFLAG_GROUP_ADMIN_FIELDS = 0x00000080
720
- """This group's administrative fields"""
721
-
722
- DATAFLAG_GROUP_ALL = 4611686018427387903
723
- """All possible group data flags"""
724
-
725
-
726
- ## User - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/user
727
- DATAFLAG_USER_BASE = 0x00000001
728
- """This user's basic properties"""
729
-
730
- DATAFLAG_USER_CUSTOM_PROPERTIES = 0x00000002
731
- """This user's custom properties"""
732
-
733
- DATAFLAG_USER_BILLING_PROPERTIES = 0x00000004
734
- """This user's billing properties"""
735
-
736
- DATAFLAG_USER_CUSTOM_FIELDS = 0x00000008
737
- """This user's custom fields"""
738
-
739
- DATAFLAG_USER_MESSAGES = 0x00000020
740
- """This user's messages"""
741
-
742
- DATAFLAG_USER_GUID = 0x00000040
743
- """This user's GUID"""
744
-
745
- DATAFLAG_USER_ADMIN_FIELDS = 0x00000080
746
- """This user's administrative fields"""
747
-
748
- DATAFLAG_USER_OTHER_PROPERTIES = 0x00000100
749
- """This user's other properties"""
750
-
751
- DATAFLAG_USER_NOTIFICATIONS = 0x00000200
752
- """This user's notifications"""
753
-
754
- DATAFLAG_USER_ALL = 4611686018427387903
755
- """All possible user data flags"""
756
-
757
-
758
- # Settings flags
759
- ## User - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/user/update_user_flags
760
- SETTINGSFLAG_USER_DISABLED = 0x01
761
- """This user is disabled"""
762
-
763
- SETTINGSFLAG_USER_CANNOT_CHANGE_PASSWORD = 0x02
764
- """This user cannot change their password"""
765
-
766
- SETTINGSFLAG_USER_CAN_CREATE_ITEMS = 0x04
767
- """This user can create objects"""
768
-
769
- SETTINGSFLAG_USER_CANNOT_CHANGE_SETTINGS = 0x10
770
- """This user cannot change settings"""
771
-
772
- SETTINGSFLAG_USER_CAN_SEND_SMS = 0x20
773
- """This user can send SMS messages"""
774
-
775
-
776
- # Token flags
777
- ## General - https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/format/token
778
- TOKENFLAG_ONLINE_TRACKING = 0x100
779
- """Online tracking"""
780
-
781
- TOKENFLAG_VIEW_ACCESS = 0x200
782
- """View access to most data"""
783
-
784
- TOKENFLAG_MANAGE_NONSENSITIVE = 0x400
785
- """Modification of non-sensitive data"""
786
-
787
- TOKENFLAG_MANAGE_SENSITIVE = 0x800
788
- """Modification of sensitive data"""
789
-
790
- TOKENFLAG_MANAGE_CRITICAL = 0x1000
791
- """Modification of critical data, including message deletion"""
792
-
793
- TOKENFLAG_COMMUNICATION = 0x2000
794
- """Modification of communication data"""
795
-
796
- TOKENFLAG_MANAGE_ALL = -1
797
- """Unlimited operation as authorized user"""
@@ -14,7 +14,9 @@ class WialonBase:
14
14
 
15
15
  self._session = session
16
16
  self._id = str(id if id else self.create(*args, **kwargs))
17
- self.populate()
17
+ self._name = None
18
+ self._hw_type = None
19
+ self._access_lvl = None
18
20
 
19
21
  def __str__(self) -> str:
20
22
  return str(self.id)
@@ -26,9 +28,30 @@ class WialonBase:
26
28
  )
27
29
  if response is not None:
28
30
  item = response.get("item", {})
29
- self.name = item.get("nm")
30
- self.hw_type = item.get("cls")
31
- self.access_lvl = item.get("uacl")
31
+ self._name = item.get("nm")
32
+ self._hw_type = item.get("cls")
33
+ self._access_lvl = item.get("uacl")
34
+
35
+ @property
36
+ def name(self) -> str:
37
+ """Name of the Wialon object."""
38
+ if self._name is None:
39
+ self.populate()
40
+ return str(self._name)
41
+
42
+ @property
43
+ def hw_type(self) -> str:
44
+ """Hardware type of the Wialon object."""
45
+ if self._hw_type is None:
46
+ self.populate()
47
+ return str(self._hw_type)
48
+
49
+ @property
50
+ def access_lvl(self) -> str:
51
+ """Access level of the Wialon object."""
52
+ if self._access_lvl is None:
53
+ self.populate()
54
+ return str(self._access_lvl)
32
55
 
33
56
  @property
34
57
  def session(self) -> WialonSession:
@@ -1,10 +1,18 @@
1
- from urllib.parse import quote_plus
1
+ from urllib.parse import quote_plus, urljoin
2
+
3
+ from django.conf import settings
2
4
 
3
5
  from terminusgps.wialon import flags
4
6
  from terminusgps.wialon.items.base import WialonBase
5
7
 
6
8
 
7
9
  class WialonUnit(WialonBase):
10
+ def __init__(self, *args, **kwargs) -> None:
11
+ super().__init__(*args, **kwargs)
12
+ self._imei_number = None
13
+ self._active = None
14
+ self._image_uri = None
15
+
8
16
  def create(
9
17
  self, creator_id: str | int, name: str, hw_type_id: str | int
10
18
  ) -> int | None:
@@ -48,11 +56,13 @@ class WialonUnit(WialonBase):
48
56
  **{
49
57
  "id": self.id,
50
58
  "flags": (
51
- flags.DataFlag.UNIT_ADVANCED_PROPERTIES | flags.DataFlag.UNIT_IMAGE
59
+ flags.DataFlag.UNIT_ADVANCED_PROPERTIES
60
+ | flags.DataFlag.UNIT_IMAGE
61
+ | flags.DataFlag.UNIT_ADMIN_FIELDS
52
62
  ).value,
53
63
  }
54
64
  )
55
- if response:
65
+ if response is not None:
56
66
  item = response.get("item", {})
57
67
  self._imei_number = item.get("uid")
58
68
  self._active = item.get("act", False)
@@ -79,28 +89,72 @@ class WialonUnit(WialonBase):
79
89
 
80
90
  @property
81
91
  def available_commands(self) -> dict:
82
- """Assigned commands to the unit."""
92
+ """
93
+ Commands assigned to the unit.
94
+
95
+ :type: :py:obj:`dict`
96
+
97
+ """
83
98
  return self.session.wialon_api.core_get_hw_cmds(
84
99
  **{"deviceTypeId": 0, "unitId": self.id}
85
100
  )
86
101
 
87
102
  @property
88
103
  def image_uri(self) -> str:
89
- """An image URI for the unit."""
90
- return self._image_uri
104
+ """
105
+ Image URI for the unit.
106
+
107
+ :type :py:obj:`str`
108
+
109
+ """
110
+ if self._image_uri is None:
111
+ self.populate()
112
+ return str(self._image_uri)
91
113
 
92
114
  @property
93
- def imei_number(self) -> int | None:
94
- """The unit's IMEI number."""
95
- if self._imei_number:
96
- return int(self._imei_number)
115
+ def imei_number(self) -> str:
116
+ """
117
+ IMEI # for the unit.
118
+
119
+ :type: :py:obj:`str`
120
+
121
+ """
122
+ if self._imei_number is None:
123
+ self.populate()
124
+ return str(self._imei_number)
125
+
126
+ @property
127
+ def iccid(self) -> str | None:
128
+ """
129
+ SIM Card # for the unit, if any.
130
+
131
+ :type: :py:obj:`str` | :py:obj:`None`
132
+
133
+ """
134
+ return self.afields.get("iccid")
135
+
136
+ @property
137
+ def carrier(self) -> str | None:
138
+ """
139
+ Name of the telecommunications company associated with the unit's SIM card, if any.
140
+
141
+ :type: :py:obj:`str` | :py:obj:`None`
142
+
143
+ """
144
+ return self.afields.get("carrier")
97
145
 
98
146
  @property
99
147
  def active(self) -> bool:
100
- """Whether or not the unit is active."""
101
- if self._active:
102
- return bool(self._active)
103
- return False
148
+ """Whether or not the unit is activated."""
149
+ if self._active is None:
150
+ self.populate()
151
+ return bool(self._active)
152
+
153
+ @property
154
+ def image_url(self) -> str | None:
155
+ if hasattr(settings, "WIALON_HOST"):
156
+ return urljoin(settings.WIALON_HOST, self._image_uri)
157
+ return urljoin("https://hst-api.wialon.com", self._image_uri)
104
158
 
105
159
  def execute_command(
106
160
  self,
@@ -269,7 +269,7 @@ class WialonSession:
269
269
 
270
270
  """
271
271
  try:
272
- self.logger.info("Logging into Wialon API session...")
272
+ self.logger.debug("Logging into Wialon API session...")
273
273
  response = self.wialon_api.token_login(**{"token": token, "fl": flags})
274
274
  self._set_login_response(response)
275
275
  self.logger.debug(f"Logged into Wialon API session '{response.get('eid')}'")
@@ -286,7 +286,7 @@ class WialonSession:
286
286
  :rtype: :py:obj:`None`
287
287
 
288
288
  """
289
- self.logger.info("Logging out of Wialon API session...")
289
+ self.logger.debug("Logging out of Wialon API session...")
290
290
  response: dict = self.wialon_api.core_logout({})
291
291
 
292
292
  if response.get("error") != 0:
@@ -6,7 +6,69 @@ from terminusgps.wialon import constants, flags
6
6
  from terminusgps.wialon.session import WialonSession
7
7
 
8
8
 
9
- def get_resource_ids(session: WialonSession) -> list[int] | None:
9
+ def get_units_by_carrier(carrier_name: str, session: WialonSession) -> list[str]:
10
+ """
11
+ Returns a list of all unit ids by telecommunications carrier company name.
12
+
13
+ :param carrier_name: A telecommunications carrier company name, e.g. ``"US Cell"`` or ``"Conetixx"``.
14
+ :type carrier_name: :py:obj:`str`
15
+ :param session: A valid Wialon API session.
16
+ :type session: :py:obj:`~terminusgps.wialon.session.WialonSession`
17
+ :returns: A list of unit ids.
18
+ :rtype: :py:obj:`list`
19
+
20
+ """
21
+ property: str = constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE.value
22
+ results = session.wialon_api.core_search_items(
23
+ **{
24
+ "spec": {
25
+ "itemsType": "avl_unit",
26
+ "propName": property,
27
+ "propValueMask": f"carrier:{carrier_name}",
28
+ "sortType": property,
29
+ },
30
+ "force": 0,
31
+ "flags": flags.DataFlag.UNIT_BASE.value,
32
+ "from": 0,
33
+ "to": 0,
34
+ }
35
+ )
36
+ return [item.get("id") for item in results.get("items", [])]
37
+
38
+
39
+ def get_unit_by_iccid(iccid: str, session: WialonSession) -> str | None:
40
+ """
41
+ Returns a unit id by iccid (SIM card #).
42
+
43
+ :param iccid: A SIM card #.
44
+ :type iccid: :py:obj:`str`
45
+ :param session: A valid Wialon API session.
46
+ :type session: :py:obj:`~terminusgps.wialon.session.WialonSession`
47
+ :returns: The unit id, if it was found.
48
+ :rtype: :py:obj:`str` | :py:obj:`None`
49
+
50
+ """
51
+ property: str = constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE.value
52
+ results = session.wialon_api.core_search_items(
53
+ **{
54
+ "spec": {
55
+ "itemsType": "avl_unit",
56
+ "propName": property,
57
+ "propValueMask": f"iccid:{iccid}",
58
+ "sortType": property,
59
+ },
60
+ "force": 0,
61
+ "flags": flags.DataFlag.UNIT_BASE.value,
62
+ "from": 0,
63
+ "to": 0,
64
+ }
65
+ )
66
+ if results.get("totalItemsCount") != 1:
67
+ raise ValueError(results)
68
+ return results.get("items", [{}])[0].get("id")
69
+
70
+
71
+ def get_resources(session: WialonSession) -> list[int] | None:
10
72
  """
11
73
  Returns a list of all resource ids in Wialon.
12
74
 
@@ -61,7 +123,7 @@ def get_hw_type_id(name: str, session: WialonSession) -> int | None:
61
123
  return int(hw_types.get(name)) if name in hw_types.keys() else None
62
124
 
63
125
 
64
- def get_id_from_imei(imei: str, session: WialonSession) -> str | None:
126
+ def get_unit_by_imei(imei: str, session: WialonSession) -> str | None:
65
127
  """
66
128
  Takes a Wialon unit's IMEI # and returns its unit id.
67
129
 
@@ -170,11 +232,11 @@ def generate_wialon_password(length: int = 32) -> str:
170
232
  min_length, max_length = 8, 64
171
233
  if length > max_length:
172
234
  raise ValueError(
173
- f"Password cannot be greater than {max_length} characters in length. Got {length}."
235
+ f"Password cannot be greater than {max_length} characters in length, got {length}."
174
236
  )
175
237
  elif length < min_length:
176
238
  raise ValueError(
177
- f"Password cannot be less than {min_length} characters in length. Got {length}."
239
+ f"Password cannot be less than {min_length} characters in length, got {length}."
178
240
  )
179
241
 
180
242
  s0 = list(string.ascii_uppercase)
@@ -1,20 +1,38 @@
1
1
  import string
2
2
 
3
- from django.core.exceptions import ValidationError
3
+ from django.conf import settings
4
+ from django.core.exceptions import ImproperlyConfigured, ValidationError
4
5
  from django.utils.translation import gettext_lazy as _
5
6
 
6
- from .wialon.session import WialonSession
7
+ from terminusgps.wialon.session import WialonSession
8
+
9
+ if not hasattr(settings, "WIALON_TOKEN"):
10
+ raise ImproperlyConfigured("'WIALON_TOKEN' setting is required.")
7
11
 
8
12
 
9
13
  class WialonValidatorBase:
10
14
  def __init__(self) -> None:
11
15
  self.session: WialonSession = WialonSession()
12
- self.session.login(self.session.token)
16
+ self.session.login(settings.WIALON_TOKEN)
13
17
 
14
18
  def __call__(self, value: str) -> None:
15
19
  raise NotImplementedError("Subclasses must implement this method.")
16
20
 
17
21
 
22
+ class WialonVinNumberValidator(WialonValidatorBase):
23
+ def __call__(self, value: str) -> None:
24
+ response = self.session.wialon_api.unit_get_vin_info(vin=value)
25
+ if "error" in response["vin_lookup_result"].keys():
26
+ raise ValidationError(
27
+ _("Failed to get info for VIN '%(value)s': '%(message)s'"),
28
+ code="invalid",
29
+ params={
30
+ "value": value,
31
+ "message": response["vin_lookup_result"].get("message", ""),
32
+ },
33
+ )
34
+
35
+
18
36
  class WialonImeiNumberValidator(WialonValidatorBase):
19
37
  def __call__(self, value: str) -> None:
20
38
  response = self.session.wialon_api.core_search_items(
@@ -33,7 +51,7 @@ class WialonImeiNumberValidator(WialonValidatorBase):
33
51
  )
34
52
  if response is None or not response.get("items"):
35
53
  raise ValidationError(
36
- _("IMEI #%(value)s was not found in Wialon."),
54
+ _("IMEI '%(value)s' was not found in Wialon."),
37
55
  code="invalid",
38
56
  params={"value": value},
39
57
  )
@@ -41,20 +59,18 @@ class WialonImeiNumberValidator(WialonValidatorBase):
41
59
 
42
60
  def validate_imei_number(value: str) -> None:
43
61
  """Raises :py:exec:`ValidationError` if the value is an invalid IMEI number."""
44
- try:
45
- WialonImeiNumberValidator()(value)
46
- except ValidationError:
47
- raise
62
+ WialonImeiNumberValidator()(value)
48
63
 
49
64
 
50
65
  def validate_vin_number(value: str) -> None:
51
66
  """Raises :py:exec:`ValidationError` if the value is an invalid VIN number."""
52
- if not len(value) == 17:
67
+ if len(value) != 17:
53
68
  raise ValidationError(
54
- _("Whoops! VIN # must be exactly 17 characters long, got %(len)s."),
69
+ _("Whoops! VIN # must be exactly 17 characters in length, got %(length)s."),
55
70
  code="invalid",
56
- params={"len": len(value)},
71
+ params={"length": len(value)},
57
72
  )
73
+ WialonVinNumberValidator()(value)
58
74
 
59
75
 
60
76
  def validate_wialon_password(value: str) -> None:
@@ -62,19 +78,16 @@ def validate_wialon_password(value: str) -> None:
62
78
  special_symbols_0: list[str] = ["!", "@", "#", "$", "%", "^", "*"]
63
79
  special_symbols_1: list[str] = ["(", ")", "[", "]", "-", "_", "+"]
64
80
  forbidden_symbols: list[str] = [",", ":", "&", "<", ">", "'"]
65
- value = value.strip() if value.startswith(" ") or value.endswith(" ") else value
66
81
 
67
82
  if len(value) < 4:
68
83
  raise ValidationError(
69
- _("Password cannot be less than 4 characters in length. Got '%(len)s'."),
84
+ _("Password cannot be less than 4 characters in length, got %(len)s."),
70
85
  code="invalid",
71
86
  params={"len": len(value)},
72
87
  )
73
88
  if len(value) > 64:
74
89
  raise ValidationError(
75
- _(
76
- "Password cannot be greater than 64 characters in length. Got '%(len)s'."
77
- ),
90
+ _("Password cannot be greater than 64 characters in length, got %(len)s."),
78
91
  code="invalid",
79
92
  params={"len": len(value)},
80
93
  )