From 131f8f7f45e210156a4aaa025b34f1211898cc81 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Wed, 22 May 2013 20:42:26 +0300 Subject: [PATCH] disable status polling on devices the regular flow should be reading the battery on all devices now --- lib/logitech/unifying_receiver/listener.py | 9 +++++---- lib/logitech/unifying_receiver/status.py | 7 +++++-- lib/solaar/listener.py | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/logitech/unifying_receiver/listener.py b/lib/logitech/unifying_receiver/listener.py index 6ba0d15d..d53a39a3 100644 --- a/lib/logitech/unifying_receiver/listener.py +++ b/lib/logitech/unifying_receiver/listener.py @@ -104,7 +104,7 @@ class _ThreadedHandle(object): _EVENT_READ_TIMEOUT = 500 # After this many reads that did not produce a packet, call the tick() method. -_IDLE_READS = 3 +_IDLE_READS = 4 class EventsListener(_threading.Thread): @@ -135,7 +135,7 @@ class EventsListener(_threading.Thread): self.has_started() last_tick = 0 - idle_reads = 0 + idle_reads = _IDLE_READS * 10 while self._active: if self._queued_notifications.empty(): @@ -162,8 +162,9 @@ class EventsListener(_threading.Thread): _log.exception("processing %s", n) elif self.tick_period: - idle_reads = (idle_reads + 1) % _IDLE_READS - if idle_reads == 0: + idle_reads -= 1 + if idle_reads <= 0: + idle_reads = _IDLE_READS now = _timestamp() if now - last_tick >= self.tick_period: last_tick = now diff --git a/lib/logitech/unifying_receiver/status.py b/lib/logitech/unifying_receiver/status.py index 87a221fc..ad71b3c7 100644 --- a/lib/logitech/unifying_receiver/status.py +++ b/lib/logitech/unifying_receiver/status.py @@ -39,7 +39,7 @@ ERROR='error' # if not updates have been receiver from the device for a while, assume # it has gone offline and clear all its know properties. -_STATUS_TIMEOUT = 120 # seconds +_STATUS_TIMEOUT = 5 * 60 # seconds # # @@ -196,6 +196,9 @@ class DeviceStatus(dict): self[BATTERY_LEVEL] = battery if self.updated == 0 and active: + # if the device is active on the very first status notification, + # (meaning just when the program started or a new receiver was just + # detected), pop-up a notification about it alert |= ALERT.NOTIFICATION self.updated = timestamp or _timestamp() @@ -214,7 +217,7 @@ class DeviceStatus(dict): _log.debug("polling status of %s", d) # read these from the device in case they haven't been read already - # d.protocol, d.serial, d.firmware + d.protocol, d.serial, d.firmware if BATTERY_LEVEL not in self: self.read_battery(timestamp) diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index d7b67d22..f98bf93b 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -39,7 +39,8 @@ class ReceiverListener(_listener.EventsListener): """ def __init__(self, receiver, status_changed_callback): super(ReceiverListener, self).__init__(receiver, self._notifications_handler) - self.tick_period = _POLL_TICK + # no reason to enable polling yet + # self.tick_period = _POLL_TICK self._last_tick = 0 assert status_changed_callback @@ -74,6 +75,7 @@ class ReceiverListener(_listener.EventsListener): # if _log.isEnabledFor(_DEBUG): # _log.debug("%s: polling status: %s", self.receiver, list(iter(self.receiver))) + # not necessary anymore, we're now using udev monitor to watch for receiver status # if self._last_tick > 0 and timestamp - self._last_tick > _POLL_TICK * 2: # # if we missed a couple of polls, most likely the computer went into # # sleep, and we have to reinitialize the receiver again