From 282c96a9e4507f63af0689746b0dea610d39ba67 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Mon, 21 Dec 2020 18:13:05 +0530 Subject: [PATCH] Add fuel_check plugin --- plugins/__init__.py | 3 ++- plugins/fuel_check.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 plugins/fuel_check.py diff --git a/plugins/__init__.py b/plugins/__init__.py index bf320ab..1cebcf3 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -1 +1,2 @@ -plugins = [] +from . import fuel_check +plugins = [fuel_check] diff --git a/plugins/fuel_check.py b/plugins/fuel_check.py new file mode 100644 index 0000000..3abdba4 --- /dev/null +++ b/plugins/fuel_check.py @@ -0,0 +1,26 @@ +import time + +start = time.monotonic() +last_message = None +threshold = 5 + +def check(data, emit): + "Checks if the fuel ratio is below a certain threshold" + global last_message + if "FuelRatio" not in data: + return + + ratio = data["FuelRatio"] + if ratio <= threshold: + if last_message is None: + emit("switchPlugin", { + "plugin": "warning", + "data": { + "title": "Low Fuel", + "description": f"Only {int(ratio)}% fuel left. Please refill the tank." + }, + "time": 5000 + }) + last_message = time.monotonic() + else: + last_message = None