[core] Switch update interval parameter to seconds

As correctly pointed out by @rrhuffy, restricting update intervals to
minutes is pretty arbitrary. Therefore, change logic to specify updates
intervals in *seconds*.

Also, to maintain backwards compatibility for users that already have
custom intervals in their config, allow a module to specify their own
"factor" for intervals. So a module that expects the interval to be in
minutes can set the factor to 60.
This commit is contained in:
Tobias Witek 2019-10-29 20:20:19 +01:00
parent 45e7574ef8
commit 621564d247
7 changed files with 11 additions and 1 deletions

View file

@ -41,6 +41,7 @@ class Module(object):
self.error = None self.error = None
self._next = int(time.time()) self._next = int(time.time())
self._default_interval = 0 self._default_interval = 0
self._interval_factor = 1
self._engine = engine self._engine = engine
self._configFile = None self._configFile = None
@ -99,7 +100,10 @@ class Module(object):
except Exception as e: except Exception as e:
log.error("error updating '{}': {}".format(self.name, str(e))) log.error("error updating '{}': {}".format(self.name, str(e)))
self.error = str(e) self.error = str(e)
self._next += int(self.parameter("interval", self._default_interval))*60 self._next += int(self.parameter("interval", self._default_interval))*self._interval_factor
def interval_factor(self, factor):
self._interval_factor = factor
def interval(self, intvl): def interval(self, intvl):
self._default_interval = intvl self._default_interval = intvl

View file

@ -44,6 +44,7 @@ class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
widget = bumblebee.output.Widget(full_text=self.updates) widget = bumblebee.output.Widget(full_text=self.updates)
super(Module, self).__init__(engine, config, widget) super(Module, self).__init__(engine, config, widget)
self.interval_factor(60)
self.interval(30) self.interval(30)
def updates(self, widget): def updates(self, widget):

View file

@ -37,6 +37,7 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget(full_text=self.price) bumblebee.output.Widget(full_text=self.price)
) )
self._data = [] self._data = []
self.interval_factor(60)
self.interval(1) self.interval(1)
self._base = self.parameter("source", "GBP") self._base = self.parameter("source", "GBP")
self._symbols = self.parameter("destination", "USD,EUR").split(",") self._symbols = self.parameter("destination", "USD,EUR").split(",")

View file

@ -52,6 +52,7 @@ class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
widget = bumblebee.output.Widget(full_text=self.updates) widget = bumblebee.output.Widget(full_text=self.updates)
super(Module, self).__init__(engine, config, widget) super(Module, self).__init__(engine, config, widget)
self.interval_factor(60)
self.interval(30) self.interval(30)
def updates(self, widget): def updates(self, widget):

View file

@ -25,6 +25,7 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget(full_text=self.github) bumblebee.output.Widget(full_text=self.github)
) )
self._count = 0 self._count = 0
self.interval_factor(60)
self.interval(5) self.interval(5)
self._requests = requests.Session() self._requests = requests.Session()
self._requests.headers.update({"Authorization":"token {}".format(self.parameter("token", ""))}) self._requests.headers.update({"Authorization":"token {}".format(self.parameter("token", ""))})

View file

@ -29,6 +29,7 @@ class Module(bumblebee.engine.Module):
self._symbols = self.parameter('symbols', '') self._symbols = self.parameter('symbols', '')
self._change = bumblebee.util.asbool(self.parameter('change', True)) self._change = bumblebee.util.asbool(self.parameter('change', True))
self._value = None self._value = None
self.interval_factor(60)
self.interval(60) self.interval(60)
def value(self, widget): def value(self, widget):

View file

@ -42,6 +42,7 @@ class Module(bumblebee.engine.Module):
self._showcity = bumblebee.util.asbool(self.parameter("showcity", True)) self._showcity = bumblebee.util.asbool(self.parameter("showcity", True))
self._unit = self.parameter("unit", "metric") self._unit = self.parameter("unit", "metric")
self._valid = False self._valid = False
self.interval_factor(60)
self.interval(15) self.interval(15)
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self._next_location) engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self._next_location)