Merge pull request #927 from kellya/main

Correct battery modules handling of critical/warning states
This commit is contained in:
tobi-wan-kenobi 2022-09-17 02:05:52 +02:00 committed by GitHub
commit 0807bfb5c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 11 deletions

View file

@ -211,7 +211,9 @@ class UPowerManager:
battery_proxy = self.bus.get_object(self.UPOWER_NAME, battery) battery_proxy = self.bus.get_object(self.UPOWER_NAME, battery)
battery_proxy_interface = dbus.Interface(battery_proxy, self.DBUS_PROPERTIES) battery_proxy_interface = dbus.Interface(battery_proxy, self.DBUS_PROPERTIES)
return bool(battery_proxy_interface.Get(self.UPOWER_NAME + ".Device", "IsPresent")) return bool(
battery_proxy_interface.Get(self.UPOWER_NAME + ".Device", "IsPresent")
)
def is_loading(self, battery): def is_loading(self, battery):
battery_proxy = self.bus.get_object(self.UPOWER_NAME, battery) battery_proxy = self.bus.get_object(self.UPOWER_NAME, battery)
@ -309,11 +311,6 @@ class Module(core.module.Module):
if capacity < 0: if capacity < 0:
return ["critical", "unknown"] return ["critical", "unknown"]
if capacity < int(self.parameter("critical", 10)):
state.append("critical")
elif capacity < int(self.parameter("warning", 20)):
state.append("warning")
if widget.get("ac"): if widget.get("ac"):
state.append("AC") state.append("AC")
else: else:
@ -339,6 +336,16 @@ class Module(core.module.Module):
state.append("charged") state.append("charged")
else: else:
state.append("charging") state.append("charging")
if (
capacity < int(self.parameter("critical", 10))
and self.power.get_state(self.device) == "Discharging"
):
state.append("critical")
elif (
capacity < int(self.parameter("warning", 20))
and self.power.get_state(self.device) == "Discharging"
):
state.append("warning")
return state return state

View file

@ -180,11 +180,6 @@ class Module(core.module.Module):
log.debug("battery state: {}".format(state)) log.debug("battery state: {}".format(state))
return ["critical", "unknown"] return ["critical", "unknown"]
if capacity < int(self.parameter("critical", 10)):
state.append("critical")
elif capacity < int(self.parameter("warning", 20)):
state.append("warning")
if widget.get("ac"): if widget.get("ac"):
state.append("AC") state.append("AC")
else: else:
@ -209,6 +204,18 @@ class Module(core.module.Module):
state.append("charged") state.append("charged")
else: else:
state.append("charging") state.append("charging")
if (
capacity < int(self.parameter("critical", 10))
and self.__manager.charge_any(self._batteries) == "Discharging"
):
state.append("critical")
elif (
capacity < int(self.parameter("warning", 20))
and self.__manager.charge_any(self._batteries) == "Discharging"
):
state.append("warning")
return state return state