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.
16
17import enum
18
19from acts.controllers.relay_lib.errors import RelayConfigError
20from acts.controllers.relay_lib.devices.bluetooth_relay_device import BluetoothRelayDevice
21
22PAIRING_MODE_WAIT_TIME = 3
23WAIT_TIME = 0.1
24MISSING_RELAY_MSG = 'Relay config for i6s Headset "%s" missing relay "%s".'
25
26
27class Buttons(enum.Enum):
28    POWER = "Power"
29    NEXT = 'Next'
30    PREVIOUS = "Previous"
31    PLAY_PAUSE = 'Play_pause'
32    PAIR = "Pair"
33    VOLUME_UP = "Volume_up"
34    VOLUME_DOWN = "Volume_down"
35
36
37class I6sHeadset(BluetoothRelayDevice):
38
39    def __init__(self, config, relay_rig):
40        BluetoothRelayDevice.__init__(self, config, relay_rig)
41        self._ensure_config_contains_relays(button.value for button in Buttons)
42
43    def setup(self):
44        """Sets all relays to their default state (off)."""
45        BluetoothRelayDevice.setup(self)
46
47    def clean_up(self):
48        """Turns off headset."""
49        self.relays[Buttons.PAIR.value].set_no_for(PAIRING_MODE_WAIT_TIME)
50
51    def enter_pairing_mode(self):
52        """Sets relay in paring mode."""
53        self.relays[Buttons.PAIR.value].set_no_for(PAIRING_MODE_WAIT_TIME)
54
55    def power_on(self):
56        """Power on relay."""
57        self.relays[Buttons.POWER.value].set_no_for(WAIT_TIME)
58
59    def press_play_pause(self):
60        """
61        Sets relay to
62            Play state : if there is no A2DP_streaming.
63            Pause state : if there is A2DP_streaming.
64        """
65        self.relays[Buttons.PLAY_PAUSE.value].set_no_for(WAIT_TIME)
66
67    def press_next(self):
68        """Skips to next song from relay_device."""
69        self.relays[Buttons.NEXT.value].set_no_for(WAIT_TIME)
70
71    def press_previous(self):
72        """Skips to previous song from relay_device."""
73        self.relays[Buttons.PREVIOUS.value].set_no_for(WAIT_TIME)
74
75    def press_volume_up(self):
76        """Increases volume from relay_device."""
77        self.relays[Buttons.VOLUME_UP.value].set_no_for(WAIT_TIME)
78
79    def press_volume_down(self):
80        """Decreases volume from relay_device."""
81        self.relays[Buttons.VOLUME_DOWN.value].set_no_for(WAIT_TIME)
82
83    def press_initiate_call(self):
84        """Initiate call from relay device."""
85        for i in range(0, 2):
86            self.relays[Buttons.POWER.value].set_no_for(WAIT_TIME)
87        return True
88
89    def press_accept_call(self):
90        """Accepts call from relay device."""
91        self.relays[Buttons.POWER.value].set_no_for(WAIT_TIME)
92        return True
93