10
10
class DeviceManager :
11
11
"""
12
12
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.
13
16
"""
14
17
def __init__ (self , client ):
15
18
self .client = client
@@ -63,6 +66,12 @@ def get_device_filter_model(self) -> typing.Type[device_models.FilterDeviceModel
63
66
return device_models .FilterDeviceModel
64
67
65
68
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
+ """
66
75
device_id = self .validate_device (device )
67
76
sms_response = device_call_managers .GetAllSmsFromDevice ().call_api (
68
77
client = self .client , path_params = {'endpoint_id' : device_id }
@@ -76,7 +85,8 @@ def send_sms(
76
85
sms : device_models .SmsCreateModel
77
86
) -> bool :
78
87
"""
79
- Method sends sms to device
88
+ Sends an SMS to the device.
89
+
80
90
:param device: device model or id of device
81
91
:param sms: SmsCreateModel
82
92
:return: True if sms was sent
@@ -90,7 +100,8 @@ def send_sms(
90
100
91
101
def update_device (self , * , device_id : int , device : device_models .UpdateDevice ) -> device_models .Device :
92
102
"""
93
- Method updates device
103
+ Updates the device.
104
+
94
105
:param device_id: id of device
95
106
:param device: device update model
96
107
:return: True if device was updated
@@ -101,7 +112,8 @@ def update_device(self, *, device_id: int, device: device_models.UpdateDevice) -
101
112
102
113
def reset_connectivity_network (self , device_id : int ) -> True :
103
114
"""
104
- Method resets device connectivity network
115
+ Resets the device's connectivity network.
116
+
105
117
:param device_id: id of device
106
118
:return: True if reset of network was successful
107
119
"""
@@ -111,7 +123,8 @@ def reset_connectivity_network(self, device_id: int) -> True:
111
123
112
124
def reset_connectivity_data (self , device_id : int ) -> True :
113
125
"""
114
- Method resets device connectivity data
126
+ Resets the device's connectivity data.
127
+
115
128
:param device_id: id of device
116
129
:return: True if reset of data was successful
117
130
"""
@@ -121,7 +134,8 @@ def reset_connectivity_data(self, device_id: int) -> True:
121
134
122
135
def get_device_connectivity_status (self , device_id : int ) -> device_models .DeviceConnectivityStatus :
123
136
"""
124
- Method returns device connectivity status
137
+ Returns the device's connectivity status.
138
+
125
139
:param device_id: id of device
126
140
:return: DeviceConnectivityStatus model
127
141
"""
@@ -135,9 +149,10 @@ def get_devices_list(
135
149
filter_model : device_models .FilterDeviceModel = None ,
136
150
sort_enum : device_models .DeviceSortModel = None ,
137
151
** kwargs
138
- ) -> typing .Generator [device_models .RetrieveDevice , None , None ]:
152
+ ) -> typing .Generator [device_models .Device , None , None ]:
139
153
"""
140
- Method returns list of devices
154
+ Returns a list of devices.
155
+
141
156
:param filter_model: device filter model
142
157
:param sort_enum: device sort enum
143
158
:return: list of devices
@@ -151,6 +166,8 @@ def get_devices_list(
151
166
152
167
def delete_device (self , device_id : int ) -> True :
153
168
"""
169
+ Deletes the device.
170
+
154
171
:param device_id: id of device
155
172
:return: True if device was deleted
156
173
"""
@@ -161,6 +178,8 @@ def delete_device(self, device_id: int) -> True:
161
178
162
179
def add_device_blacklist_operator (self , device_id : int , operator_id : int ) -> True :
163
180
"""
181
+ Adds an operator to the blacklist.
182
+
164
183
:param device_id: id of device
165
184
:param operator_id: id of operator
166
185
: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
171
190
172
191
def delete_device_blacklist_operator (self , device_id : int , operator_id : int ):
173
192
"""
193
+ Removes an operator from the blacklist.
194
+
174
195
:param device_id: id of device
175
196
:param operator_id: id of operator
176
197
:return: True if operator was deleted from blacklist
@@ -181,6 +202,8 @@ def delete_device_blacklist_operator(self, device_id: int, operator_id: int):
181
202
182
203
def get_device_operator_blacklist (self , device_id : int ):
183
204
"""
205
+ Returns a list of blacklisted operators.
206
+
184
207
:param device_id: id of device
185
208
:return: list of operators
186
209
"""
@@ -192,6 +215,8 @@ def get_device_operator_blacklist(self, device_id: int):
192
215
193
216
def get_device_events_list (self , device : typing .Union [device_models .Device , int ]):
194
217
"""
218
+ Returns a list of events for the device.
219
+
195
220
:param device: Device pydantic-model or int
196
221
:return: Generator with Device objects
197
222
"""
@@ -207,16 +232,13 @@ def change_status(
207
232
device_models .UpdateDevice , device_models .Device , device_models .RetrieveDevice , int
208
233
],
209
234
enable : bool = None , disable : bool = None
210
- ) -> None :
235
+ ) -> bool :
211
236
"""
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.
213
238
214
239
:param device: The ID or device model to update.
215
- :type device: Union[UpdateDevice, Device, RetrieveDevice, int]
216
240
:param enable: Whether to enable the device.
217
- :type enable: bool
218
241
:param disable: Whether to disable the device.
219
- :type disable: bool
220
242
:raises ValidationErrorException: If neither `enable` nor `disable` is provided, or if both are provided.
221
243
"""
222
244
if not (enable or disable ) or (enable and disable ):
@@ -231,7 +253,8 @@ def change_status(
231
253
232
254
def disable_device (self , device_id : int ):
233
255
"""
234
- Method for changing a device status to 'disabled'
256
+ Changes a device status to 'disabled'.
257
+
235
258
:param device_id: id of device
236
259
:return: True if device was disabled
237
260
"""
@@ -240,7 +263,10 @@ def disable_device(self, device_id: int):
240
263
241
264
def release_sim (self , device_id : int ):
242
265
"""
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
244
270
"""
245
271
device = self .retrieve_device (device_id = device_id )
246
272
if not device .sim :
@@ -253,7 +279,11 @@ def release_sim(self, device_id: int):
253
279
254
280
def assign_sim (self , device_id : int , sim_id : int , enable : bool = False ) -> None :
255
281
"""
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
257
287
"""
258
288
device = self .retrieve_device (device_id = device_id )
259
289
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:
270
300
271
301
def create_device (self , device : device_models .Device ) -> bool :
272
302
"""
273
- Method for creating a device
303
+ Creates a device
304
+
274
305
:param device: device model
275
306
:return: True if device was created
276
307
"""
@@ -279,6 +310,12 @@ def create_device(self, device: device_models.Device) -> bool:
279
310
return device_call_managers .CreateDevice ().call_api (client = self .client , data = device .dict (exclude_none = True ))
280
311
281
312
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
+ """
282
319
if not isinstance (device_id , int ) or device_id <= 0 :
283
320
raise UnexpectedArgumentException ('Device id must be positive integer' )
284
321
response = device_call_managers .RetrieveDevice ().call_api (
@@ -297,18 +334,11 @@ def validate_device(device: device_models.Device) -> int:
297
334
298
335
@staticmethod
299
336
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
- """
304
337
if status == emnify_constants .SimStatusesDict .ACTIVATED_DICT :
305
338
if not device .sim :
306
339
raise emnify_errors .ValidationErrorException ('Devices for activation must have sim`s' )
307
340
308
341
def __change_device_status (self , action : str , device ):
309
- """
310
- Hidden method for changing status of the device
311
- """
312
342
status_dict = {
313
343
'enable' : {
314
344
'sim_status' : emnify_constants .SimStatusesDict .ACTIVATED_DICT .value ,
0 commit comments