From 454eedd8d175af2cba399520954dd093a4b219ef Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 2 Sep 2024 15:13:59 +0200 Subject: [PATCH] Added battery temperature to telemetry --- sbapp/sideband/sense.py | 17 ++++++++++++----- sbapp/ui/objectdetails.py | 12 ++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/sbapp/sideband/sense.py b/sbapp/sideband/sense.py index edbb17c..aa1c3fa 100644 --- a/sbapp/sideband/sense.py +++ b/sbapp/sideband/sense.py @@ -466,7 +466,7 @@ class Battery(Sensor): 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: @@ -485,7 +485,7 @@ class Battery(Sensor): 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 @@ -495,14 +495,20 @@ class Battery(Sensor): 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 @@ -512,6 +518,7 @@ class Battery(Sensor): d = self.data p = d["charge_percent"] + t = d["temperature"] if d["charging"]: charge_string = "charging" else: @@ -520,7 +527,7 @@ class Battery(Sensor): rendered = { "icon": "battery-outline", "name": "Battery", - "values": {"percent": p, "_meta": charge_string}, + "values": {"percent": p, "temperature": t, "_meta": charge_string}, } if d["charging"]: diff --git a/sbapp/ui/objectdetails.py b/sbapp/ui/objectdetails.py index d099728..6d84da4 100644 --- a/sbapp/ui/objectdetails.py +++ b/sbapp/ui/objectdetails.py @@ -405,7 +405,15 @@ class RVDetails(MDRecycleView): 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": @@ -581,7 +589,7 @@ class RVDetails(MDRecycleView): 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 ""