Small changes in battery module
This commit is contained in:
parent
105a2d12bd
commit
237123ae0f
@ -5,7 +5,7 @@ import re
|
|||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
from . import IntervalModule
|
from . import IntervalModule
|
||||||
from .core.util import PrefixedKeyDict
|
from .core.util import PrefixedKeyDict, lchop
|
||||||
from .core.desktop import display_notification
|
from .core.desktop import display_notification
|
||||||
|
|
||||||
class UEventParser(configparser.ConfigParser):
|
class UEventParser(configparser.ConfigParser):
|
||||||
@ -16,17 +16,11 @@ class UEventParser(configparser.ConfigParser):
|
|||||||
parser.read_string(file.read())
|
parser.read_string(file.read())
|
||||||
return dict(parser.items("id10t"))
|
return dict(parser.items("id10t"))
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def lchop(string, prefix):
|
|
||||||
if string.startswith(prefix):
|
|
||||||
return string[len(prefix):]
|
|
||||||
return string
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(default_section="id10t")
|
super().__init__(default_section="id10t")
|
||||||
|
|
||||||
def optionxform(self, key):
|
def optionxform(self, key):
|
||||||
return self.lchop(key, "POWER_SUPPLY_")
|
return lchop(key, "POWER_SUPPLY_")
|
||||||
|
|
||||||
def read_string(self, string):
|
def read_string(self, string):
|
||||||
super().read_string("[id10t]\n" + string)
|
super().read_string("[id10t]\n" + string)
|
||||||
@ -54,10 +48,7 @@ class Battery:
|
|||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
if self.consumption():
|
if self.consumption():
|
||||||
if self.bat["STATUS"] == "Discharging":
|
return "Discharging" if self.bat["STATUS"] == "Discharging" else "Charging"
|
||||||
return "Discharging"
|
|
||||||
else:
|
|
||||||
return "Charging"
|
|
||||||
else:
|
else:
|
||||||
return "Full"
|
return "Full"
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ __all__ = [
|
|||||||
"ModuleList", "KeyConstraintDict", "PrefixedKeyDict",
|
"ModuleList", "KeyConstraintDict", "PrefixedKeyDict",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def lchop(string, prefix):
|
||||||
|
if string.startswith(prefix):
|
||||||
|
return string[len(prefix):]
|
||||||
|
return string
|
||||||
|
|
||||||
def popwhile(predicate, iterable):
|
def popwhile(predicate, iterable):
|
||||||
while iterable:
|
while iterable:
|
||||||
item = iterable.pop()
|
item = iterable.pop()
|
||||||
|
Loading…
Reference in New Issue
Block a user