1#!/usr/bin/env python3 2# 3# Copyright 2017 - 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_ON_WAIT_TIME = 2 23POWER_OFF_WAIT_TIME = 6 24 25 26class Buttons(enum.Enum): 27 POWER = 'Power' 28 PAIR = 'Pair' 29 30 31class SonyXB2Speaker(BluetoothRelayDevice): 32 """Sony XB2 Bluetooth Speaker model 33 34 Wraps the button presses, as well as the special features like pairing. 35 """ 36 37 def __init__(self, config, relay_rig): 38 BluetoothRelayDevice.__init__(self, config, relay_rig) 39 self._ensure_config_contains_relays(button.value for button in Buttons) 40 41 def _hold_button(self, button, seconds): 42 self.hold_down(button.value) 43 time.sleep(seconds) 44 self.release(button.value) 45 46 def power_on(self): 47 self._hold_button(Buttons.POWER, POWER_ON_WAIT_TIME) 48 49 def power_off(self): 50 self._hold_button(Buttons.POWER, POWER_OFF_WAIT_TIME) 51 52 def enter_pairing_mode(self): 53 self._hold_button(Buttons.PAIR, PAIRING_MODE_WAIT_TIME) 54 55 def setup(self): 56 """Sets all relays to their default state (off).""" 57 BluetoothRelayDevice.setup(self) 58 59 def clean_up(self): 60 """Sets all relays to their default state (off).""" 61 BluetoothRelayDevice.clean_up(self) 62