Skip to content

Commit

Permalink
device: be defensive when converting battery status to string
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Jun 3, 2024
1 parent 104556e commit 8987c42
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/logitech_receiver/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ def charging(self) -> bool:
def to_str(self) -> str:
if isinstance(self.level, BatteryLevelApproximation):
level = self.level.name.lower()
status = self.status.name.lower().replace("_", " ")
status = self.status.name.lower().replace("_", " ") if self.status is not None else "Unknown"
return _("Battery: %(level)s (%(status)s)") % {"level": _(level), "status": _(status)}
elif isinstance(self.level, int):
status = self.status.name.lower().replace("_", " ")
status = self.status.name.lower().replace("_", " ") if self.status is not None else "Unknown"
return _("Battery: %(percent)d%% (%(status)s)") % {"percent": self.level, "status": _(status)}
else:
return ""
Expand Down

0 comments on commit 8987c42

Please sign in to comment.