Home | History | Annotate | Download | only in relay_lib
      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.
     16 """
     17 Device Details:
     18 https://www.logitech.com/en-in/product/bluetooth-audio-adapter#specification-tabular
     19 """
     20 import enum
     21 from acts.controllers.relay_lib.errors import RelayConfigError
     22 from acts.controllers.relay_lib.generic_relay_device import GenericRelayDevice
     23 from acts.controllers.relay_lib.helpers import validate_key
     24 
     25 PAIRING_MODE_WAIT_TIME = 5
     26 WAIT_TIME = 0.1
     27 MISSING_RELAY_MSG = 'Relay config for logitech Headset "%s" missing relay "%s".'
     28 
     29 
     30 class Buttons(enum.Enum):
     31     Power = "Power"
     32     Pair = "Pair"
     33 
     34 
     35 class LogitechAudioReceiver(GenericRelayDevice):
     36     def __init__(self, config, relay_rig):
     37         GenericRelayDevice.__init__(self, config, relay_rig)
     38         self.mac_address = validate_key('mac_address', config, str,
     39                                         'LogitechAudioReceiver')
     40         for button in Buttons:
     41             self.ensure_config_contains_relay(button.value)
     42 
     43     def setup(self):
     44         GenericRelayDevice.setup(self)
     45 
     46     def clean_up(self):
     47         """Sets all relays to their default state (off)."""
     48         GenericRelayDevice.clean_up(self)
     49 
     50     def ensure_config_contains_relay(self, relay_name):
     51         """
     52         Throws an error if the relay does not exist.
     53 
     54         Args:
     55             relay_name:relay_name to be checked.
     56         """
     57         if relay_name not in self.relays:
     58             raise RelayConfigError(MISSING_RELAY_MSG % (self.name, relay_name))
     59 
     60     def power_on(self):
     61         """Power on relay."""
     62         self.relays[Buttons.Power.value].set_nc()
     63 
     64     def pairing_mode(self):
     65         """Sets relay in paring mode."""
     66         self.relays[Buttons.Pair.value].set_nc()
     67