Background-Daemon/plugins/fuel_check.py

36 lines
1023 B
Python

"Fuel Check"
import time
from daemon import DaemonPlugin
class FuelCheck(DaemonPlugin):
start = None
last_message = None
threshold = 5
def initialize(self):
"Initialize plugin"
self.start = time.monotonic()
def check(self, data):
"Checks if the fuel ratio is below a certain threshold"
if "FuelRatio" not in data:
return
ratio = data["FuelRatio"]
if ratio <= self.threshold:
if self.last_message is None:
desc = f"Only {int(ratio)}% fuel left. Please refill the tank."
self.speak(desc.replace("%", " percent"))
self.emit("switchPlugin", {
"plugin": "warning",
"data": {
"title": "Low Fuel",
"description": desc
},
"time": 5000
})
self.last_message = time.monotonic()
else:
self.last_message = None