2016-11-28 13:48:11 +02:00
|
|
|
import plugins
|
2016-10-22 19:27:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
BATTERY_DIR = '/sys/class/power_supply/BAT0/'
|
|
|
|
|
|
|
|
|
2016-11-28 13:48:11 +02:00
|
|
|
class PluginThread(plugins.PluginThreadCommon):
|
2017-12-16 01:55:28 +02:00
|
|
|
def __init__(self, config):
|
2018-04-28 19:40:10 +03:00
|
|
|
defaults = {
|
|
|
|
'problem': 15,
|
|
|
|
'symbol_charging': '\u2191',
|
|
|
|
'symbol_discharging': '\u2193'
|
|
|
|
}
|
|
|
|
super(PluginThread, self).__init__(config, defaults)
|
2016-10-22 19:27:28 +03:00
|
|
|
|
|
|
|
def main(self):
|
2017-12-16 01:55:28 +02:00
|
|
|
with \
|
2018-04-28 19:40:10 +03:00
|
|
|
open(BATTERY_DIR + 'capacity', 'r') as batt_capacity, \
|
|
|
|
open(BATTERY_DIR + 'status', 'r') as batt_status:
|
|
|
|
status = batt_status.read().strip()
|
|
|
|
capacity = batt_capacity.read().strip()
|
|
|
|
if status != 'Discharging':
|
|
|
|
symbol = self.conf['symbol_charging']
|
2016-10-31 15:35:38 +02:00
|
|
|
self.status['urgent'] = False
|
2018-04-28 19:40:10 +03:00
|
|
|
else:
|
|
|
|
symbol = self.conf['symbol_discharging']
|
|
|
|
self.status['urgent'] = float(capacity) <= self.conf['problem']
|
2016-10-25 19:48:40 +03:00
|
|
|
|
2018-04-28 19:40:10 +03:00
|
|
|
self.status['full_text'] = 'BAT: ' + capacity + '% ' + symbol
|