1 #!/usr/bin/env python 2 # 3 # Copyright 2016 - The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 import json 18 19 from acts.controllers.relay_lib.relay_rig import RelayRig 20 21 ACTS_CONTROLLER_CONFIG_NAME = "RelayDevice" 22 ACTS_CONTROLLER_REFERENCE_NAME = "relay_devices" 23 24 25 def create(config): 26 """Creates RelayDevice controller objects. 27 28 Args: 29 config: A dict of: 30 config_path: The path to the RelayDevice config file. 31 devices: A list of configs or names associated with the devices. 32 33 Returns: 34 A list of RelayDevice objects. 35 """ 36 devices = list() 37 with open(config) as json_file: 38 relay_rig = RelayRig(json.load(json_file)) 39 40 for device in relay_rig.devices.values(): 41 devices.append(device) 42 43 return devices 44 45 46 def destroy(relay_devices): 47 """Cleans up RelayDevice objects. 48 49 Args: 50 relay_devices: A list of AndroidDevice objects. 51 """ 52 for device in relay_devices: 53 device.clean_up() 54 pass 55 56 57 def get_info(relay_devices): 58 """Get information on a list of RelayDevice objects. 59 60 Args: 61 relay_devices: A list of RelayDevice objects. 62 63 Returns: 64 A list of dict, each representing info for an RelayDevice objects. 65 """ 66 device_info = [] 67 for device in relay_devices: 68 relay_ids = list() 69 for relay in device.relays: 70 relay_ids.append(relay) 71 info = {"name": device.name, "relays": relay_ids} 72 device_info.append(info) 73 return device_info 74