def get_device_for_enterprise(enterprise_id): api_instance = esperclient.DeviceApi(esperclient.ApiClient(configuration)) try: api_response = api_instance.get_all_devices(enterprise_id) except ApiException as e: print("Exception when calling DeviceApi->get_all_devices: %s\n" % e) return api_response.results[0].id
def get_package_id(device_id, package_name): api_instance = esperclient.DeviceApi(esperclient.ApiClient(CONFIGURATION)) response = api_instance.get_app_installs(ENTERPRISE_ID, device_id, package_name=package_name) if response and response.count > 0: print("getting package id for package_name") app_id = response.results[0].application.version.app_version_id if app_id: return response.results[0].application.version.app_version_id return None
def test_device_detail(): api_instance = esperclient.DeviceApi(esperclient.ApiClient(configuration)) try: # Fetch device details by ID api_response = api_instance.get_device_by_id(enterprise_id, device_id) # print(api_response) except ApiException as e: print("Exception when calling DeviceApi->get_device_by_id: %s\n" % e) assert api_response.id is not None, "Id cannot be null"
def setAppStateForAllAppsListed(state, maxAttempt=Globals.MAX_RETRY): api_instance = esperclient.DeviceApi( esperclient.ApiClient(Globals.configuration)) api_response = None for attempt in range(maxAttempt): try: api_response = api_instance.get_all_devices( Globals.enterprise_id, limit=Globals.limit, offset=Globals.offset, ) break except Exception as e: if attempt == maxAttempt - 1: postEventToFrame( wxThread.myEVT_LOG, "---> ERROR: Failed to get devices ids to modify tags and aliases", ) print(e) ApiToolLog().LogError(e) return time.sleep(Globals.RETRY_SLEEP) deviceIdentifers = Globals.frame.gridPanel.getDeviceIdentifersFromGrid() if api_response: tempRes = [] for device in api_response.results: for deviceIds in deviceIdentifers: if (device.device_name in deviceIds or device.hardware_info["serialNumber"] in deviceIds): tempRes.append(device) if tempRes: api_response.results = tempRes threads = [] for device in api_response.results: if (device.device_name in deviceIdentifers or device.hardware_info["serialNumber"] in deviceIdentifers): t = wxThread.GUIThread( Globals.frame, setAllAppsState, args=(Globals.frame, device, state), name="setAllAppsState", ) threads.append(t) t.start() limitActiveThreads(threads) t = wxThread.GUIThread( Globals.frame, waitTillThreadsFinish, args=(tuple(threads), state, -1, 4), name="waitTillThreadsFinish%s" % state, ) t.start()
def __init__(self, host, key, eid): self.eid = eid self.configuration = esperclient.Configuration() self.configuration.host = f"https://{host}-api.esper.cloud/api" self.configuration.api_key['Authorization'] = key self.configuration.api_key_prefix['Authorization'] = 'Bearer' self.app_api_instance = esperclient.ApplicationApi( esperclient.ApiClient(self.configuration)) self.cmd_api_instance = esperclient.CommandsV2Api( esperclient.ApiClient(self.configuration)) self.dev_api_instance = esperclient.DeviceApi( esperclient.ApiClient(self.configuration))
def test_device_app_list(): api_instance = esperclient.DeviceApi(esperclient.ApiClient(configuration)) #package_name = 'com.android.calculator2' # str | Filter by Package name (optional) #whitelisted = False # str | Whitelist filter (optional) try: # List all device apps api_response = api_instance.get_device_apps(enterprise_id, device_id) #print(api_response) except ApiException as e: print("Exception when calling DeviceApi->get_device_apps: %s\n" % e) assert api_response.count > 0, "No apps present on device"
def test_device_status(): api_instance = esperclient.DeviceApi(esperclient.ApiClient(configuration)) latest_event = 1 # float | Flag to get latest event try: # Get latest device event api_response = api_instance.get_device_event(enterprise_id, device_id, latest_event) # print(api_response) except ApiException as e: print("Exception when calling DeviceApi->get_device_event: %s\n" % e) assert api_response.count == 1, "Device not sending status events" assert api_response.results[0].id is not None
def getAllDevices(groupToUse, maxAttempt=Globals.MAX_RETRY): """ Make a API call to get all Devices belonging to the Enterprise """ if not groupToUse: return None try: api_instance = esperclient.DeviceApi( esperclient.ApiClient(Globals.configuration)) api_response = None if type(groupToUse) == list: for group in groupToUse: for attempt in range(maxAttempt): try: response = api_instance.get_all_devices( Globals.enterprise_id, group=group, limit=Globals.limit, offset=Globals.offset, ) break except Exception as e: if attempt == maxAttempt - 1: ApiToolLog().LogError(e) raise e time.sleep(Globals.RETRY_SLEEP) if not api_response: api_response = response else: api_response.results = api_response.results + response.results else: for attempt in range(maxAttempt): try: api_response = api_instance.get_all_devices( Globals.enterprise_id, group=groupToUse, limit=Globals.limit, offset=Globals.offset, ) break except Exception as e: if attempt == maxAttempt - 1: ApiToolLog().LogError(e) raise e time.sleep(Globals.RETRY_SLEEP) postEventToFrame(wxThread.myEVT_LOG, "---> Device API Request Finished") return api_response except ApiException as e: raise Exception( "Exception when calling DeviceApi->get_all_devices: %s\n" % e)
def test_device_list(): api_instance = esperclient.DeviceApi(esperclient.ApiClient(configuration)) # name = 'name_example' # str | Filter by device name (optional) # search = 'search_example' # str | A search term. Search by device name or imei (optional) # limit = 20 # int | Number of results to return per page. (optional) (default to 20) # offset = 56 # int | The initial index from which to return the results. (optional) try: # Fetch all devices in an enterprise api_response = api_instance.get_all_devices(enterprise_id) # print(api_response) except ApiException as e: print("Exception when calling DeviceApi->get_all_devices: %s\n" % e) assert api_response.count > 0, "Atleast one device is needed for testing" assert api_response.results[0].id is not None, "Id cannot be null"
def get_devices_in_group(group_id): # create an instance of the API class api_instance = esperclient.DeviceApi(esperclient.ApiClient(CONFIGURATION)) try: api_response = api_instance.get_all_devices( ENTERPRISE_ID, group=group_id, limit=CONFIGURATION.per_page_limit, offset=CONFIGURATION.per_page_offset) if len(api_response.results): for device in api_response.results: if device.status == 1: # Check for active devices only ACTIVE_DEVICE_LIST.append(device) else: INACTIVE_DEVICE_LIST.append(device) except ApiException as api_exception: print("Exception when calling DeviceApi->get_all_devices: %s\n" % api_exception)
def test_device_app_installs(): # create an instance of the API class api_instance = esperclient.DeviceApi(esperclient.ApiClient(configuration)) #device = 'device_example' # str | filter by device id (optional) #package_name = 'package_name_example' # str | filter by package name (optional) #application_name = 'application_name_example' # str | filter by application name (optional) #install_state = 'install_state_example' # str | filter by install state (optional) #limit = 20 # int | Number of results to return per page. (optional) (default to 20) #offset = 56 # int | The initial index from which to return the results. (optional) #device_id = 'cd2d9e3b-953c-482f-abbc-168910851bad' try: api_response = api_instance.get_app_installs(enterprise_id, device_id) # print(api_response) except ApiException as e: print("Exception when calling DeviceApi->get_app_installs: %s\n" % e) assert api_response.count is not None assert isinstance(api_response.results, list)
def getDeviceById(deviceToUse, maxAttempt=Globals.MAX_RETRY): """ Make a API call to get a Device belonging to the Enterprise by its Id """ try: api_instance = esperclient.DeviceApi( esperclient.ApiClient(Globals.configuration)) api_response_list = [] api_response = None if type(deviceToUse) == list: for device in deviceToUse: for attempt in range(maxAttempt): try: api_response = api_instance.get_device_by_id( Globals.enterprise_id, device_id=device) break except Exception as e: if attempt == maxAttempt - 1: ApiToolLog().LogError(e) raise e time.sleep(Globals.RETRY_SLEEP) if api_response: api_response_list.append(api_response) else: for attempt in range(maxAttempt): try: api_response = api_instance.get_device_by_id( Globals.enterprise_id, device_id=deviceToUse) break except Exception as e: if attempt == maxAttempt - 1: ApiToolLog().LogError(e) raise e time.sleep(Globals.RETRY_SLEEP) if api_response and api_response_list: api_response.results = api_response_list elif api_response: api_response.results = [api_response] postEventToFrame(wxThread.myEVT_LOG, "---> Device API Request Finished") return api_response except ApiException as e: print("Exception when calling DeviceApi->get_device_by_id: %s\n" % e) ApiToolLog().LogError(e)
def executeDeviceModification(frame, maxAttempt=Globals.MAX_RETRY): """ Attempt to modify device data according to what has been changed in the Grid """ api_instance = esperclient.DeviceApi( esperclient.ApiClient(Globals.configuration)) api_response = None for attempt in range(maxAttempt): try: api_response = api_instance.get_all_devices( Globals.enterprise_id, limit=Globals.limit, offset=Globals.offset, ) break except Exception as e: if attempt == maxAttempt - 1: postEventToFrame( wxThread.myEVT_LOG, "---> ERROR: Failed to get devices ids to modify tags and aliases", ) print(e) ApiToolLog().LogError(e) return time.sleep(Globals.RETRY_SLEEP) tagsFromGrid = frame.gridPanel.getDeviceTagsFromGrid() aliasDic = frame.gridPanel.getDeviceAliasFromList() frame.gauge.SetValue(1) maxGaugeAction = len(tagsFromGrid.keys()) + len(aliasDic.keys()) if api_response: tempRes = list( filter(lambda x: x.device_name in tagsFromGrid.keys(), api_response.results)) if not tempRes: if "serialNumber" in api_response.results[0].hardware_info: tempRes = list( filter( lambda x: x.hardware_info["serialNumber"] in tagsFromGrid.keys(), api_response.results, )) if tempRes: api_response.results = tempRes splitResults = splitListIntoChunks(api_response.results) threads = [] for chunk in splitResults: t = wxThread.GUIThread( frame, processDeviceModificationForList, args=(frame, chunk, tagsFromGrid, aliasDic, maxGaugeAction), name="processDeviceModificationForList", ) threads.append(t) t.start() t = wxThread.GUIThread( frame, waitTillThreadsFinish, args=(tuple(threads), -1, -1, 2), name="waitTillThreadsFinish", ) t.start()
def get_remoteadb_api_client(self): return client.DeviceApi(client.ApiClient(self.config))
def get_device_api_client(self): return client.DeviceApi(client.ApiClient(self.config))