Skip to content

Commit

Permalink
Added BTInput support.
Browse files Browse the repository at this point in the history
  • Loading branch information
liamw9534 committed Jun 19, 2014
1 parent 65a7d77 commit 82cafba
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ Project resources
Changelog
=========

v0.2.0
------

Added support for:

- BTInput (org.bluez.Input)

v0.1.0
------

Expand Down
3 changes: 2 additions & 1 deletion bt_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cffi
import os

__version__ = '0.1.0'
__version__ = '0.2.0'

if StrictVersion(cffi.__version__) < StrictVersion('0.7'):
raise RuntimeError(
Expand Down Expand Up @@ -35,6 +35,7 @@
from bt_manager.interface import BTInterface # noqa
from bt_manager.manager import BTManager # noqa
from bt_manager.media import BTMedia, BTMediaTransport # noqa
from bt_manager.input import BTInput # noqa
from bt_manager.serviceuuids import SERVICES # noqa
from bt_manager.uuid import BTUUID, BTUUID16, BTUUID32 # noqa
from bt_manager.uuid import BASE_UUID # noqa
Expand Down
42 changes: 42 additions & 0 deletions bt_manager/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from __future__ import unicode_literals

from device import BTGenericDevice


class BTInput(BTGenericDevice):
"""
Wrapper around dbus to encapsulate the org.bluez.Input
interface.
:Properties:
* **Connected(boolean) [readonly]**:
Indicates if the device is connected.
See also: :py:class:`.BTGenericDevice` for setup params.
"""
def __init__(self, *args, **kwargs):
BTGenericDevice.__init__(self, addr='org.bluez.Input',
*args, **kwargs)

def connect(self):
"""
Connect to the input device.
:return:
:raises dbus.Exception: org.bluez.Error.AlreadyConnected
:raises dbus.Exception: org.bluez.Error.ConnectionAttemptFailed
"""
return self._interface.Connect()

def disconnect(self):
"""
Disconnect from the input device.
To abort a connection attempt in case of errors or
timeouts in the client it is fine to call this method.
:return:
:raises dbus.Exception: org.bluez.Error.Failed
"""
return self._interface.Disconnect()
52 changes: 52 additions & 0 deletions demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,49 @@ def sink_disconnect(args):
print 'Unable to complete:', sys.exc_info()


def input_info(args):
if (len(args)):
dev_path = args.pop(0)
else:
print 'Error: Must specify device path'
return

try:
ip = bt_manager.BTInput(dev_path=dev_path)
print '========================================================='
print ip
except dbus.exceptions.DBusException:
print 'Unable to complete:', sys.exc_info()


def input_connect(args):
if (len(args)):
dev_path = args.pop(0)
else:
print 'Error: Must specify device path'
return

try:
ip = bt_manager.BTInput(dev_path=dev_path)
ip.connect()
except dbus.exceptions.DBusException:
print 'Unable to complete:', sys.exc_info()


def input_disconnect(args):
if (len(args)):
dev_path = args.pop(0)
else:
print 'Error: Must specify device path'
return

try:
sink = bt_manager.BTInput(dev_path=dev_path)
sink.disconnect()
except dbus.exceptions.DBusException:
print 'Unable to complete:', sys.exc_info()


def source_info(args):
if (len(args)):
dev_path = args.pop(0)
Expand Down Expand Up @@ -634,6 +677,15 @@ def media_stop(args):
'exit': CmdEntry(exit_cleanup,
'Cleanup and exit',
None),
'input-info': CmdEntry(input_info,
'Input device properties',
'<dev_path>'),
'input-connect': CmdEntry(input_connect,
'Input device connect',
'<dev_path>'),
'input-disconnect': CmdEntry(input_disconnect,
'Input device connect',
'<dev_path>'),
}


Expand Down
23 changes: 23 additions & 0 deletions tests/test_bt_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def __init__(self, obj, addr):
self._props = {u'Connected': False}
elif (self.addr == 'org.bluez.Media'):
pass
elif (self.addr == 'org.bluez.Input'):
self._props = {u'Connected': False}
elif (self.addr == 'org.freedesktop.DBus.Introspectable'):
self._introspect = \
"""
Expand Down Expand Up @@ -1460,3 +1462,24 @@ def test_sbc_audio_sink(self, patched_transport, patched_audio,

media.ClearConfiguration()
media.Release()


class BTInputTest(unittest.TestCase):

def setUp(self):
patcher = mock.patch('dbus.Interface', MockDBusInterface)
patcher.start()
self.addCleanup(patcher.stop)
patcher = mock.patch('dbus.SystemBus')
patched_system_bus = patcher.start()
self.addCleanup(patcher.stop)
mock_system_bus = mock.MagicMock()
patched_system_bus.return_value = mock_system_bus
mock_system_bus.get_object.return_value = dbus.ObjectPath('/org/bluez')

def test_input(self):
ip = bt_manager.BTInput(dev_id='00:12:A1:69:85:42')
ip.connect()
self.assertTrue(ip.Connected)
ip.disconnect()
self.assertFalse(ip.Connected)

0 comments on commit 82cafba

Please sign in to comment.