Refactor controlers
This commit is contained in:
+5
-3
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user