Mercurial > templog
comparison py/fridge.py @ 465:a40f30fad8f6
Merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 21 Jan 2013 07:25:52 +0800 |
parents | a91adc95543d |
children | 5d5424acfed0 |
comparison
equal
deleted
inserted
replaced
464:c3926e7cfb0c | 465:a40f30fad8f6 |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 from utils import L,W,E,EX | 2 from utils import L,W,E,EX,D |
3 import config | 3 import config |
4 import gevent | 4 import gevent |
5 | 5 |
6 class Fridge(gevent.Greenlet): | 6 class Fridge(gevent.Greenlet): |
7 | 7 |
48 % (self.value_file.name, buf)) | 48 % (self.value_file.name, buf)) |
49 return True | 49 return True |
50 | 50 |
51 # greenlet subclassed | 51 # greenlet subclassed |
52 def _run(self): | 52 def _run(self): |
53 if self.server.params.disabled: | |
54 L("Fridge is disabled") | |
53 while True: | 55 while True: |
54 self.do() | 56 self.do() |
55 gevent.sleep(config.FRIDGE_SLEEP) | 57 gevent.sleep(config.FRIDGE_SLEEP) |
56 | 58 |
57 def do(self): | 59 def do(self): |
67 | 69 |
68 off_time = self.server.now() - self.fridge_off_clock | 70 off_time = self.server.now() - self.fridge_off_clock |
69 | 71 |
70 if off_time < config.FRIDGE_DELAY: | 72 if off_time < config.FRIDGE_DELAY: |
71 L("fridge skipping, too early") | 73 L("fridge skipping, too early") |
74 return | |
75 | |
76 if params.disabled: | |
77 if self.is_on(): | |
78 L("Disabled, turning fridge off") | |
79 self.off() | |
72 return | 80 return |
73 | 81 |
74 # handle broken wort sensor | 82 # handle broken wort sensor |
75 if wort is not None: | 83 if wort is not None: |
76 self.wort_valid_clock = self.server.now() | 84 self.wort_valid_clock = self.server.now() |
91 overshoot = 0 | 99 overshoot = 0 |
92 if on_time > params.overshoot_delay: | 100 if on_time > params.overshoot_delay: |
93 overshoot = params.overshoot_factor \ | 101 overshoot = params.overshoot_factor \ |
94 * min(self.OVERSHOOT_MAX_DIV, on_time) \ | 102 * min(self.OVERSHOOT_MAX_DIV, on_time) \ |
95 / self.OVERSHOOT_MAX_DIV | 103 / self.OVERSHOOT_MAX_DIV |
96 L("on_time %(on_time)f, overshoot %(overshoot)f" % locals()) | 104 D("on_time %(on_time)f, overshoot %(overshoot)f" % locals()) |
97 | 105 |
98 if wort is not None: | 106 if wort is not None: |
99 if (wort - overshoot) < params.fridge_setpoint: | 107 if (wort - overshoot) < params.fridge_setpoint: |
100 L("wort has cooled enough") | 108 L("wort has cooled enough") |
101 turn_off = True | 109 turn_off = True |
113 else: | 121 else: |
114 # fridge is off | 122 # fridge is off |
115 turn_on = False | 123 turn_on = False |
116 if wort is not None: | 124 if wort is not None: |
117 if wort >= wort_max: | 125 if wort >= wort_max: |
118 L("Wort is too hot") | 126 L("Wort is too hot %f, max %f" % (wort, wort_max)) |
119 turn_on = True | 127 turn_on = True |
120 else: | 128 else: |
121 # wort sensor is broken | 129 # wort sensor is broken |
122 if fridge is not None and fridge >= fridge_max: | 130 if fridge is not None and fridge >= fridge_max: |
123 W("frdge on fallback") | 131 W("frdge on fallback") |
124 turn_on = True | 132 turn_on = True |
125 | 133 |
126 if turn_on: | 134 if turn_on: |
127 L("Turning fridge on") | 135 L("Turning fridge on") |
128 self.on() | 136 self.on() |
129 fridge_on_clock = self.server.now() | 137 self.fridge_on_clock = self.server.now() |