@@ -141,29 +141,21 @@ def get_device_server_assignment(self, device_id: str) -> OrgDeviceAssignedServe
141141 return response .data
142142
143143 @ensure_valid_token
144- def assign_unassign_device_to_mdm_server (
145- self , device_ids : List [str ], server_id : str , action : str
146- ) -> OrgDeviceActivity :
147- """
148- Assign or unassign one or more devices to/from an MDM server.
149-
150- :param device_ids: List of device IDs.
151- :param server_id: The ID of the MDM server.
152- :param action: 'assign' or 'unassign'.
153- :return: The completed OrgDeviceActivity.
154- """
155- unassign_response = self .abm .assign_unassign_device_to_mdm_server (
156- device_ids , server_id , action , self .access_token .value
157- )
158-
159- # use the ID to check the status until it is complete
160- # Waits before the first check to prevent rate limitting
144+ def _wait_for_device_activity_completion (self , activity_id : str ) -> OrgDeviceActivity :
161145 time .sleep (10 )
162- activity_response = self .abm .get_device_activity (unassign_response . data . id , self .access_token .value )
146+ activity_response = self .abm .get_device_activity (activity_id , self .access_token .value )
163147 retry = 0
164148 while activity_response .data .attributes .status == 'IN_PROGRESS' and retry < 5 :
165149 time .sleep (10 * retry )
166150 retry += 1
167- activity_response = self .abm .get_device_activity (unassign_response .data .id , self .access_token .value )
168-
151+ activity_response = self .abm .get_device_activity (activity_id , self .access_token .value )
169152 return activity_response .data
153+
154+ @ensure_valid_token
155+ def assign_unassign_device_to_mdm_server (
156+ self , device_ids : List [str ], server_id : str , action : str
157+ ) -> OrgDeviceActivity :
158+ response = self .abm .assign_unassign_device_to_mdm_server (
159+ device_ids , server_id , action , self .access_token .value
160+ )
161+ return self ._wait_for_device_activity_completion (response .data .id )
0 commit comments