1#!/usr/bin/env python3.4 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"""This is the controller module for Pixel Buds devices. 18 19For the device definition, see buds_lib.apollo_lib. 20""" 21 22from acts.controllers.buds_lib.apollo_lib import ParentDevice 23 24 25MOBLY_CONTROLLER_CONFIG_NAME = 'BudsDevice' 26ACTS_CONTROLLER_REFERENCE_NAME = 'buds_devices' 27 28 29class ConfigError(Exception): 30 """Raised when the configuration is malformatted.""" 31 32 33def create(configs): 34 """Creates a Pixel Buds device for each config found within the configs. 35 36 Args: 37 configs: The configs can be structured in the following ways: 38 39 ['serial1', 'serial2', ... ] 40 41 [ 42 { 43 'serial': 'serial1', 44 'label': 'some_info', 45 ... 46 }, 47 { 48 'serial': 'serial2', 49 'label': 'other_info', 50 ... 51 } 52 ] 53 """ 54 created_controllers = [] 55 56 if not isinstance(configs, list): 57 raise ConfigError('Malformatted config %s. Must be a list.' % configs) 58 59 for config in configs: 60 if isinstance(config, str): 61 created_controllers.append(ParentDevice(config)) 62 elif isinstance(config, dict): 63 serial = config.get('serial', None) 64 if not serial: 65 raise ConfigError('Buds Device %s is missing entry "serial".' % 66 config) 67 created_controllers.append(ParentDevice(serial)) 68 else: 69 raise ConfigError('Malformatted config: "%s". Must be a string or ' 70 'dict' % config) 71 return created_controllers 72 73 74def destroy(buds_device_list): 75 pass 76 77 78def get_info(buds_device_list): 79 device_infos = [] 80 for buds_device in buds_device_list: 81 device_infos.append({'serial': buds_device.serial_number, 82 'name': buds_device.device_name}) 83 return device_infos 84