How to use refreshDeviceInfo method in fMBT

Best Python code snippet using fMBT_python

device_operation.py

Source:device_operation.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from django.conf import settings3from base.operation import ModelOperation,Operation4from django.utils.translation import ugettext_lazy as _5from mysite.iclock.models.model_device import Device,DEVICE_POS_SERVER6from mysite.utils import get_option 7from model_device import DEVICE_TIME_RECORDER ,DEVICE_ACCESS_CONTROL_PANEL ,DEVICE_ACCESS_CONTROL_DEVICE ,DEVICE_VIDEO_SERVER,DEVICE_POS_SERVER ,DEVICE_CAMERA_SERVER 8class Syncdata(Operation):9 #help_text = _(u"""同步所有数据主要用来将服务器中的数据同步到设备中,一般情况下只有在由于客观因素(如网络异常或其他情况)导致设备中数据和服务器不一致时才需要使用该操作。由于该操作会先将设备中的既有数据删除掉,然后同步新的数据,所以删除数据的过程势必会导致设备脱机使用受到一定程度的影响,所以建议用户使用该操作时尽量选择好时机,以免影响设备正常使用。""")10 help_text = _(u"""将服务器中的数据同步到设备中,一般情况下只有在由于客观因素(如网络异常或其他情况)导致设备中数据和服务器不一致时才需要使用该操作。""")11 verbose_name = _(u"""同步软件数据到设备""")12 perm_model_menu = ['iclock.Device','att.AttDeviceDataManage', 'pos.PosDeviceDataManage']13 only_one_object = True14 from base.sync_api import SYNC_MODEL15 def action(self):16 if get_option("POS_ID") and self.object.device_type==DEVICE_POS_SERVER:17 raise Exception(_(u'消费机不允许当前操作!'))18 else:19 #d_server = start_dict_server()20 if self.object.device_type==DEVICE_TIME_RECORDER:21 from base.sync_api import SYNC_MODEL,do_spread_device_employee22 if SYNC_MODEL:23 do_spread_device_employee(self.object)24 else:25 from model_cmmdata import adj_device_cmmdata,sync_for_server26 sync_for_server(self.object,self.object.area)27 elif self.object.device_type==DEVICE_POS_SERVER:28 self.object.set_all_pos_data()29 else: 30 if not self.object.enabled:31 raise Exception(_(u'设备已被禁用!'))32 self.object.set_all_data()#考勤门禁通用33Device.Syncdata = Syncdata34class SyncACPanelTime(Operation):35 verbose_name = _(u"""同步时间""")36 help_text = _(u"""同步设备时间为服务器时间。""")37 perm_model_menu = ['iclock.Device','pos.PosDeviceDataManage', 'iaccess.DoorSetPage','pos.PosDeviceDataManage']38 def action(self):39 if self.object.device_type == DEVICE_ACCESS_CONTROL_PANEL:40 if not self.object.enabled:41 raise Exception(_(u'设备已被禁用!'))42 self.object.set_time()43 if get_option("POS_IC") and self.object.device_type == DEVICE_POS_SERVER :44 dt = datetime.datetime.now().strftime('%Y%m%d%H%M%S')45 CMD="SET OPTION Time=%s\t\n"%(dt)46 self.object.appendcmd(CMD) 47 #else:48 #raise Exception(_(u"设备:%s 并非门禁控制器,该操作只能同步门禁控制器时间")%self.object.alias)49Device.SyncACPanelTime = SyncACPanelTime50class RefreshDeviceInfo(Operation):51 help_text = _(u"""获取设备信息""")52 verbose_name = _(u"""获取设备信息""")53 perm_model_menu = ['iclock.Device','att.AttDeviceDataManage','iclock.Device']54 def action(self):55 if self.object.device_type == DEVICE_POS_SERVER :56 raise Exception(_(u'消费机不允许当前操作!'))57 else:58 if self.object.device_type!=DEVICE_ACCESS_CONTROL_PANEL:59 from base.sync_api import SYNC_MODEL, do_get_info60 if SYNC_MODEL:61 do_get_info(self.object.sn)62 else:63 self.object.appendcmd("INFO")64Device.RefreshDeviceInfo = RefreshDeviceInfo65class Reboot(Operation):66 verbose_name = _(u"""重启设备""")67 help_text = _(u"""重启设备""")68 perm_model_menu = ['iclock.Device','att.AttDeviceDataManage', 'pos.PosDeviceDataManage']69 70 def action(self):71 if get_option("POS_ID") and self.object.device_type == DEVICE_POS_SERVER :72 raise Exception(_(u'消费机不允许当前操作!'))73 else:74 if self.object.device_type!=DEVICE_ACCESS_CONTROL_PANEL:75 from base.sync_api import SYNC_MODEL, do_reboot_device76 if SYNC_MODEL and self.object.device_type == DEVICE_TIME_RECORDER:77 do_reboot_device(self.object.sn)78 else:79 self.object.appendcmd("REBOOT")80 else:81 raise Exception(_(u'门禁控制器不允许当前操作!'))...

