base: make sure we only connect once to the bluez connect/disconnect signals
This was getting stacked - once on init and once whenever we actually made a connecting, resulting in the signal never getting disconnected properly and some races because we tried to sync twice. The whole "listen()" vs "listening" vs "connected" etc. is a bit of a mess and should be reworked for a proper fix to this. But for now this will do. This may fix #124
This commit is contained in:
parent
b16a16abde
commit
bcdf730a72
13
tuhi/base.py
13
tuhi/base.py
|
@ -72,7 +72,8 @@ class TuhiDevice(GObject.Object):
|
||||||
self._battery_percent = 0
|
self._battery_percent = 0
|
||||||
self._last_battery_update_time = 0
|
self._last_battery_update_time = 0
|
||||||
self._battery_timer_source = None
|
self._battery_timer_source = None
|
||||||
self._signals = {}
|
self._signals = {'connected': None,
|
||||||
|
'disconnected': None}
|
||||||
|
|
||||||
self._bluez_device = bluez_device
|
self._bluez_device = bluez_device
|
||||||
|
|
||||||
|
@ -151,8 +152,10 @@ class TuhiDevice(GObject.Object):
|
||||||
return self._sync_state
|
return self._sync_state
|
||||||
|
|
||||||
def _connect_device(self, mode):
|
def _connect_device(self, mode):
|
||||||
self._signals['connected'] = self._bluez_device.connect('connected', self._on_bluez_device_connected, mode)
|
if self._signals['connected'] is None:
|
||||||
self._signals['disconnected'] = self._bluez_device.connect('disconnected', self._on_bluez_device_disconnected)
|
self._signals['connected'] = self._bluez_device.connect('connected', self._on_bluez_device_connected, mode)
|
||||||
|
if self._signals['disconnected'] is None:
|
||||||
|
self._signals['disconnected'] = self._bluez_device.connect('disconnected', self._on_bluez_device_disconnected)
|
||||||
self._bluez_device.connect_device()
|
self._bluez_device.connect_device()
|
||||||
|
|
||||||
def register(self):
|
def register(self):
|
||||||
|
@ -181,7 +184,7 @@ class TuhiDevice(GObject.Object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bluez_device.disconnect(self._signals['connected'])
|
bluez_device.disconnect(self._signals['connected'])
|
||||||
del self._signals['connected']
|
self._signals['connected'] = None
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -193,7 +196,7 @@ class TuhiDevice(GObject.Object):
|
||||||
logger.debug(f'{bluez_device.address}: disconnected')
|
logger.debug(f'{bluez_device.address}: disconnected')
|
||||||
try:
|
try:
|
||||||
bluez_device.disconnect(self._signals['disconnected'])
|
bluez_device.disconnect(self._signals['disconnected'])
|
||||||
del self._signals['disconnected']
|
self._signals['disconnected'] = None
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue