Added battery temperature to telemetry

This commit is contained in:
Mark Qvist 2024-09-02 15:13:59 +02:00
parent 0425beeda5
commit 454eedd8d1
2 changed files with 22 additions and 7 deletions

View File

@ -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"]:

View File

@ -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 ""