2020-12-31 01:32:03 +01:00
|
|
|
"Fuel Check"
|
2020-12-21 13:43:05 +01:00
|
|
|
import time
|
|
|
|
|
2020-12-31 01:32:03 +01:00
|
|
|
from daemon import DaemonPlugin
|
2020-12-21 13:43:05 +01:00
|
|
|
|
2020-12-31 01:32:03 +01:00
|
|
|
class FuelCheck(DaemonPlugin):
|
|
|
|
start = None
|
|
|
|
last_message = None
|
|
|
|
threshold = 5
|
2020-12-21 13:43:05 +01:00
|
|
|
|
2020-12-31 01:32:03 +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
|