clean-up in solaar.listener

This commit is contained in:
Daniel Pavel 2013-06-08 16:18:25 +02:00
parent b2b4febd31
commit 0a86683392
1 changed files with 51 additions and 42 deletions

View File

@ -24,7 +24,13 @@ _GHOST_DEVICE.__nonzero__ = _GHOST_DEVICE.__bool__
del namedtuple del namedtuple
def _ghost(device): def _ghost(device):
return _GHOST_DEVICE(receiver=device.receiver, number=device.number, name=device.name, kind=device.kind, serial=device.serial, status=None) return _GHOST_DEVICE(
receiver=device.receiver,
number=device.number,
name=device.name,
kind=device.kind,
serial=device.serial,
status=None)
# #
# #
@ -119,7 +125,10 @@ class ReceiverListener(_listener.EventsListener):
assert device == self.receiver assert device == self.receiver
# the status of the receiver changed # the status of the receiver changed
self.status_changed_callback(device, alert, reason) self.status_changed_callback(device, alert, reason)
else: return
assert device.receiver == self.receiver
if device.status is None: if device.status is None:
# device was just un-paired # device was just un-paired
# it may be paired later, possibly to another receiver? # it may be paired later, possibly to another receiver?
@ -128,13 +137,13 @@ class ReceiverListener(_listener.EventsListener):
# device was unpaired, and since the object is weakref'ed # device was unpaired, and since the object is weakref'ed
# it won't be valid for much longer # it won't be valid for much longer
_log.info("device %s was unpaired, ghosting", device)
device = _ghost(device) device = _ghost(device)
# elif device.status: # elif device.status:
# configuration.apply_to(device) # configuration.apply_to(device)
# configuration.acquire_from(device) # configuration.acquire_from(device)
self.status_changed_callback(device, alert, reason) self.status_changed_callback(device, alert, reason)
if device.status is None: if device.status is None:
@ -149,7 +158,8 @@ class ReceiverListener(_listener.EventsListener):
# a receiver notification # a receiver notification
if self.receiver.status is not None: if self.receiver.status is not None:
self.receiver.status.process_notification(n) self.receiver.status.process_notification(n)
else: return
# a device notification # a device notification
assert n.devnumber > 0 and n.devnumber <= self.receiver.max_devices assert n.devnumber > 0 and n.devnumber <= self.receiver.max_devices
already_known = n.devnumber in self.receiver already_known = n.devnumber in self.receiver
@ -240,8 +250,7 @@ def _process_receiver_event(action, device_info):
if action == 'add': if action == 'add':
# a new receiver device was detected # a new receiver device was detected
try: try:
l = start(device_info, _status_callback) start(device_info, _status_callback)
except OSError: except OSError:
# permission error, ignore this path for now # permission error, ignore this path for now
_all_listeners.pop(device_info.path, None)
_error_callback('permissions', device_info.path) _error_callback('permissions', device_info.path)