1#!/usr/bin/env python3 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 21POWER_TOGGLE_WAIT_TIME = 0.5 22 23class Buttons(enum.Enum): 24 POWER = 'Power' 25 26 27class PowerSupply(BluetoothRelayDevice): 28 """Power Supply for Headset. 29 30 Wraps the button presses. 31 """ 32 def __init__(self, config, relay_rig): 33 BluetoothRelayDevice.__init__(self, config, relay_rig) 34 self._ensure_config_contains_relays(button.value for button in Buttons) 35 36 def _hold_button(self, button, seconds): 37 self.hold_down(button.value) 38 time.sleep(seconds) 39 self.release(button.value) 40 41 def power_off(self): 42 self._hold_button(Buttons.POWER, POWER_TOGGLE_WAIT_TIME) 43 44 def setup(self): 45 """Do nothing, since this is not a headset""" 46 return True 47 48 def clean_up(self): 49 """Do nothing, since this is not a headset""" 50 return True 51