Best Python code snippet using fMBT_python
device_operation.py
Source:device_operation.py
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'é¨ç¦æ§å¶å¨ä¸å
许å½åæä½ï¼'))...
Refresh_device_info.py
Source:Refresh_device_info.py
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:...
RefreshDeviceInfo.py
Source:RefreshDeviceInfo.py
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:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!