Full Screen

Full Screen

Refresh_device_info.py

Source:Refresh_device_info.py Github

copy

Full Screen

1import requests,json2baseurl="https://suremdm.42gears.com/api" # BaseURL of SureMDM3Username="Username"4Password="Password"5ApiKey="Your ApiKey"6# Method for getting device info7def GetDeviceID(deviceName):8 '''9 Retreiving information of device10 Endpoint: /device11 Method: POST12 Request Body:13 { 14 "ID": string,15 "SearchValue":string,16 "Limit":integer,17 "SortColumn":string,18 "SortOrder":string,19 "IsSearch":boolean,20 "SearchColumns":string[]21 }22 Authentication:23 Basic authentication24 Headers:25 ApiKey: “Your Api-Key”26 '''27 # Api url28 url = baseurl+"/device"29 # Headers30 headers = {31 # Api-Key header32 'ApiKey': ApiKey,33 # Set Content type34 'Content-Type': "application/json",35 }36 # Basic authentication credentials37 Credentials=(Username,Password)38 # Request body39 PayLoad={40 "ID" : "AllDevices",41 "IsSearch" : bool(1),42 "Limit" : 10,43 "SearchColumns" : ["DeviceName"],44 "SearchValue" : deviceName,45 "SortColumn" : "LastTimeStamp",46 "SortOrder" : "asc"47 }48 # Executing request49 response = requests.post(url,auth=Credentials,json=PayLoad,headers=headers)50 # Extracting required GroupID51 if response.status_code == 200:52 if response.text != '[]':53 data = response.json()54 for device in data['rows']:55 if device['DeviceName'] == deviceName:56 return device["DeviceID"]57 else:58 return None59# Method to apply dynamic jobs60def RefreshDeviceInfo(deviceID):61 '''62 Api to apply dynamic jobs63 Endpoint: /dynamicjob64 Method: POST65 Request Body:66 {67 "JobType":string,68 "DeviceID":string69 }70 Authentication:71 Basic authentication72 Headers:73 ApiKey: “Your Api-Key”74 '''75 PayLoad={76 "JobType": "Refresh_Device",77 "DeviceID": deviceID78 }79 # Api url80 url = baseurl+"/dynamicjob"81 # Headers82 headers = {83 # Api-Key header84 'ApiKey': ApiKey,85 # Set Content type86 'Content-Type': "application/json",87 }88 # Basic authentication credentials89 Credentials=(Username,Password)90 # Executing request91 response = requests.post(url,auth=Credentials,json=PayLoad,headers=headers)92 return response.text93# Main94DeviceID=GetDeviceID("Device_Name")95if DeviceID!=None:96 status=RefreshDeviceInfo(DeviceID)97 print(status)98else:...

Full Screen

Full Screen

RefreshDeviceInfo.py

Source:RefreshDeviceInfo.py Github

copy

Full Screen

1import requests,json2baseurl="https://suremdm.42gears.com/api" # BaseURL of SureMDM3Username="Username"4Password="Password"5ApiKey="Your ApiKey"6# Method for getting device info7def GetDeviceID(deviceName):8 # Api url9 url = baseurl+"/device"10 # Headers11 headers = {12 # Api-Key header13 'ApiKey': ApiKey,14 # Set Content type15 'Content-Type': "application/json",16 }17 # Basic authentication credentials18 Credentials=(Username,Password)19 # Request body20 PayLoad={21 "ID" : "AllDevices",22 "IsSearch" : bool(1),23 "Limit" : 10,24 "SearchColumns" : ["DeviceName"],25 "SearchValue" : deviceName,26 "SortColumn" : "LastTimeStamp",27 "SortOrder" : "asc"28 }29 # Executing request30 response = requests.post(url,auth=Credentials,json=PayLoad,headers=headers)31 # Extracting required GroupID32 if response.status_code == 200:33 if response.text != '[]':34 data = response.json()35 for device in data['rows']:36 if device['DeviceName'] == deviceName:37 return device["DeviceID"]38 else:39 return None40# Method to apply dynamic jobs41def RefreshDeviceInfo(deviceID):42 PayLoad={43 "JobType": "Refresh_Device",44 "DeviceID": deviceID45 }46 # Api url47 url = baseurl+"/dynamicjob"48 # Headers49 headers = {50 # Api-Key header51 'ApiKey': ApiKey,52 # Set Content type53 'Content-Type': "application/json",54 }55 # Basic authentication credentials56 Credentials=(Username,Password)57 # Executing request58 response = requests.post(url,auth=Credentials,json=PayLoad,headers=headers)59 return response.text60# Main starts61deviceName="device 1" #Name of the device 62DeviceID=GetDeviceID(deviceName)63if DeviceID!=None:64 status=RefreshDeviceInfo(DeviceID)65 print(status)66else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful