[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:
tobi-wan-kenobi 2022-11-27 12:02:38 +01:00
parent 6a93238bda
commit 87a2890b48

View file

@ -51,7 +51,7 @@ class Module(core.module.Module):
self.background = True
self.__type = type
self.__volume = "n/a"
self.__volume = 0
self.__devicename = "n/a"
self.__muted = False
self.__showbars = util.format.asbool(self.parameter("showbars", False))
@ -108,11 +108,15 @@ class Module(core.module.Module):
def toggle_mute(self, _):
with pulsectl.Pulse(self.id + "vol") as pulse:
dev = self.get_device(pulse)
if not dev:
return
pulse.mute(dev, not self.__muted)
def change_volume(self, amount):
with pulsectl.Pulse(self.id + "vol") as pulse:
dev = self.get_device(pulse)
if not dev:
return
vol = dev.volume
vol.value_flat += amount
if self.__limit > 0 and vol.value_flat > self.__limit/100:
@ -132,13 +136,19 @@ class Module(core.module.Module):
for dev in devs:
if dev.name == default:
return dev
return devs[0] # fallback
if len(devs) == 0:
return None
return devs[0] # fallback
def process(self, _):
with pulsectl.Pulse(self.id + "proc") as pulse:
dev = self.get_device(pulse)
if not dev:
self.__volume = 0
self.__devicename = "n/a"
else:
self.__volume = dev.volume.value_flat
self.__muted = dev.mute
self.__devicename = dev.name