fix: state, check regex result before use it

This commit is contained in:
zetxx 2017-03-15 23:12:55 +02:00
parent 0b961e2304
commit 289b42b26a

View file

@ -13,17 +13,19 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget(full_text=self.volume) bumblebee.output.Widget(full_text=self.volume)
) )
self._level = "0" self._level = "0"
self._muted = False self._muted = True
device = self.parameter("device", "Master,0") device = self.parameter("device", "Master,0")
self._cmdString = "amixer get {}".format(device) self._cmdString = "amixer get {}".format(device)
def volume(self, widget): def volume(self, widget):
m = re.search(r'([\d]+)\%', self._level) m = re.search(r'([\d]+)\%', self._level)
self._muted = False self._muted = True
if m == "0": if m:
self._muted = True if m.group(1) != "0":
self._muted = False
return "{}%".format(m.group(1)) return "{}%".format(m.group(1))
else:
return "0%"
def update(self, widgets): def update(self, widgets):
self._level = bumblebee.util.execute(self._cmdString) self._level = bumblebee.util.execute(self._cmdString)