Skip to content

Commit 7338215

Browse files
authored
Merge release candidate #233 from emnify/development
2 parents 0b57dcb + adcbec7 commit 7338215

File tree

4 files changed

+71
-44
lines changed

4 files changed

+71
-44
lines changed

DEVELOPMENT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To set up your sandbox, modify the code in this file as needed.
2424
2525
Once your sandbox is set up, you can launch the file and view the results.
2626
```shell
27-
docker run -t -e EMNIFY_SDK_APPLICATION_TOKEN=<your_token_here> -e EMINFY_SDK_API_ENDPOINT_URL=<your_debug_API_endpoint> -v $(pwd):/sdk emnify/python-sdk python docs/examples/local_debug.py
27+
docker run -t -e EMNIFY_SDK_APPLICATION_TOKEN=<your_token_here> -e EMNIFY_SDK_API_ENDPOINT_URL=<your_debug_API_endpoint> -v $(pwd):/sdk emnify/python-sdk python docs/examples/local_debug.py
2828
```
2929

3030
## Version Bump

emnify/api_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from emnify.modules.api.models import AuthenticationResponse
77
from emnify import constants as emnify_constants
88

9-
MAIN_URL = os.environ.get('EMINFY_SDK_API_ENDPOINT_URL', 'https://cdn.emnify.net/api')
9+
MAIN_URL = os.environ.get('EMNIFY_SDK_API_ENDPOINT_URL', 'https://cdn.emnify.net/api')
1010

1111
MAX_PAGES_IN_PAGINATOR = 1000 # with regular page size 1000...2000 gives max 2_000_000 records
1212

