python-terminusgps 30.0.0__py3-none-any.whl → 31.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-terminusgps
3
- Version: 30.0.0
3
+ Version: 31.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,7 +1,4 @@
1
1
  terminusgps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- terminusgps/mixins.py,sha256=jzs_dH_YDmohH86I3uPnN-66C9OPVXaDPVdRHXA6vdk,940
3
- terminusgps/settings.py,sha256=vY5yNjyMu-7Ya0bIPWUvrrSLERtxHGdkfeoY4Ul6cP0,613
4
- terminusgps/utils.py,sha256=SYDQyHA5tTuVwdpZGsCtf0LpTTD0ilRKoxa8StfSTpQ,156
5
2
  terminusgps/authorizenet/__init__.py,sha256=LiGLlWNNiqS7RSOP4Apabx-b9EBYyNbxRY_a0mvJoaE,466
6
3
  terminusgps/authorizenet/auth.py,sha256=ICxPPzoUc64VbsIIemEWKrn8xjHGwbNdo2VbtaFCFss,1107
7
4
  terminusgps/authorizenet/errors.py,sha256=HG5NwVxQCtOYidVl30y49PC0Ovw5VYdsy9wTgUFMw9M,949
@@ -15,25 +12,29 @@ terminusgps/authorizenet/profiles/subscriptions.py,sha256=N4_0kbBBJ0FtKdIydN8FLn
15
12
  terminusgps/aws/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
13
  terminusgps/aws/connect.py,sha256=TWf2bVz6LqSNQfVD7FKRn3K71VuLOwBj05Gs-9BsROg,693
17
14
  terminusgps/aws/secrets.py,sha256=MxQEmmBLpMUQ2tYAsHdCYf-7RZ84LiogdKcTsACX5dw,361
15
+ terminusgps/django/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ terminusgps/django/mixins.py,sha256=jzs_dH_YDmohH86I3uPnN-66C9OPVXaDPVdRHXA6vdk,940
17
+ terminusgps/django/settings.py,sha256=vY5yNjyMu-7Ya0bIPWUvrrSLERtxHGdkfeoY4Ul6cP0,613
18
+ terminusgps/django/utils.py,sha256=SYDQyHA5tTuVwdpZGsCtf0LpTTD0ilRKoxa8StfSTpQ,156
18
19
  terminusgps/twilio/__init__.py,sha256=dYo41F2jft_eHDWSUtSpKGSRG1bewq_qClqilUJZkYM,33
19
20
  terminusgps/twilio/caller.py,sha256=TiQ4f0TDDC35he1M1iSsBM2vutdGriwtV4pc17T--6I,3552
20
21
  terminusgps/twilio/validators.py,sha256=nn7CCBTktNjcln6M4MR0ACxEsClgioSu89LRLgIiBZk,1112
21
22
  terminusgps/wialon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- terminusgps/wialon/constants.py,sha256=5Yj5YflagDaqIYrF2k8QOqyFgmNkXM05647omBTZeDc,5467
23
+ terminusgps/wialon/constants.py,sha256=-fRrvtQuSAJ6hpBJzp_Xa4GDI4LuQbqZ1z1L_QFzZiE,5609
23
24
  terminusgps/wialon/flags.py,sha256=M50EdhxQ8IMnJnU0mrHK7-h8Asc6tvNiTOOfd1dBW6A,12815
24
25
  terminusgps/wialon/logger.py,sha256=nUBsaLMaffSaAHGHAM6mFXDzix9hbNecVtA3INVtii8,968
25
- terminusgps/wialon/session.py,sha256=UUPJFwoN4sUnB9Q7i18pjmBaKFt3wdZ1MZdj68ieO_0,9640
26
- terminusgps/wialon/utils.py,sha256=E_5OCC9wHhrKEwJv4hkTOqplJ_KmnQ5KlSPOhuXbhcg,8423
26
+ terminusgps/wialon/session.py,sha256=emB0XHJjFObtb6WbttsXZXTeRaPztcbjAV212B_Ssek,9781
27
+ terminusgps/wialon/utils.py,sha256=iRZi4uLk-qqNUXdEIbL-4ibfXh9xvEjXWmdoML9CubQ,10051
27
28
  terminusgps/wialon/validators.py,sha256=NNqMhoXn1M_f4Edm6oD8I7lzzXKZSqyZ6n7fR3obWj8,4241
