From 6fe45026b05668d1604fe23ef9d867b0be0c801c Mon Sep 17 00:00:00 2001 From: iGoX Date: Wed, 25 Mar 2026 08:35:40 +0100 Subject: [PATCH] Refactor controlers --- ESP32/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ESP32/main.py b/ESP32/main.py index 3aa716c..aefe8e8 100644 --- a/ESP32/main.py +++ b/ESP32/main.py @@ -25,7 +25,7 @@ class LedController: self._task = None # state - self.statusColors = { + self.states = { 'BUSY': (255, 0, 0), 'AVAILABLE': (0, 255, 0), 'AWAY': (246, 190, 0), @@ -33,7 +33,7 @@ class LedController: 'ON': (255, 255, 255) } - self.color = self.statusColors['OFF'] + self.color = self.states['OFF'] self.status = 'off' self.previousStatus = 'off' self.brightness = 0.1 @@ -61,6 +61,7 @@ class LedController: await self._flag.wait() cmd = self._cmd + # Cancel any ongoing task before starting a new one if self._task: self._task.cancel() try: @@ -68,6 +69,7 @@ class LedController: except asyncio.CancelledError: pass + # Process the new command t = cmd["type"] if t == "blink": @@ -135,7 +137,7 @@ class LedController: async def set_status(self, status): status = status.upper() - color = self.statusColors.get(status) + color = self.states.get(status) if color is None: raise ValueError("invalid status")