Update plugins to new class-based structure

This commit is contained in:
Ceda EI 2020-12-31 06:02:03 +05:30
parent c55899cd8a
commit 398f432e1a
2 changed files with 33 additions and 24 deletions

View File

@ -1,2 +1,2 @@
from . import fuel_check from .fuel_check import FuelCheck
plugins = [fuel_check] plugins = [FuelCheck]

View File

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