Skip to content

Commit 86808fd

Browse files
author
catodd
committed
Merge pull request #3 from corytodd/master
Remove redundant stack messages and check message dict safely
2 parents 3cb374e + 4e8c131 commit 86808fd

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

host.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#Change this value to modify polling rate. Currently 100 ms
4747
POLL_RATE = 0.1
4848

49+
#pylint: disable-msg=R0902
4950

5051
class Host(object):
5152
"""
@@ -178,18 +179,22 @@ def _serial_runner(self, portname):
178179

179180
# With the exception of Stacked and Returned, only we can
180181
# only be in one state at once
181-
status = Host.state_dict[ord(out[3])]
182+
try:
183+
status = Host.state_dict[ord(out[3])]
184+
except KeyError:
185+
print "unknown state dic key {:d}".format(ord(out[3]))
186+
182187
self.escrowed = ord(out[3]) & 4
183-
if ord(out[3]) & 0x10:
184-
status += " STACKED "
185-
if ord(out[3]) & 0x40:
186-
status += " RETURNED "
187188

188189
# If there is no match, we get an empty string
189-
status += Host.event_dict[ord(out[4]) & 1]
190-
status += Host.event_dict[ord(out[4]) & 2]
191-
status += Host.event_dict[ord(out[4]) & 4]
192-
status += Host.event_dict[ord(out[4]) & 8]
190+
try:
191+
status += Host.event_dict[ord(out[4]) & 1]
192+
status += Host.event_dict[ord(out[4]) & 2]
193+
status += Host.event_dict[ord(out[4]) & 4]
194+
status += Host.event_dict[ord(out[4]) & 8]
195+
except KeyError:
196+
print "unknown state dic key {:d}".format(ord(out[4]))
197+
193198
if ord(out[4]) & 0x10 != 0x10:
194199
status += " CASSETTE MISSING"
195200

@@ -208,7 +213,8 @@ def _serial_runner(self, portname):
208213
if ord(out[3]) & 0x10:
209214
print "Bill credited: Bill#", credit
210215
self.bill_count[credit] += 1
211-
print "Acceptor now holds:", binascii.hexlify(self.bill_count)
216+
print "Acceptor now holds: {:s}".format(
217+
binascii.hexlify(self.bill_count))
212218

213219
time.sleep(POLL_RATE)
214220

0 commit comments

Comments
 (0)