Update plugins to new class-based structure
This commit is contained in:
parent
c55899cd8a
commit
398f432e1a
@ -1,2 +1,2 @@
|
|||||||
from . import fuel_check
|
from .fuel_check import FuelCheck
|
||||||
plugins = [fuel_check]
|
plugins = [FuelCheck]
|
||||||
|
@ -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):
|
||||||
|
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"
|
"Checks if the fuel ratio is below a certain threshold"
|
||||||
global last_message
|
|
||||||
if "FuelRatio" not in data:
|
if "FuelRatio" not in data:
|
||||||
return
|
return
|
||||||
|
|
||||||
ratio = data["FuelRatio"]
|
ratio = data["FuelRatio"]
|
||||||
if ratio <= threshold:
|
if ratio <= self.threshold:
|
||||||
if last_message is None:
|
if self.last_message is None:
|
||||||
emit("switchPlugin", {
|
desc = f"Only {int(ratio)}% fuel left. Please refill the tank."
|
||||||
|
self.speak(desc)
|
||||||
|
self.emit("switchPlugin", {
|
||||||
"plugin": "warning",
|
"plugin": "warning",
|
||||||
"data": {
|
"data": {
|
||||||
"title": "Low Fuel",
|
"title": "Low Fuel",
|
||||||
"description": f"Only {int(ratio)}% fuel left. Please refill the tank."
|
"description": desc
|
||||||
},
|
},
|
||||||
"time": 5000
|
"time": 5000
|
||||||
})
|
})
|
||||||
last_message = time.monotonic()
|
self.last_message = time.monotonic()
|
||||||
else:
|
else:
|
||||||
last_message = None
|
self.last_message = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user