Background-Daemon/plugins/air_bags.py

29 lines
826 B
Python

"AirBags"
import time
from daemon import DaemonPlugin
class AirBags(DaemonPlugin):
"Checks AirBags and sends relevant warnings"
last_message = None
start = None
def initialize(self):
"Initialize plugin"
self.start = time.monotonic()
def check(self, data):
"Checks if the air bags are deployed"
if "AirBags-Deploy" not in data:
return
if data["AirBags-Deploy"]:
if self.last_message is None:
self.emit("switchPlugin", { "plugin": "accident" })
message = ("Airbags were released. Calling ambulance in 20 "
"seconds. Tap screen to cancel.")
self.speak(message)
self.last_message = time.monotonic()
else:
self.last_message = None