vdstatus/plugins/batt.py

30 lines
934 B
Python
Raw Normal View History

import plugins
2016-10-22 19:27:28 +03:00
BATTERY_DIR = '/sys/class/power_supply/BAT0/'
BATT_DEFAULTS = {
'problem': 15,
'symbol_charging': '\u2191',
'symbol_discharging': '\u2193'
}
2016-10-22 19:27:28 +03:00
class PluginThread(plugins.PluginThreadCommon):
def __init__(self, config):
super(PluginThread, self).__init__(config, BATT_DEFAULTS)
2016-10-22 19:27:28 +03:00
def main(self):
with \
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']
self.status['urgent'] = False
else:
symbol = self.conf['symbol_discharging']
self.status['urgent'] = float(capacity) <= self.conf['problem']
self.status['full_text'] = 'BAT: ' + capacity + '% ' + symbol