Skip to content

Commit

Permalink
Added battery temperature to telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Sep 2, 2024
1 parent 0425bee commit 454eedd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 12 additions & 5 deletions sbapp/sideband/sense.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def update_data(self):
if RNS.vendor.platformutils.is_android():
self.battery.get_state()
b = self.battery.status
self.data = {"charge_percent": b["percentage"], "charging": b["isCharging"]}
self.data = {"charge_percent": b["percentage"], "charging": b["isCharging"], "temperature": None}

elif RNS.vendor.platformutils.is_linux():
if self.battery_node_name:
Expand All @@ -485,7 +485,7 @@ def update_data(self):

is_charging = output['POWER_SUPPLY_STATUS'] == 'Charging'
charge_percent = float(output['POWER_SUPPLY_CAPACITY'])
self.data = {"charge_percent": round(charge_percent, 1), "charging": is_charging}
self.data = {"charge_percent": round(charge_percent, 1), "charging": is_charging, "temperature": None}

except:
self.data = None
Expand All @@ -495,14 +495,20 @@ def pack(self):
if d == None:
return None
else:
return [round(d["charge_percent"],1), d["charging"]]
return [round(d["charge_percent"],1), d["charging"], d["temperature"]]

def unpack(self, packed):
try:
if packed == None:
return None
else:
return {"charge_percent": round(packed[0], 1), "charging": packed[1]}
unpacked = {"charge_percent": round(packed[0], 1), "charging": packed[1]}
if len(packed) > 2:
unpacked["temperature"] = packed[2]
else:
unpacked["temperature"] = None

return unpacked
except:
return None

Expand All @@ -512,6 +518,7 @@ def render(self, relative_to=None):

d = self.data
p = d["charge_percent"]
t = d["temperature"]
if d["charging"]:
charge_string = "charging"
else:
Expand All @@ -520,7 +527,7 @@ def render(self, relative_to=None):
rendered = {
"icon": "battery-outline",
"name": "Battery",
"values": {"percent": p, "_meta": charge_string},
"values": {"percent": p, "temperature": t, "_meta": charge_string},
}

if d["charging"]:
Expand Down
12 changes: 10 additions & 2 deletions sbapp/ui/objectdetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,15 @@ def copy_info(e=None):
elif name == "Battery":
p = s["values"]["percent"]
cs = s["values"]["_meta"]
if cs != None: cs_str = f" ({cs})"
t = None
if "temperature" in s["values"]:
t = s["values"]["temperature"]
if cs != None:
if t != None:
cs_str = f" ({cs}, {t}° C)"
else:
cs_str = f" ({cs})"

if p != None: formatted_values = f"{name} [b]{p}%[/b]"+cs_str

elif name == "Ambient Pressure":
Expand Down Expand Up @@ -581,7 +589,7 @@ def copy_info(e=None):
load = c["current_load"]
avgs = c["load_avgs"]
clock = c["clock"]
pct = round(load*100, 1)
pct = round(load*100.0, 1)

avgs_str = f", averages are [b]{round(avgs[0],2)}[/b], [b]{round(avgs[1],2)}[/b], [b]{round(avgs[2],2)}[/b]" if avgs != None and len(avgs) == 3 else ""
clock_str = " at [b]"+RNS.prettyfrequency(clock)+"[/b]" if clock != None else ""
Expand Down

0 comments on commit 454eedd

Please sign in to comment.