-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsink.py
50 lines (40 loc) · 1.19 KB
/
sink.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import print_function
import sys
import unittest
class Sink:
STATUS = {
'NONE': (0,0,0),
'BUILDING': (255,255,0),
'ERROR': (255,0,0),
'OK': (0,255,0),
'UNKNOWN': (200,200,190),
}
NO_STATUS = (128,128,110)
MAX_STATUS = 64
matrix = None
def __init__(self, m):
self.matrix = m
if m:
self.MAX_STATUS = m.AREA
self.matrix.brightness(0.6)
def put(self,status):
status = status[:self.MAX_STATUS] #trim the input
translated = [self.STATUS.get(s,self.NO_STATUS) for s in status]
self.notify(translated)
return translated
def translate_status(self,val):
return self.STATUS[val]
def notify(self,status_colors):
if self.matrix:
self.matrix.show(status_colors)
print(status_colors,file=sys.stderr)
#################################################################################
class TestSink(unittest.TestCase):
def test_upper(self):
sink = Sink(None)
def ignore(args):
pass
sink.notify = ignore
self.assertEqual([(0,0,0)], sink.put(['NONE']))
if __name__ == "__main__":
unittest.main()