Improve solaar error handling/display
Improve errors shown by solaar plugin, also cleaning up how error are internally handled. See #335
This commit is contained in:
parent
c287204321
commit
9a091ab024
@ -2,6 +2,17 @@ from i3pystatus import IntervalModule
|
|||||||
from i3pystatus.core.command import run_through_shell
|
from i3pystatus.core.command import run_through_shell
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceNotFound(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NoBatteryStatus(Exception):
|
||||||
|
message = None
|
||||||
|
|
||||||
|
def __init__(self, message):
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
|
||||||
class Solaar(IntervalModule):
|
class Solaar(IntervalModule):
|
||||||
"""
|
"""
|
||||||
Shows status and load percentage of bluetooth-device
|
Shows status and load percentage of bluetooth-device
|
||||||
@ -29,8 +40,8 @@ class Solaar(IntervalModule):
|
|||||||
for line in out.split('\n'):
|
for line in out.split('\n'):
|
||||||
if line.count(self.nameOfDevice) > 0 and line.count(':') > 0:
|
if line.count(self.nameOfDevice) > 0 and line.count(':') > 0:
|
||||||
numberOfDevice = line.split(':')[0]
|
numberOfDevice = line.split(':')[0]
|
||||||
return(0, numberOfDevice)
|
return numberOfDevice
|
||||||
return(1, 0)
|
raise DeviceNotFound()
|
||||||
|
|
||||||
def findBatteryStatus(self, numberOfDevice):
|
def findBatteryStatus(self, numberOfDevice):
|
||||||
command = 'solaar-cli show -v %s' % (numberOfDevice)
|
command = 'solaar-cli show -v %s' % (numberOfDevice)
|
||||||
@ -39,24 +50,25 @@ class Solaar(IntervalModule):
|
|||||||
if line.count('Battery') > 0:
|
if line.count('Battery') > 0:
|
||||||
if line.count(':') > 0:
|
if line.count(':') > 0:
|
||||||
batterystatus = line.split(':')[1].strip().strip(",")
|
batterystatus = line.split(':')[1].strip().strip(",")
|
||||||
return(0, batterystatus)
|
return batterystatus
|
||||||
|
elif line.count('offline'):
|
||||||
|
raise NoBatteryStatus('offline')
|
||||||
else:
|
else:
|
||||||
return(1, 0)
|
raise NoBatteryStatus('unknown')
|
||||||
return(1, 0)
|
raise NoBatteryStatus('unknown/error')
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.output = {}
|
self.output = {}
|
||||||
rcfindDeviceNumber = self.findDeviceNumber()
|
|
||||||
if rcfindDeviceNumber[0] != 0:
|
try:
|
||||||
output = "problem finding device %s" % (self.nameOfDevice)
|
device_number = self.findDeviceNumber()
|
||||||
self.output['color'] = self.error_color
|
output = self.findBatteryStatus(device_number)
|
||||||
else:
|
|
||||||
numberOfDevice = rcfindDeviceNumber[1]
|
|
||||||
rcfindBatteryStatus = self.findBatteryStatus(numberOfDevice)
|
|
||||||
if rcfindBatteryStatus[0] != 0:
|
|
||||||
output = "problem finding battery status device %s" % (self.nameOfDevice)
|
|
||||||
self.output['color'] = self.error_color
|
|
||||||
else:
|
|
||||||
output = self.findBatteryStatus(self.findDeviceNumber()[1])[1]
|
|
||||||
self.output['color'] = self.color
|
self.output['color'] = self.color
|
||||||
|
except DeviceNotFound:
|
||||||
|
output = "device absent"
|
||||||
|
self.output['color'] = self.error_color
|
||||||
|
except NoBatteryStatus as e:
|
||||||
|
output = e.message
|
||||||
|
self.output['color'] = self.error_color
|
||||||
|
|
||||||
self.output['full_text'] = output
|
self.output['full_text'] = output
|
||||||
|
Loading…
Reference in New Issue
Block a user