28
29
  terminusgps/wialon/items/__init__.py,sha256=3BVthghekMvhMQSzQgBMlD_phxmKSmp3Zvmo-z0O8Bs,211
29
- terminusgps/wialon/items/base.py,sha256=EmuTVxI7GdlCCJIwFrw0v55gDuYUWNYZ39O2Yl8K2Mc,7876
30
+ terminusgps/wialon/items/base.py,sha256=4TAsmSQ-pw4mqiuL4_clN_Kvplcze4lZwL9oO1p7gkk,8001
30
31
  terminusgps/wialon/items/resource.py,sha256=wfUxACO4OdzT2IdCF9oBmU_7nYiH3Xvs6BripPD5IMI,14622
31
32
  terminusgps/wialon/items/retranslator.py,sha256=sVEWrp8q1I-tO_rMTCH7TeQDDbZryIq8d9KVnhYyhH0,3795
32
33
  terminusgps/wialon/items/route.py,sha256=amNPKZqgl8pEzKA_XJudnvBPzEsfHTmrC7uF15sZVI4,1216
33
34
  terminusgps/wialon/items/unit.py,sha256=ChONjm3wlFSlbNz-yEXziNbbs4LJ70F9-MI2c-p905k,10638
34
35
  terminusgps/wialon/items/unit_group.py,sha256=QV2ZZgICaN3n6W1pFIyMLyNKB6KYBsLyKG64i-qXoOg,4113
35
36
  terminusgps/wialon/items/user.py,sha256=N30wdejdG7LXrgafdKZH74YArGkX3xpZfTucn3m3aqM,7155
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,,
37
+ python_terminusgps-31.0.0.dist-info/METADATA,sha256=y4fXM6pCMkZ0znIWvVqoAOzitHrjZDbrhSDPIy06qcE,1061
38
+ python_terminusgps-31.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
+ python_terminusgps-31.0.0.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
40
+ python_terminusgps-31.0.0.dist-info/RECORD,,
File without changes
@@ -1,4 +1,5 @@
1
1
  import enum
2
+ from typing import override
2
3
 
3
4
  from . import flags
4
5
 
@@ -108,6 +109,10 @@ class WialonItemProperty(enum.StrEnum):
108
109
  UNIQUE_ID = "sys_unique_id"
109
110
  """Object unique id."""
110
111
 
112
+ @override
113
+ def __add__(self, other: str) -> str:
114
+ return ",".join([super().__str__(), str(other)])
115
+
111
116
 
112
117
  ACCESSMASK_RESOURCE_BASIC: int = sum(
113
118
  [
@@ -21,10 +21,13 @@ class WialonBase:
21
21
  def __str__(self) -> str:
22
22
  return str(self.id)
23
23
 
24
+ def __repr__(self) -> str:
25
+ return f"{type(self).__name__}(id={self.id}, session={self.session.id})"
26
+
24
27
  def populate(self) -> None:
25
28
  """Retrieves and saves the latest data for the item from Wialon."""
26
29
  response = self.session.wialon_api.core_search_item(
27
- **{"id": str(self.id), "flags": flags.DataFlag.UNIT_BASE.value}
30
+ **{"id": str(self.id), "flags": flags.DataFlag.UNIT_BASE}
28
31
  )
29
32
  if response is not None:
30
33
  item = response.get("item", {})
@@ -106,6 +109,7 @@ class WialonBase:
106
109
  self.session.wialon_api.item_update_name(
107
110
  **{"itemId": self.id, "name": new_name}
108
111
  )
112
+ self._name = new_name
109
113
 
110
114
  def add_afield(self, key: str, value: str) -> None:
111
115
  """
@@ -228,7 +232,7 @@ class WialonBase:
228
232
  def cfields(self) -> dict[str, str]:
229
233
  """Custom fields for the Wialon object."""
230
234
  response = self.session.wialon_api.core_search_item(
231
- **{"id": self.id, "flags": flags.DataFlag.UNIT_CUSTOM_FIELDS.value}
235
+ **{"id": self.id, "flags": flags.DataFlag.UNIT_CUSTOM_FIELDS}
232
236
  )
233
237
  fields = response.get("item", {}).get("flds") if response is not None else {}
234
238
  return {field["n"]: field["v"] for field in fields.values()} if fields else {}
@@ -237,7 +241,7 @@ class WialonBase:
237
241
  def afields(self) -> dict[str, str]:
238
242
  """Admin fields for the Wialon object."""
239
243
  response = self.session.wialon_api.core_search_item(
240
- **{"id": self.id, "flags": flags.DataFlag.UNIT_ADMIN_FIELDS.value}
244
+ **{"id": self.id, "flags": flags.DataFlag.UNIT_ADMIN_FIELDS}
241
245
  )
242
246
  fields = response.get("item", {}).get("aflds") if response is not None else {}
243
247
  return {field["n"]: field["v"] for field in fields.values()} if fields else {}
@@ -98,6 +98,12 @@ class WialonSession:
98
98
  logging.getLogger(self.__class__.__name__), level=log_level
99
99
  ).get_logger()
100
100
 
101
+ def __str__(self) -> str:
102
+ return str(self.id)
103
+
104
+ def __repr__(self) -> str:
105
+ return f"{self.__class__}(sid={self.id})"
106
+
101
107
  def __enter__(self) -> "WialonSession":
102
108
  """Logs into the Wialon API using a token set in :py:meth:`__init__`."""
103
109
  assert self.token, "Wialon API token was not set"
@@ -3,79 +3,119 @@ import string
3
3
  import typing
4
4
 
5
5
  from terminusgps.wialon import constants, flags
6
+ from terminusgps.wialon.items import WialonUnit
7
+ from terminusgps.wialon.items.resource import WialonResource
6
8
  from terminusgps.wialon.session import WialonSession
7
9
 
8
10
 
9
- def get_units_by_carrier(carrier_name: str, session: WialonSession) -> list[str]:
11
+ def get_carrier_names(session: WialonSession) -> list[str]:
10
12
  """
11
- Returns a list of all unit ids by telecommunications carrier company name.
13
+ Returns a list of all telecommunication carrier company names present in Wialon.
14
+
15
+ :param session: A valid Wialon API session.
16
+ :type session: :py:obj:`~terminusgps.wialon.session.WialonSession`
17
+ :returns: A list of telecommunication carrier company names.
18
+ :rtype: :py:obj:`list`
19
+
20
+ """
21
+ afname: str = constants.WialonItemProperty.ADMIN_FIELD_NAME
22
+ afval: str = constants.WialonItemProperty.ADMIN_FIELD_VALUE
23
+ results: dict = session.wialon_api.core_search_items(
24
+ **{
25
+ "spec": {
26
+ "itemsType": constants.WialonItemsType.UNIT,
27
+ "propName": ",".join([afname, afval]),
28
+ "propValueMask": "carrier,*",
29
+ "sortType": ",".join([afname, afval]),
30
+ },
31
+ "force": 0,
32
+ "flags": flags.DataFlag.UNIT_BASE + flags.DataFlag.UNIT_ADMIN_FIELDS,
33
+ "from": 0,
34
+ "to": 0,
35
+ }
36
+ )
37
+ carrier_names: list[str] = [
38
+ field["v"]
39
+ for item in results.get("items", [{}])
40
+ for field in item.get("aflds", {}).values()
41
+ if field["n"] == "carrier" and field["v"]
42
+ ]
43
+ return sorted(list(frozenset(carrier_names)))
44
+
45
+
46
+ def get_units_by_carrier(
47
+ carrier_name: str, session: WialonSession
48
+ ) -> list[WialonUnit] | None:
49
+ """
50
+ Returns a list of all units by telecommunications carrier company name.
12
51
 
13
52
  :param carrier_name: A telecommunications carrier company name, e.g. ``"US Cell"`` or ``"Conetixx"``.
14
53
  :type carrier_name: :py:obj:`str`
15
54
  :param session: A valid Wialon API session.
16
55
  :type session: :py:obj:`~terminusgps.wialon.session.WialonSession`
17
- :returns: A list of unit ids.
56
+ :returns: A list of units, if any were found.
18
57
  :rtype: :py:obj:`list`
19
58
 
20
59
  """
21
- property: str = constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE.value
22
60
  results = session.wialon_api.core_search_items(
23
61
  **{
24
62
  "spec": {
25
63
  "itemsType": "avl_unit",
26
- "propName": property,
64
+ "propName": constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE,
27
65
  "propValueMask": f"carrier:{carrier_name}",
28
- "sortType": property,
66
+ "sortType": constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE,
29
67
  },
30
68
  "force": 0,
31
- "flags": flags.DataFlag.UNIT_BASE.value,
69
+ "flags": flags.DataFlag.UNIT_BASE,
32
70
  "from": 0,
33
71
  "to": 0,
34
72
  }
35
73
  )
36
- return [item.get("id") for item in results.get("items", [])]
74
+ if results:
75
+ return [
76
+ WialonUnit(id=item.get("id"), session=session)
77
+ for item in results.get("items", [])
78
+ ]
37
79
 
38
80
 
39
- def get_unit_by_iccid(iccid: str, session: WialonSession) -> str | None:
81
+ def get_unit_by_iccid(iccid: str, session: WialonSession) -> WialonUnit | None:
40
82
  """
41
- Returns a unit id by iccid (SIM card #).
83
+ Returns a unit by iccid (SIM card #).
42
84
 
43
85
  :param iccid: A SIM card #.
44
86
  :type iccid: :py:obj:`str`
45
87
  :param session: A valid Wialon API session.
46
88
  :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`
89
+ :returns: The unit, if it was found.
90
+ :rtype: :py:obj:`~terminusgps.wialon.items.WialonUnit` | :py:obj:`None`
49
91
 
50
92
  """
51
- property: str = constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE.value
52
93
  results = session.wialon_api.core_search_items(
53
94
  **{
54
95
  "spec": {
55
96
  "itemsType": "avl_unit",
56
- "propName": property,
97
+ "propName": constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE,
57
98
  "propValueMask": f"iccid:{iccid}",
58
- "sortType": property,
99
+ "sortType": constants.WialonItemProperty.ADMIN_FIELD_NAME_VALUE,
59
100
  },
60
101
  "force": 0,
61
- "flags": flags.DataFlag.UNIT_BASE.value,
102
+ "flags": flags.DataFlag.UNIT_BASE,
62
103
  "from": 0,
63
104
  "to": 0,
64
105
  }
65
106
  )
66
- if results.get("totalItemsCount") != 1:
67
- raise ValueError(results)
68
- return results.get("items", [{}])[0].get("id")
107
+ if results:
108
+ return WialonUnit(id=results.get("items", [{}])[0].get("id"), session=session)
69
109
 
70
110
 
71
- def get_resources(session: WialonSession) -> list[int] | None:
111
+ def get_resources(session: WialonSession) -> list[WialonResource] | None:
72
112
  """
73
- Returns a list of all resource ids in Wialon.
113
+ Returns a list of all resources in Wialon.
74
114
 
75
115
  :param session: A valid Wialon API session.
76
116
  :type session: :py:obj:`~terminusgps.wialon.session.WialonSession`
77
- :returns: A list of account ids.
78
- :rtype: :py:obj:`list`
117
+ :returns: A list of resources, if found.
118
+ :rtype: :py:obj:`list` | :py:obj:`None`
79
119
 
80
120
  """
81
121
  results = session.wialon_api.core_search_items(
@@ -95,7 +135,10 @@ def get_resources(session: WialonSession) -> list[int] | None:
95
135
  }
96
136
  )
97
137
  if results:
98
- return [int(item.get("id")) for item in results.get("items", [])]
138
+ return [
139
+ WialonResource(id=item.get("id"), session=session)
140
+ for item in results.get("items", [])
141
+ ]
99
142
 
100
143
 
101
144
  def get_hw_type_id(name: str, session: WialonSession) -> int | None:
@@ -123,7 +166,7 @@ def get_hw_type_id(name: str, session: WialonSession) -> int | None:
123
166
  return int(hw_types.get(name)) if name in hw_types.keys() else None
124
167
 
125
168
 
126
- def get_unit_by_imei(imei: str, session: WialonSession) -> str | None:
169
+ def get_unit_by_imei(imei: str, session: WialonSession) -> WialonUnit | None:
127
170
  """
128
171
  Takes a Wialon unit's IMEI # and returns its unit id.
129
172
 
@@ -158,7 +201,7 @@ def get_unit_by_imei(imei: str, session: WialonSession) -> str | None:
158
201
  )
159
202
 
160
203
  if results and results.get("totalItemsCount", 0) == 1:
161
- return results["items"][0].get("id")
204
+ return WialonUnit(id=results["items"][0].get("id"), session=session)
162
205
 
163
206
 
164
207
  def get_vin_info(vin_number: str, session: WialonSession) -> dict:
File without changes
File without changes
File without changes