disable status polling on devices

the regular flow should be reading the battery on all devices now
This commit is contained in:
Daniel Pavel 2013-05-22 20:42:26 +03:00
parent c3b73964d5
commit 131f8f7f45
3 changed files with 13 additions and 7 deletions

View File

@ -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

View File

@ -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)

View File

@ -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