diff --git a/app/receiver.py b/app/receiver.py index 5647ff05..b860bece 100644 --- a/app/receiver.py +++ b/app/receiver.py @@ -4,6 +4,7 @@ from logging import getLogger as _Logger from struct import pack as _pack +from time import time as _timestamp from logitech.unifying_receiver import base as _base from logitech.unifying_receiver import api as _api @@ -126,6 +127,7 @@ class DeviceInfo(_api.PairedDevice): assert status_changed_callback self.status_changed_callback = status_changed_callback self._status = status + self.status_updated = _timestamp() self.props = {} self._features = _FeaturesArray(self) @@ -149,6 +151,7 @@ class DeviceInfo(_api.PairedDevice): self._features._check() self.protocol, self.codename, self.name, self.kind + self.status_updated = _timestamp() old_status = self._status if new_status != old_status and not (new_status == STATUS.CONNECTED and old_status > new_status): self.LOG.debug("status %d => %d", old_status, new_status) diff --git a/app/solaar.py b/app/solaar.py index f0f0df24..82cd8ae3 100644 --- a/app/solaar.py +++ b/app/solaar.py @@ -130,11 +130,26 @@ if __name__ == '__main__': # print ("opened receiver", listener, listener.receiver) notify_missing = True status_changed(listener.receiver, None, STATUS.UI_NOTIFY) - GObject.timeout_add(5 * 1000, _check_still_scanning, listener) + GObject.timeout_add(3 * 1000, _check_still_scanning, listener) pairing.state = pairing.State(listener) listener.trigger_device_events() + _DEVICE_TIMEOUT = 3 * 60 # seconds + _DEVICE_STATUS_CHECK = 30 # seconds + from time import time as _timestamp + + def check_for_inactive_devices(): + if listener and listener.receiver: + for dev in listener.receiver.devices.values(): + if (dev.status < STATUS.CONNECTED and + dev.props and + _timestamp() - dev.status_updated > _DEVICE_TIMEOUT): + dev.props.clear() + status_changed(listener.receiver, dev) + return True + GObject.timeout_add(50, check_for_listener, False) + GObject.timeout_add(_DEVICE_STATUS_CHECK * 1000, check_for_inactive_devices) Gtk.main() if listener is not None: diff --git a/app/ui/main_window.py b/app/ui/main_window.py index b2ac964e..c74c92b0 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -277,17 +277,17 @@ def _update_device_box(frame, dev): if dev.status < STATUS.CONNECTED: label.set_sensitive(False) + for c in status_icons[2:-1]: + c.set_visible(False) battery_icon, battery_label = status_icons[0:2] battery_icon.set_sensitive(False) battery_label.set_sensitive(False) battery_level = dev.props.get(PROPS.BATTERY_LEVEL) if battery_level is None: - battery_label.set_markup('(%s)' % dev.status_text) + battery_label.set_markup('%s' % dev.status_text) else: - battery_label.set_markup('%d%% (%s)' % (battery_level, dev.status_text)) - for c in status_icons[2:-1]: - c.set_visible(False) + battery_label.set_markup('%d%%' % battery_level) else: label.set_sensitive(True) @@ -299,7 +299,7 @@ def _update_device_box(frame, dev): battery_icon.set_from_icon_name('battery_unknown', _STATUS_ICON_SIZE) text = 'no status' if dev.protocol < 2.0 else 'waiting for status...' battery_label.set_markup('%s' % text) - battery_label.set_sensitive(False) + battery_label.set_sensitive(True) else: battery_icon.set_from_icon_name(ui.get_battery_icon(battery_level), _STATUS_ICON_SIZE) battery_icon.set_sensitive(True) diff --git a/app/ui/status_icon.py b/app/ui/status_icon.py index 2e24d48d..814eeb17 100644 --- a/app/ui/status_icon.py +++ b/app/ui/status_icon.py @@ -45,10 +45,10 @@ def update(icon, receiver): if p: p = '\t' + p if dev.status < STATUS.CONNECTED: - p += ' (' + dev.status_text + ')' + p += ' (' + dev.status_text + ')' lines.append(p) elif dev.status < STATUS.CONNECTED: - lines.append('\t(' + dev.status_text + ')') + lines.append('\t(' + dev.status_text + ')') elif dev.protocol < 2.0: lines.append('\t' + 'no status') else: