Background-Daemon/plugins/fuel_check.py

36 lines
998 B
Python
Raw Normal View History

"Fuel Check"
2020-12-21 13:43:05 +01:00
import time
from daemon import DaemonPlugin
2020-12-21 13:43:05 +01:00
class FuelCheck(DaemonPlugin):
start = None
last_message = None
threshold = 5
2020-12-21 13:43:05 +01:00
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)
self.emit("switchPlugin", {
"plugin": "warning",
"data": {
"title": "Low Fuel",
"description": desc
},
"time": 5000
})
self.last_message = time.monotonic()
else:
self.last_message = None