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
|
@ -72,7 +72,8 @@ class TuhiDevice(GObject.Object):
|
|||
self._battery_percent = 0
|
||||
self._last_battery_update_time = 0
|
||||
self._battery_timer_source = None
|
||||
self._signals = {}
|
||||
self._signals = {'connected': None,
|
||||
'disconnected': None}
|
||||
|
||||
self._bluez_device = bluez_device
|
||||
|
||||
|
@ -151,7 +152,9 @@ class TuhiDevice(GObject.Object):
|
|||
return self._sync_state
|
||||
|
||||
def _connect_device(self, mode):
|
||||
if self._signals['connected'] is None:
|
||||
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()
|
||||
|
||||
|
@ -181,7 +184,7 @@ class TuhiDevice(GObject.Object):
|
|||
|
||||
try:
|
||||
bluez_device.disconnect(self._signals['connected'])
|
||||
del self._signals['connected']
|
||||
self._signals['connected'] = None
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
@ -193,7 +196,7 @@ class TuhiDevice(GObject.Object):
|
|||
logger.debug(f'{bluez_device.address}: disconnected')
|
||||
try:
|
||||
bluez_device.disconnect(self._signals['disconnected'])
|
||||
del self._signals['disconnected']
|
||||
self._signals['disconnected'] = None
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue