Skip to content

GPS Plugin

Bases: BasePlugin

Simulates GPS location updates and signal loss.

Source code in plugins/gps/main.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class GPSPlugin(BasePlugin):
    """
    Simulates GPS location updates and signal loss.
    """
    def __init__(self):
        self.name = "GPSPlugin"
        self.logger = Logger(self.name)
        self.active = True
        self.location = {"lat": 0.0, "lon": 0.0}

    def on_init(self, config):
        self.logger.info("GPS plugin initialized.")

    def on_event(self, topic, data, timestamp):
        action = topic.split(".")[1]

        if action == "set_location":
            lat = data.get("lat")
            lon = data.get("lon")
            if lat is not None and lon is not None:
                self.location = {"lat": lat, "lon": lon}
                self.active = True
                self.logger.info(f"[{timestamp:.3f}s] GPS location set to ({lat}, {lon})")
            else:
                self.logger.warn(f"Invalid location data: {data}")

        elif action == "simulate_loss":
            self.active = False
            self.logger.info(f"[{timestamp:.3f}s] GPS signal lost.")

    def on_shutdown(self):
        self.logger.info("GPS plugin shutting down.")