mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2026-07-28 14:37:00 -07:00
Merge pull request #508 from CoderFX/fix/pisugarx-null-safety
fix(pisugarx): guard against None self.ps in on_loaded and on_ui_update
This commit is contained in:
@@ -600,9 +600,12 @@ class PiSugar(plugins.Plugin):
|
|||||||
f"[PiSugarX] Rotation is {'enabled' if self.rotation_enabled else 'disabled'}.")
|
f"[PiSugarX] Rotation is {'enabled' if self.rotation_enabled else 'disabled'}.")
|
||||||
logging.info(
|
logging.info(
|
||||||
f"[PiSugarX] Default display (when rotation disabled): {self.default_display}")
|
f"[PiSugarX] Default display (when rotation disabled): {self.default_display}")
|
||||||
self.ps.lowpower_shutdown = self.options['lowpower_shutdown']
|
if self.ps is not None:
|
||||||
self.ps.lowpower_shutdown_level = self.options['lowpower_shutdown_level']
|
self.ps.lowpower_shutdown = self.options.get('lowpower_shutdown', False)
|
||||||
self.ps.max_charge_voltage_protection = self.options['max_charge_voltage_protection']
|
self.ps.lowpower_shutdown_level = self.options.get('lowpower_shutdown_level', 10)
|
||||||
|
self.ps.max_charge_voltage_protection = self.options.get('max_charge_voltage_protection', False)
|
||||||
|
else:
|
||||||
|
logging.warning("[PiSugarX] PiSugar not connected during on_loaded, skipping config")
|
||||||
|
|
||||||
def on_ready(self, agent):
|
def on_ready(self, agent):
|
||||||
try:
|
try:
|
||||||
@@ -811,11 +814,13 @@ class PiSugar(plugins.Plugin):
|
|||||||
capacity = 0
|
capacity = 0
|
||||||
voltage = 0.00
|
voltage = 0.00
|
||||||
temp = 0
|
temp = 0
|
||||||
logging.info(f"[PiSugarX] PiSugar is not ready")
|
logging.debug("[PiSugarX] PiSugar is not ready")
|
||||||
|
|
||||||
# Check if battery is plugged in
|
# Check if battery is plugged in (only when ready and ps is available)
|
||||||
battery_plugged = self.safe_get(
|
battery_plugged = False
|
||||||
self.ps.get_battery_power_plugged, default=False)
|
if self.ready and self.ps is not None:
|
||||||
|
battery_plugged = self.safe_get(
|
||||||
|
self.ps.get_battery_power_plugged, default=False)
|
||||||
|
|
||||||
if battery_plugged:
|
if battery_plugged:
|
||||||
# If plugged in, display "CHG"
|
# If plugged in, display "CHG"
|
||||||
|
|||||||
Reference in New Issue
Block a user