kdeconnector module: add support for version 20.12.3
@@ -76,6 +76,8 @@ INTERFACE_BATTERY = INTERFACE + ".battery"
INTERFACE_NOTIFICATIONS = INTERFACE + ".notifications"
PATH = "/modules/kdeconnect"
DEVICE_PATH = PATH + "/devices"
+BATTERY_SUBPATH = "/battery"
+NOTIFICATIONS_SUBPATH = "/notifications"
UNKNOWN = "Unknown"
UNKNOWN_DEVICE = "unknown device"
UNKNOWN_SYMBOL = "?"
@@ -100,6 +102,8 @@ class Py3status:
def post_config_hook(self):
self._dev = None
+ self._bat = None
+ self._not = None
def _init_dbus(self):
"""
@@ -114,6 +118,18 @@ class Py3status:
try:
self._dev = _bus.get(SERVICE_BUS, DEVICE_PATH + f"/{self.device_id}")
+ try:
+ self._bat = _bus.get(
+ SERVICE_BUS, DEVICE_PATH + f"/{self.device_id}" + BATTERY_SUBPATH
+ )
+ self._not = _bus.get(
+ SERVICE_BUS,
+ DEVICE_PATH + f"/{self.device_id}" + NOTIFICATIONS_SUBPATH,
+ )
+ except Exception:
+ # Fallback to the old version
+ self._bat = None
+ self._not = None
except Exception:
return False
@@ -170,9 +186,15 @@ class Py3status:
Get the battery
"""
try:
+ charge = self._bat.charge if self._bat is not None else self._dev.charge()
+ isCharging = (
+ self._bat.isCharging
+ if self._bat is not None
+ else self._dev.isCharging()
+ )
battery = {
- "charge": self._dev.charge(),
- "isCharging": self._dev.isCharging() == 1,
+ "charge": charge,
+ "isCharging": isCharging == 1,
}
except Exception:
return None
@@ -184,7 +206,12 @@ class Py3status:
Get notifications
"""
try:
- notifications = {"activeNotifications": self._dev.activeNotifications()}
+ activeNotifications = (
+ self._not.activeNotifications()
+ if self._not is not None
+ else self._dev.activeNotifications()
+ )
+ notifications = {"activeNotifications": activeNotifications}
except Exception:
return None
