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 enum 17import time 18 19from acts.controllers.relay_lib.devices.bluetooth_relay_device import BluetoothRelayDevice 20 21PAIRING_MODE_WAIT_TIME = 5 22POWER_TOGGLE_WAIT_TIME = 1 23 24 25class Buttons(enum.Enum): 26 POWER = 'Power' 27 28 29class Skullcandy(BluetoothRelayDevice): 30 """Skullcandy Bluetooth Speaker model 31 32 Wraps the button presses, as well as the special features like pairing. 33 """ 34 35 def __init__(self, config, relay_rig): 36 BluetoothRelayDevice.__init__(self, config, relay_rig) 37 self._ensure_config_contains_relays(button.value for button in Buttons) 38 39 def _hold_button(self, button, seconds): 40 self.hold_down(button.value) 41 time.sleep(seconds) 42 self.release(button.value) 43 44 def power_off(self): 45 self._hold_button(Buttons.POWER, POWER_TOGGLE_WAIT_TIME) 46 47 def turn_power_on_and_enter_pairing_mode(self): 48 self._hold_button(Buttons.POWER, PAIRING_MODE_WAIT_TIME) 49 50 def setup(self): 51 """Sets all relays to their default state (off).""" 52 BluetoothRelayDevice.setup(self) 53 54 def clean_up(self): 55 """Sets all relays to their default state (off).""" 56 BluetoothRelayDevice.clean_up(self) 57