1#!/usr/bin/env python 2# 3# Copyright 2018 - 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. 16import time 17import enum 18 19from acts.controllers.relay_lib.devices.bluetooth_relay_device import BluetoothRelayDevice 20 21PAIRING_MODE_WAIT_TIME = 9 22POWER_TOGGLE_WAIT_TIME = 2 23 24 25class Buttons(enum.Enum): 26 POWER = 'Power' 27 28 29class Headset(BluetoothRelayDevice): 30 """Headset with same Power and Pair Button. 31 32 Wraps the button presses, as well as the special features like pairing. 33 """ 34 def __init__(self, config, relay_rig): 35 BluetoothRelayDevice.__init__(self, config, relay_rig) 36 self._ensure_config_contains_relays(button.value for button in Buttons) 37 38 def _hold_button(self, button, seconds): 39 self.hold_down(button.value) 40 time.sleep(seconds) 41 self.release(button.value) 42 43 def power_off(self): 44 self._hold_button(Buttons.POWER, POWER_TOGGLE_WAIT_TIME) 45 46 def turn_power_on_and_enter_pairing_mode(self): 47 self._hold_button(Buttons.POWER, PAIRING_MODE_WAIT_TIME) 48