aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xclient/ur_fuzzy_alarm_clock.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/client/ur_fuzzy_alarm_clock.py b/client/ur_fuzzy_alarm_clock.py
index 1f0775d..a202b35 100755
--- a/client/ur_fuzzy_alarm_clock.py
+++ b/client/ur_fuzzy_alarm_clock.py
@@ -1,18 +1,20 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import datetime
+import io
+import logging
import sys
try:
import urwid
except ImportError:
- sys.stderr.write('This program needs urwid\n')
+ logging.error('This program needs urwid')
sys.exit(1)
try:
import serial
except ImportError:
- sys.stderr.write('This program needs pySerial\n')
+ logging.error('This program needs pySerial')
sys.exit(1)
class FuzzyAlarmClock:
@@ -21,8 +23,13 @@ class FuzzyAlarmClock:
try:
self.serial = serial.Serial(device,9600,timeout=5)
except serial.serialutil.SerialException:
- sys.stderr.write('No such serial device '+device+'\n')
- sys.exit(1)
+ logging.warning('No such serial device {device}; mocking'.format(
+ device=device
+ ))
+ self.serial = io.StringIO()
+ self.mock = True
+ else:
+ self.mock = False
def set_time_to_now(self):
now = 's'+datetime.datetime.now().strftime("%y%m%d%u%H%M%S")
@@ -32,12 +39,12 @@ class FuzzyAlarmClock:
data = []
self.serial.flushInput()
self.serial.write('p')
- for i in xrange(n):
+ for i in range(n):
data.append(self.serial.readline())
- for i in xrange(n):
+ for i in range(n):
data[i] = data[i].split(' ')[2:-1]
days = []
- for j in xrange(8):
+ for j in range(8):
days.append(bool(int(data[i][0]) & 2**j))
days = days[7:8] + days[:7]
data[i] = days+data[i][1:]
@@ -147,7 +154,7 @@ class UI:
]
self.alarms = []
- for i in xrange(self.alarm_number):
+ for i in range(self.alarm_number):
self.alarms.append(Alarm(i,self.fac))
alarm_headers = urwid.Columns([