[modules/pulsectl] fix case when no devices are available
no devices lead to an exception that completely stopped bumblebee-status from processing data. handle this case more gracefully by defaulting to a volume of 0%. if this proves to be an issue, we can still add error indicators later. see #940
This commit is contained in:
parent
6a93238bda
commit
87a2890b48
1 changed files with 15 additions and 5 deletions
|
@ -51,7 +51,7 @@ class Module(core.module.Module):
|
||||||
self.background = True
|
self.background = True
|
||||||
|
|
||||||
self.__type = type
|
self.__type = type
|
||||||
self.__volume = "n/a"
|
self.__volume = 0
|
||||||
self.__devicename = "n/a"
|
self.__devicename = "n/a"
|
||||||
self.__muted = False
|
self.__muted = False
|
||||||
self.__showbars = util.format.asbool(self.parameter("showbars", False))
|
self.__showbars = util.format.asbool(self.parameter("showbars", False))
|
||||||
|
@ -108,11 +108,15 @@ class Module(core.module.Module):
|
||||||
def toggle_mute(self, _):
|
def toggle_mute(self, _):
|
||||||
with pulsectl.Pulse(self.id + "vol") as pulse:
|
with pulsectl.Pulse(self.id + "vol") as pulse:
|
||||||
dev = self.get_device(pulse)
|
dev = self.get_device(pulse)
|
||||||
|
if not dev:
|
||||||
|
return
|
||||||
pulse.mute(dev, not self.__muted)
|
pulse.mute(dev, not self.__muted)
|
||||||
|
|
||||||
def change_volume(self, amount):
|
def change_volume(self, amount):
|
||||||
with pulsectl.Pulse(self.id + "vol") as pulse:
|
with pulsectl.Pulse(self.id + "vol") as pulse:
|
||||||
dev = self.get_device(pulse)
|
dev = self.get_device(pulse)
|
||||||
|
if not dev:
|
||||||
|
return
|
||||||
vol = dev.volume
|
vol = dev.volume
|
||||||
vol.value_flat += amount
|
vol.value_flat += amount
|
||||||
if self.__limit > 0 and vol.value_flat > self.__limit/100:
|
if self.__limit > 0 and vol.value_flat > self.__limit/100:
|
||||||
|
@ -132,13 +136,19 @@ class Module(core.module.Module):
|
||||||
for dev in devs:
|
for dev in devs:
|
||||||
if dev.name == default:
|
if dev.name == default:
|
||||||
return dev
|
return dev
|
||||||
return devs[0] # fallback
|
if len(devs) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return devs[0] # fallback
|
||||||
|
|
||||||
|
|
||||||
def process(self, _):
|
def process(self, _):
|
||||||
with pulsectl.Pulse(self.id + "proc") as pulse:
|
with pulsectl.Pulse(self.id + "proc") as pulse:
|
||||||
dev = self.get_device(pulse)
|
dev = self.get_device(pulse)
|
||||||
|
if not dev:
|
||||||
|
self.__volume = 0
|
||||||
|
self.__devicename = "n/a"
|
||||||
|
else:
|
||||||
self.__volume = dev.volume.value_flat
|
self.__volume = dev.volume.value_flat
|
||||||
self.__muted = dev.mute
|
self.__muted = dev.mute
|
||||||
self.__devicename = dev.name
|
self.__devicename = dev.name
|
||||||
|
|
Loading…
Reference in a new issue