-
Notifications
You must be signed in to change notification settings - Fork 1
/
Steps.py
63 lines (46 loc) · 1.35 KB
/
Steps.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
51
52
53
54
55
56
57
58
59
60
61
62
63
import datetime
class Pause:
def __init__(self, msg):
self.msg = msg.strip()
self.tag = 'PAUSE'
def __str__(self):
return 'Pause ({msg})'.format(**self.__dict__)
class Done:
def __init__(self):
self.tag = 'DONE'
def __str__(self):
return 'Done!'.format(**self.__dict__)
class Target:
def __init__(self):
self.tag = 'TARGET'
def __str__(self):
return 'Use settings file for target'.format(**self.__dict__)
class Heat:
def __init__(self, temp):
self.tag = 'HEAT'
self.temp = temp
def __str__(self):
return 'Heat to {temp}°'.format(**self.__dict__)
class Cook:
def __init__(self, temp, time):
self.tag = 'COOK'
self.temp = temp
self.time = time
def __str__(self):
self.timestring = datetime.timedelta(seconds=self.time)
return 'Cook at {temp}° for {timestring}'.format(**self.__dict__)
def parse(command):
if not command or command[0] == '#':
return None
op, *args = command.split(' ')
if op == 'PAUSE':
return Pause(' '.join(args))
elif op == 'DONE':
return Done()
elif op == 'TARGET':
return Target()
elif op == 'HEAT':
return Heat(float(args[0]))
elif op == 'COOK':
return Cook(float(args[0]), float(args[1]) * 60.)
return None