How to use device_status method in Airtest

Best Python code snippet using Airtest

collect_handle.py

Source:collect_handle.py Github

copy

Full Screen

...23def get_all_app_no_virtual():24 # 获取所有应用非宿主机的个数25 ret = models.IDCPhysical.objects.filter(server_type=u"非宿主机").count()26 return ret27def get_no_user_device_status():28 # 获取所有下线报废的数量29 ret = models.IDCPhysical.objects.filter(device_status__in=[u"下线", u"报废"]).count()30 return ret31def get_all_vhost_online():32 # 获取所有宿主机、在线的数量33 ret = models.IDCPhysical.objects.filter(server_type=u"宿主机", device_status=u"在线").count()34 return ret35def get_all_host_online():36 # 获取所有非宿主机、在线的数量37 ret = models.IDCPhysical.objects.filter(server_type=u"非宿主机", device_status=u"在线").count()38 return ret39def get_all_host_downline():40 # 获取所有非宿主机、下线的数量41 ret = models.IDCPhysical.objects.filter(server_type=u"非宿主机", device_status=u"下线").count()42 return ret43def get_all_vhost_downline():44 # 获取所有宿主机、下线的数量45 ret = models.IDCPhysical.objects.filter(server_type=u"宿主机", device_status=u"下线").count()46 return ret47def get_all_host_not_use():48 # 获取所有非宿主机、报废的数量49 ret = models.IDCPhysical.objects.filter(server_type=u"非宿主机", device_status=u"报废").count()50 return ret51def get_all_vhost_not_use():52 # 获取所有宿主机、报废的数量53 ret = models.IDCPhysical.objects.filter(server_type=u"宿主机", device_status=u"报废").count()54 return ret55def get_can_virtual_online():56 # 获取所有可虚拟化、在线的数量57 ret = models.IDCPhysical.objects.filter(is_virtual=u"是", device_status=u"在线").count()58 return ret59def get_can_virtual_offline():60 # 获取所有可虚拟化、下线的数量61 ret = models.IDCPhysical.objects.filter(is_virtual=u"是", device_status=u"下线").count()62 return ret63def get_can_virtual_scrap():64 # 获取所有可虚拟化、报废的数量65 ret = models.IDCPhysical.objects.filter(is_virtual=u"是", device_status=u"报废").count()66 return ret67def get_not_virtual_online():68 # 获取所有可虚拟化、在线的数量69 ret = models.IDCPhysical.objects.filter(is_virtual=u"否", device_status=u"在线").count()70 return ret71def get_not_virtual_offline():72 # 获取所有可虚拟化、下线的数量73 ret = models.IDCPhysical.objects.filter(is_virtual=u"否", device_status=u"下线").count()74 return ret75def get_not_virtual_scrap():76 # 获取所有可虚拟化、报废的数量77 ret = models.IDCPhysical.objects.filter(is_virtual=u"否", device_status=u"报废").count()78 return ret79def get_idc_device_status(idc_name):80 # 获取各个机房不同状态的设备数量 (在线 下线 报废)81 online = models.IDCPhysical.objects.filter(idc=idc_name, device_status=u"在线").count()82 offline = models.IDCPhysical.objects.filter(idc=idc_name, device_status=u"下线").count()83 scrap = models.IDCPhysical.objects.filter(idc=idc_name, device_status=u"报废").count()84 return online, offline, scrap85def get_brand_status(device_name):86 # 获取各个品牌服务器不同状态的设备数量 (在线 下线 报废)87 online = models.IDCPhysical.objects.filter(brand=device_name, device_status=u"在线").count()88 offline = models.IDCPhysical.objects.filter(brand=device_name, device_status=u"下线").count()89 scrap = models.IDCPhysical.objects.filter(brand=device_name, device_status=u"报废").count()...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

1import logging2import boto33import uuid4import json5logger = logging.getLogger()6logger.setLevel(logging.ERROR)7def lambda_handler(event, context):8 thing_name = event['thing_name']9 timestamp = event['update']['timestamp']10 current_record = event['update']['current']['state']['desired']11 if 'device_status' not in current_record:12 logger.error('Shadow has no "device_status" field')13 return { 'statusCode': 200 }14 else:15 device_status = current_record['device_status']16 logger.info('Thing: %s State: %s Time: %s', thing_name, current_record, timestamp)17 iot_client = boto3.client('iotanalytics')18 uid = uuid.uuid4()19 entry = {}20 entry['thing_name'] = thing_name21 entry['timestamp'] = timestamp22 if 'last_gps_location' in device_status:23 gps = device_status['last_gps_location']24 entry['last_gps_fix_longitude'] = gps['longitude']25 entry['last_gps_fix_latitude'] = gps['latitude']26 entry['last_gps_fix_time'] = gps['timestamp']27 if 'last_cellular_connected_timestamp' in device_status:28 ts = device_status['last_cellular_connected_timestamp']29 entry['last_cellular_connection'] = ts30 if 'last_sat_tx_timestamp' in device_status:31 ts = device_status['last_sat_tx_timestamp']32 entry['last_sat_tx'] = ts33 if 'next_sat_tx_timestamp' in device_status:34 ts = device_status['next_sat_tx_timestamp']35 entry['next_sat_tx'] = ts36 if 'battery_level' in device_status:37 n = device_status['battery_level']38 entry['battery_level'] = n39 if 'battery_voltage' in device_status:40 n = device_status['battery_voltage']41 entry['battery_voltage'] = n42 if 'configuration_version' in device_status:43 n = device_status['configuration_version']44 entry['config_version'] = n45 if 'firmware_version' in device_status:46 n = device_status['firmware_version']47 entry['fw_version'] = n48 if 'last_log_file_read_pos' in device_status:49 n = device_status['last_log_file_read_pos']50 entry['last_log_read_pos'] = n51 resp = iot_client.batch_put_message(channelName='arribada_device_status',52 messages=[{53 'messageId': str(uid),54 'payload': json.dumps(entry)55 }56 ])57 logger.debug('resp=%s', resp)...

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 Airtest 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