Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bt.py
diff options
context:
space:
mode:
Diffstat (limited to 'bt.py')
-rw-r--r--bt.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/bt.py b/bt.py
index 72241ea..8686780 100644
--- a/bt.py
+++ b/bt.py
@@ -27,16 +27,28 @@ SEARCH_TIME = 20 # seconds
class Bluetooth(GObject.GObject):
__gsignals__ = {
- 'device-found': (GObject.SignalFlags.RUN_FIRST, None, [object])}
+ 'device-found': (GObject.SignalFlags.RUN_FIRST, None, [object]),
+ 'search-finished': (GObject.SignalFlags.RUN_FIRST, None, [])}
def __init__(self):
super(Bluetooth, self).__init__()
manager = bluez.Manager('gobject')
self._adapter = manager.DefaultAdapter()
- #self._adapter.HandleSignal(self._device_found, 'DeviceFound')
- self._nearby_devices = []
+ def device_found(address, properties):
+ already_found = False
+ for i in self.nearby_devices:
+ if properties['Address'] == i['Address']:
+ already_found = True
+
+ if not already_found:
+ self.nearby_devices.append(properties)
+ self.emit('device-found', properties)
+
+ self._adapter.HandleSignal(device_found, 'DeviceFound')
+
+ self.nearby_devices = []
self._paired_devices = self._adapter.ListDevices()
def get_paired_devices(self):
@@ -44,13 +56,8 @@ class Bluetooth(GObject.GObject):
def find_devices(self):
self._adapter.StartDiscovery()
- self._nearby_devices = []
- GObject.timeout_add(SEARCH_TIME * 1000, self._stop_search)
+ self.nearby_devices = []
- def _device_found(self, address, properties):
- self._nearby_devices.append(properties)
- self.emit('device-found', properties)
- return
-
- def _stop_search(self):
+ def stop_search(self):
self._adapter.StopDiscovery()
+