yasb
yasb copied to clipboard
[BUG] Battery State is None in Desktop PCs
Expected Behavior
If the user is on a desktop PC rather than a laptop, psutil will not be able to detect a battery sensor and will return None.
Expected Behavior:
- Battery Present (Laptop): Returns an object with battery details like charge level and time remaining.
- Battery Absent (Desktop PC): Implement checks or use exception handling (try-except) to avoid AttributeError errors.
Current Behavior
Because the state of the battery is not verified, this triggers AttributeError exceptions (see yasb.log).
Possible Solution
This is the solution that I've implemented on my code: Inside: "yasb\src\core\widgets\yasb\battery.py"
alt_class = "alt" if self._show_alt_label else ""
self._battery_state = psutil.sensors_battery()
if self._battery_state is None:
# With this the user is still able to customize the widget
active_label.setProperty("class", f"label {alt_class} status-high")
return
Steps to Reproduce
Run YASB on a Desktop PC
Context (Environment)
Platform: Windows 11 Python Version: 3.12.2 Psutil Version: 5.9.1 yasb.log