From 87fb7c49eb8848bd78781d2cb884066c2dfbfb9c Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Sun, 2 Jun 2024 15:55:41 +0200 Subject: [PATCH] turn off blinkstick on exit --- podstatus/app.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/podstatus/app.py b/podstatus/app.py index ba853a5..8ea15d3 100644 --- a/podstatus/app.py +++ b/podstatus/app.py @@ -1,6 +1,7 @@ import logging import time import random +import atexit from threading import Thread, Event from kubernetes import client, config as k8sconfig, watch from kubernetes.config import ConfigException @@ -58,6 +59,17 @@ logging.fatal(f"BlinkStick setup failed: {e}") bstick = None + +# Ensure Blinkstick is turned off on exit +def turn_off_blinkstick(): + if bstick: + logging.info("Turning off BlinkStick") + for i in range(config.BLINKSTICK_TOTAL_LED): + bstick.set_color(channel=0, index=i, hex="#000000") + + +atexit.register(turn_off_blinkstick) + # Threading setup stop_event = Event()