tweaked timing of enabling receiver notifications

This commit is contained in:
Daniel Pavel 2013-06-21 15:20:52 +02:00
parent f9c192c47a
commit c1aa341a7a
3 changed files with 12 additions and 14 deletions

View File

@ -241,14 +241,12 @@ class PairedDevice(object):
else: else:
set_flag_bits = 0 set_flag_bits = 0
ok = _hidpp10.set_notification_flags(self, set_flag_bits) ok = _hidpp10.set_notification_flags(self, set_flag_bits)
if ok is None:
_log.warn("%s: failed to %s device notifications", self, 'enable' if enable else 'disable')
flag_bits = _hidpp10.get_notification_flags(self) flag_bits = _hidpp10.get_notification_flags(self)
flag_names = None if flag_bits is None else tuple(_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits)) flag_names = None if flag_bits is None else tuple(_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits))
_log.info("%s: device notifications %s %s", self, 'enabled' if enable else 'disabled', flag_names)
if ok:
_log.info("%s: device notifications %s %s", self, 'enabled' if enable else 'disabled', flag_names)
else:
_log.warn("%s: failed to %s device notifications %s", self, 'enable' if enable else 'disable', flag_names)
return flag_bits if ok else None return flag_bits if ok else None
def request(self, request_id, *params): def request(self, request_id, *params):
@ -355,15 +353,14 @@ class Receiver(object):
else: else:
set_flag_bits = 0 set_flag_bits = 0
ok = _hidpp10.set_notification_flags(self, set_flag_bits) ok = _hidpp10.set_notification_flags(self, set_flag_bits)
if ok is None:
_log.warn("%s: failed to %s receiver notifications", self, 'enable' if enable else 'disable')
return None
flag_bits = _hidpp10.get_notification_flags(self) flag_bits = _hidpp10.get_notification_flags(self)
flag_names = None if flag_bits is None else tuple(_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits)) flag_names = None if flag_bits is None else tuple(_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits))
_log.info("%s: receiver notifications %s => %s", self, 'enabled' if enable else 'disabled', flag_names)
if ok: return flag_bits
_log.info("%s: receiver notifications %s => %s", self, 'enabled' if enable else 'disabled', flag_names)
else:
_log.warn("%s: failed to %s receiver notifications %s", self, 'enable' if enable else 'disable', flag_names)
return flag_bits if ok else None
def notify_devices(self): def notify_devices(self):
"""Scan all devices.""" """Scan all devices."""

View File

@ -69,7 +69,7 @@ class ReceiverStatus(dict):
self.new_device = None self.new_device = None
self[KEYS.ERROR] = None self[KEYS.ERROR] = None
self[KEYS.NOTIFICATION_FLAGS] = receiver.enable_notifications() # self[KEYS.NOTIFICATION_FLAGS] = receiver.enable_notifications()
def __str__(self): def __str__(self):
count = len(self._receiver) count = len(self._receiver)
@ -93,7 +93,7 @@ class ReceiverStatus(dict):
r.serial, r.firmware, None r.serial, r.firmware, None
# get an update of the notification flags # get an update of the notification flags
self[KEYS.NOTIFICATION_FLAGS] = _hidpp10.get_notification_flags(r) # self[KEYS.NOTIFICATION_FLAGS] = _hidpp10.get_notification_flags(r)
def process_notification(self, n): def process_notification(self, n):
if n.sub_id == 0x4A: if n.sub_id == 0x4A:

View File

@ -57,7 +57,8 @@ class ReceiverListener(_listener.EventsListener):
def has_started(self): def has_started(self):
_log.info("%s: notifications listener has started (%s)", self.receiver, self.receiver.handle) _log.info("%s: notifications listener has started (%s)", self.receiver, self.receiver.handle)
# self.receiver.enable_notifications() notification_flags = self.receiver.enable_notifications()
self.receiver.status[_status.KEYS.NOTIFICATION_FLAGS] = notification_flags
self.receiver.notify_devices() self.receiver.notify_devices()
self._status_changed(self.receiver) #, _status.ALERT.NOTIFICATION) self._status_changed(self.receiver) #, _status.ALERT.NOTIFICATION)