@@ -46,7 +46,7 @@ def process_exception(self, response: requests.Response, client, data: dict = No
4646
raise emnify_errors.ValidationErrorException(f'{response.json()}')
4747

4848
def return_paginator(
49-
self, response: requests.Response, client, data, files, query_params, path_params
49+
self, response: requests.Response, client, data: dict = None, files=None, path_params: dict = None, query_params: dict = None
5050
) -> typing.Generator:
5151
query_params = query_params or {}
5252
page = query_params.get('page', 1) if query_params else 1

emnify/modules/device/manager.py

+53-23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
class DeviceManager:
1111
"""
1212
Manager that allows to get/retrieve/create/update/send_sms to device
13+
14+
Args:
15+
client: An instance of the EMnify class used for making API requests.
1316
"""
1417
def __init__(self, client):
1518
self.client = client
@@ -63,6 +66,12 @@ def get_device_filter_model(self) -> typing.Type[device_models.FilterDeviceModel
6366
return device_models.FilterDeviceModel
6467

6568
def get_device_sms_list(self, *, device: typing.Union[device_models.Device, int]) -> device_models.ListSms:
69+
"""
70+
Returns a list of SMS from the device.
71+
72+
:param device: device model or id of device
73+
:return: list of devices
74+
"""
6675
device_id = self.validate_device(device)
6776
sms_response = device_call_managers.GetAllSmsFromDevice().call_api(
6877
client=self.client, path_params={'endpoint_id': device_id}
@@ -76,7 +85,8 @@ def send_sms(
7685
sms: device_models.SmsCreateModel
7786
) -> bool:
7887
"""
79-
Method sends sms to device
88+
Sends an SMS to the device.
89+
8090
:param device: device model or id of device
8191
:param sms: SmsCreateModel
8292
:return: True if sms was sent
@@ -90,7 +100,8 @@ def send_sms(
90100

91101
def update_device(self, *, device_id: int, device: device_models.UpdateDevice) -> device_models.Device:
92102
"""
93-
Method updates device
103+
Updates the device.
104+
94105
:param device_id: id of device
95106
:param device: device update model
96107
:return: True if device was updated
@@ -101,7 +112,8 @@ def update_device(self, *, device_id: int, device: device_models.UpdateDevice) -
101112

102113
def reset_connectivity_network(self, device_id: int) -> True:
103114
"""
104-
Method resets device connectivity network
115+
Resets the device's connectivity network.
116+
105117
:param device_id: id of device
106118
:return: True if reset of network was successful
107119
"""
@@ -111,7 +123,8 @@ def reset_connectivity_network(self, device_id: int) -> True:
111123

112124
def reset_connectivity_data(self, device_id: int) -> True:
113125
"""
114-
Method resets device connectivity data
126+
Resets the device's connectivity data.
127+
115128
:param device_id: id of device
116129
:return: True if reset of data was successful
117130
"""
@@ -121,7 +134,8 @@ def reset_connectivity_data(self, device_id: int) -> True:
121134

122135
def get_device_connectivity_status(self, device_id: int) -> device_models.DeviceConnectivityStatus:
123136
"""
124-
Method returns device connectivity status
137+
Returns the device's connectivity status.
138+
125139
:param device_id: id of device
126140
:return: DeviceConnectivityStatus model
127141
"""
@@ -135,9 +149,10 @@ def get_devices_list(
135149
filter_model: device_models.FilterDeviceModel = None,
136150
sort_enum: device_models.DeviceSortModel = None,
137151
**kwargs
138-
) -> typing.Generator[device_models.RetrieveDevice, None, None]:
152+
) -> typing.Generator[device_models.Device, None, None]:
139153
"""
140-
Method returns list of devices
154+
Returns a list of devices.
155+
141156
:param filter_model: device filter model
142157
:param sort_enum: device sort enum
143158
:return: list of devices
@@ -151,6 +166,8 @@ def get_devices_list(
151166

152167
def delete_device(self, device_id: int) -> True:
153168
"""
169+
Deletes the device.
170+
154171
:param device_id: id of device
155172
:return: True if device was deleted
156173
"""
@@ -161,6 +178,8 @@ def delete_device(self, device_id: int) -> True:
161178

162179
def add_device_blacklist_operator(self, device_id: int, operator_id: int) -> True:
163180
"""
181+
Adds an operator to the blacklist.
182+
164183
:param device_id: id of device
165184
:param operator_id: id of operator
166185
:return: True if operator was added to blacklist
@@ -171,6 +190,8 @@ def add_device_blacklist_operator(self, device_id: int, operator_id: int) -> Tru
171190

172191
def delete_device_blacklist_operator(self, device_id: int, operator_id: int):
173192
"""
193+
Removes an operator from the blacklist.
194+
174195
:param device_id: id of device
175196
:param operator_id: id of operator
176197
:return: True if operator was deleted from blacklist
@@ -181,6 +202,8 @@ def delete_device_blacklist_operator(self, device_id: int, operator_id: int):
181202

182203
def get_device_operator_blacklist(self, device_id: int):
183204
"""
205+
Returns a list of blacklisted operators.
206+
184207
:param device_id: id of device
185208
:return: list of operators
186209
"""
@@ -192,6 +215,8 @@ def get_device_operator_blacklist(self, device_id: int):
192215

193216
def get_device_events_list(self, device: typing.Union[device_models.Device, int]):
194217
"""
218+
Returns a list of events for the device.
219+
195220
:param device: Device pydantic-model or int
196221
:return: Generator with Device objects
197222
"""
@@ -207,16 +232,13 @@ def change_status(
207232
device_models.UpdateDevice, device_models.Device, device_models.RetrieveDevice, int
208233
],
209234
enable: bool = None, disable: bool = None
210-
) -> None:
235+
) -> bool:
211236
"""
212-
Change the status of a device and assigned SIM to enabled or disabled.
237+
Changes the status of a device and its assigned SIM to enabled or disabled.
213238
214239
:param device: The ID or device model to update.
215-
:type device: Union[UpdateDevice, Device, RetrieveDevice, int]
216240
:param enable: Whether to enable the device.
217-
:type enable: bool
218241
:param disable: Whether to disable the device.
219-
:type disable: bool
220242
:raises ValidationErrorException: If neither `enable` nor `disable` is provided, or if both are provided.
221243
"""
222244
if not (enable or disable) or (enable and disable):
@@ -231,7 +253,8 @@ def change_status(
231253

232254
def disable_device(self, device_id: int):
233255
"""
234-
Method for changing a device status to 'disabled'
256+
Changes a device status to 'disabled'.
257+
235258
:param device_id: id of device
236259
:return: True if device was disabled
237260
"""
@@ -240,7 +263,10 @@ def disable_device(self, device_id: int):
240263

241264
def release_sim(self, device_id: int):
242265
"""
243-
This method allows to release the assigned SIM from device by device_id
266+
Releases the assigned SIM from the device.
267+
268+
:param device_id: id of device
269+
:return: True if sim was released
244270
"""
245271
device = self.retrieve_device(device_id=device_id)
246272
if not device.sim:
@@ -253,7 +279,11 @@ def release_sim(self, device_id: int):
253279

254280
def assign_sim(self, device_id: int, sim_id: int, enable: bool = False) -> None:
255281
"""
256-
this method allow to assign a SIM to the device
282+
Assigns a SIM to the device
283+
284+
:param device_id: id of device
285+
:param sim_id: id of SIM
286+
:param enable: boolean value/activate to enable or disable the device
257287
"""
258288
device = self.retrieve_device(device_id=device_id)
259289
sim = self.client.sim.retrieve_sim(sim_id=sim_id)
@@ -270,7 +300,8 @@ def assign_sim(self, device_id: int, sim_id: int, enable: bool = False) -> None:
270300

271301
def create_device(self, device: device_models.Device) -> bool:
272302
"""
273-
Method for creating a device
303+
Creates a device
304+
274305
:param device: device model
275306
:return: True if device was created
276307
"""
@@ -279,6 +310,12 @@ def create_device(self, device: device_models.Device) -> bool:
279310
return device_call_managers.CreateDevice().call_api(client=self.client, data=device.dict(exclude_none=True))
280311

281312
def retrieve_device(self, device_id: int) -> device_models.RetrieveDevice:
313+
"""
314+
Retrieves endpoint details for a given ID.
315+
316+
:param device_id: id of the device.
317+
:return: Endpoint details associated with the given ID.
318+
"""
282319
if not isinstance(device_id, int) or device_id <= 0:
283320
raise UnexpectedArgumentException('Device id must be positive integer')
284321
response = device_call_managers.RetrieveDevice().call_api(
@@ -297,18 +334,11 @@ def validate_device(device: device_models.Device) -> int:
297334

298335
@staticmethod
299336
def __check_device_status(device, status: dict):
300-
"""
301-
Hidden method for checking device for status update
302-
devices to activate must have activated sim
303-
"""
304337
if status == emnify_constants.SimStatusesDict.ACTIVATED_DICT:
305338
if not device.sim:
306339
raise emnify_errors.ValidationErrorException('Devices for activation must have sim`s')
307340

308341
def __change_device_status(self, action: str, device):
309-
"""
310-
Hidden method for changing status of the device
311-
"""
312342
status_dict = {
313343
'enable': {
314344
'sim_status': emnify_constants.SimStatusesDict.ACTIVATED_DICT.value,

emnify/modules/sim/manager.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,24 @@ class SimManager:
1212
Args:
1313
client: An instance of the EMnify class used for making API requests.
1414
"""
15+
1516
def __init__(self, client):
1617
self.client = client
1718

1819
@property
1920
def get_sim_list_model(self):
20-
"""
21-
Returns the model for the SIM list.
22-
"""
2321
return sim_models.SimList
2422

2523
@property
2624
def get_sim_update_model(self):
27-
"""
28-
Returns the model for updating SIM cards.
29-
"""
3025
return sim_models.SimUpdate
3126

3227
@property
3328
def get_sim_filter_model(self):
34-
"""
35-
Returns the model for filtering SIM cards.
36-
"""
3729
return sim_models.SimFilter
3830

3931
@property
4032
def get_sim_sort_enum(self):
41-
"""
42-
Returns sim sorting options.
43-
"""
4433
return emnify_const.SimSort
4534

4635
def get_sim_list(
@@ -50,7 +39,8 @@ def get_sim_list(
5039
sort_enum: emnify_const.SimSort = None
5140
) -> typing.Generator[sim_models.SimList, None, None]:
5241
"""
53-
Retrieve iterable list of SIM`s.
42+
Retrieves an iterable list of SIM`s.
43+
5444
:param without_device: Allows to add a filter for request to find all SIM`s without device
5545
:param filter_model: Model for request`s filtering
5646
:param sort_enum: Model for request`s sorting
@@ -65,13 +55,17 @@ def get_sim_list(
6555

6656
def retrieve_sim(self, sim_id: int):
6757
"""
68-
Method for retrieving details of single sim by id
58+
Retrieves details of single SIM by ID.
59+
60+
:param sim_id: id of sim to retrieve
6961
"""
7062
return sim_models.SimList(**SimRetrieveApi().call_api(client=self.client, path_params={'sim': sim_id}))
7163

7264
def register_sim(self, bic: str) -> typing.Union[typing.List[sim_models.SimList], sim_models.SimList]:
7365
"""
74-
:param bic: BIC number of sim/batch sims for registration
66+
Registers SIM/batch SIMs.
67+
68+
:param bic: BIC number of SIM/batch SIMs for registration.
7569
"""
7670
data = emnify_const.SimStatusesDict.ACTIVATED_DICT.value
7771
sim_response = SimActivateApi().call_api(client=self.client, data=data, path_params={'bic': bic})
@@ -83,18 +77,20 @@ def register_sim(self, bic: str) -> typing.Union[typing.List[sim_models.SimList]
8377

8478
def update_sim(self, sim_id: int, sim: sim_models.SimUpdate) -> bool:
8579
"""
86-
Method for updating sim`s
80+
Updates SIM.
81+
8782
:param sim_id: int of sim to update
8883
:param sim: filled sim update model
8984
"""
90-
return SimUpdateApi()\
85+
return SimUpdateApi() \
9186
.call_api(client=self.client, data=sim.dict(exclude_none=True), path_params={'sim': sim_id})
9287

9388
def activate_sim(self, sim_id: int):
9489
"""
9590
Activates `suspended` or `issued` SIM.
9691
If you want to control both the device and SIM as a whole, it's recommended to use the :class:`DeviceManager.change_status` method if the SIM is assigned to a device.
9792
Learn more about SIM Lifecycle: https://docs.emnify.com/services/sim-lifecycle-management
93+
9894
:param sim_id: int of sim to update
9995
"""
10096
return SimUpdateApi() \
@@ -108,6 +104,7 @@ def suspend_sim(self, sim_id: int):
108104
Puts the `active` SIM to `suspended` state.
109105
If you want to control both the device and SIM as a whole, it's recommended to use the :class:`DeviceManager.change_status` method if the SIM is assigned to a device.
110106
Learn more about SIM Lifecycle: https://docs.emnify.com/services/sim-lifecycle-management
107+
111108
:param sim_id: id of sim to update
112109
"""
113110
return SimUpdateApi() \
@@ -131,7 +128,7 @@ def __transform_sim_filter_params(
131128
query_filter['sort'] = sort_enum
132129
if without_device is not None and without_device:
133130
if query_filter.get('q'):
134-
query_filter['q'] = query_filter['q']+'endpoint:null'
131+
query_filter['q'] = query_filter['q'] + 'endpoint:null'
135132
else:
136133
query_filter['q'] = 'endpoint:null'
137134
return query_filter

0 commit comments

Comments
 (0)