2016-11-28 13:48:11 +02:00
|
|
|
import plugins
|
2016-10-22 19:27:28 +03:00
|
|
|
|
|
|
|
|
2019-03-28 12:21:15 +02:00
|
|
|
BATT_DEFAULTS = {
|
|
|
|
'problem': 15,
|
|
|
|
'symbol_charging': '\u2191',
|
|
|
|
'symbol_discharging': '\u2193'
|
|
|
|
}
|
2016-10-22 19:27:28 +03:00
|
|
|
|
|
|
|
|
2016-11-28 13:48:11 +02:00
|
|
|
class PluginThread(plugins.PluginThreadCommon):
|
2017-12-16 01:55:28 +02:00
|
|
|
def __init__(self, config):
|
2019-03-28 12:21:15 +02:00
|
|
|
super(PluginThread, self).__init__(config, BATT_DEFAULTS)
|
2016-10-22 19:27:28 +03:00
|
|
|
|
|
|
|
def main(self):
|
2017-12-16 01:55:28 +02:00
|
|
|
with \
|
2019-07-08 14:19:05 +03:00
|
|
|
open('/sys/class/power_supply/BAT0/capacity', 'r') as bcap, \
|
|
|
|
open('/sys/class/power_supply/BAT0/status', 'r') as bstat:
|
|
|
|
capacity = bcap.readline().strip()
|
|
|
|
status_value = bstat.readline().strip()
|
2019-07-05 18:24:46 +03:00
|
|
|
|
|
|
|
if status_value != 'Discharging':
|
2018-04-28 19:40:10 +03:00
|
|
|
symbol = self.conf['symbol_charging']
|
2019-07-05 18:24:46 +03:00
|
|
|
urgent = False
|
2018-04-28 19:40:10 +03:00
|
|
|
else:
|
|
|
|
symbol = self.conf['symbol_discharging']
|
2019-07-05 18:24:46 +03:00
|
|
|
urgent = float(capacity) <= self.conf['problem']
|
2016-10-25 19:48:40 +03:00
|
|
|
|
2019-07-08 14:19:05 +03:00
|
|
|
status = '{}% {}'.format(capacity, symbol)
|
|
|
|
self.format_status(status, urgent)
|