clean-up in solaar.listener
This commit is contained in:
parent
b2b4febd31
commit
0a86683392
|
|
@ -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,28 +125,31 @@ 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
|
||||||
if device.status is None:
|
|
||||||
# device was just un-paired
|
|
||||||
# it may be paired later, possibly to another receiver?
|
|
||||||
# so maybe we shouldn't forget about it
|
|
||||||
# configuration.forget(device)
|
|
||||||
|
|
||||||
# device was unpaired, and since the object is weakref'ed
|
assert device.receiver == self.receiver
|
||||||
# it won't be valid for much longer
|
|
||||||
device = _ghost(device)
|
|
||||||
|
|
||||||
# elif device.status:
|
if device.status is None:
|
||||||
# configuration.apply_to(device)
|
# device was just un-paired
|
||||||
# configuration.acquire_from(device)
|
# it may be paired later, possibly to another receiver?
|
||||||
|
# so maybe we shouldn't forget about it
|
||||||
|
# configuration.forget(device)
|
||||||
|
|
||||||
|
# device was unpaired, and since the object is weakref'ed
|
||||||
|
# it won't be valid for much longer
|
||||||
|
_log.info("device %s was unpaired, ghosting", device)
|
||||||
|
device = _ghost(device)
|
||||||
|
|
||||||
self.status_changed_callback(device, alert, reason)
|
# elif device.status:
|
||||||
|
# configuration.apply_to(device)
|
||||||
|
# configuration.acquire_from(device)
|
||||||
|
|
||||||
if device.status is None:
|
self.status_changed_callback(device, alert, reason)
|
||||||
# the device was just unpaired, need to update the
|
|
||||||
# status of the receiver as well
|
if device.status is None:
|
||||||
self.status_changed_callback(self.receiver)
|
# the device was just unpaired, need to update the
|
||||||
|
# status of the receiver as well
|
||||||
|
self.status_changed_callback(self.receiver)
|
||||||
|
|
||||||
def _notifications_handler(self, n):
|
def _notifications_handler(self, n):
|
||||||
assert self.receiver
|
assert self.receiver
|
||||||
|
|
@ -149,31 +158,32 @@ 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
|
|
||||||
assert n.devnumber > 0 and n.devnumber <= self.receiver.max_devices
|
|
||||||
already_known = n.devnumber in self.receiver
|
|
||||||
dev = self.receiver[n.devnumber]
|
|
||||||
|
|
||||||
if not dev:
|
# a device notification
|
||||||
_log.warn("%s: received %s for invalid device %d: %r", self.receiver, n, n.devnumber, dev)
|
assert n.devnumber > 0 and n.devnumber <= self.receiver.max_devices
|
||||||
return
|
already_known = n.devnumber in self.receiver
|
||||||
|
dev = self.receiver[n.devnumber]
|
||||||
|
|
||||||
if not already_known:
|
if not dev:
|
||||||
# read these as soon as possible, they will be used everywhere
|
_log.warn("%s: received %s for invalid device %d: %r", self.receiver, n, n.devnumber, dev)
|
||||||
dev.protocol, dev.codename
|
return
|
||||||
dev.status = _status.DeviceStatus(dev, self._status_changed)
|
|
||||||
# the receiver changed status as well
|
|
||||||
self._status_changed(self.receiver)
|
|
||||||
|
|
||||||
# status may be None if the device has just been unpaired
|
if not already_known:
|
||||||
if dev.status is not None:
|
# read these as soon as possible, they will be used everywhere
|
||||||
dev.status.process_notification(n)
|
dev.protocol, dev.codename
|
||||||
if self.receiver.status.lock_open and not already_known:
|
dev.status = _status.DeviceStatus(dev, self._status_changed)
|
||||||
# this should be the first notification after a device was paired
|
# the receiver changed status as well
|
||||||
assert n.sub_id == 0x41 and n.address == 0x04
|
self._status_changed(self.receiver)
|
||||||
_log.info("%s: pairing detected new device", self.receiver)
|
|
||||||
self.receiver.status.new_device = dev
|
# status may be None if the device has just been unpaired
|
||||||
|
if dev.status is not None:
|
||||||
|
dev.status.process_notification(n)
|
||||||
|
if self.receiver.status.lock_open and not already_known:
|
||||||
|
# this should be the first notification after a device was paired
|
||||||
|
assert n.sub_id == 0x41 and n.address == 0x04
|
||||||
|
_log.info("%s: pairing detected new device", self.receiver)
|
||||||
|
self.receiver.status.new_device = dev
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '<ReceiverListener(%s,%s)>' % (self.receiver.path, self.receiver.handle)
|
return '<ReceiverListener(%s,%s)>' % (self.receiver.path, self.receiver.handle)
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue