@@ -9,9 +9,13 @@ import tconf
99import bstate
1010from w1thermsensor import W1ThermSensor
1111import subprocess
12+ import os
13+ import sys
14+
15+ devnull = open (os .devnull , 'w' )
16+
1217
1318
14- sensor = W1ThermSensor ()
1519
1620def db2local (b , db ):
1721 response = db .get_cmd (b .boiler_name ,b .boiler_name )
@@ -25,27 +29,27 @@ def db2local(b, db):
2529
2630
2731def boiler_state ():
28- out = subprocess .check_output ([tconf .relay_cmd ])
32+ out = subprocess .check_output ([tconf .relay_cmd ], stderr = devnull )
2933 if out :
3034 for l in out .splitlines ():
3135 state = l .split ('=' )
32- if len (state ) == 1 and state [0 ] == tconf .relay :
36+ if len (state ) == 2 and state [0 ] == tconf .relay :
3337 return state [1 ]
34- return None
38+ return - 1
3539
36- def boiler_on ():
37- cur_s = boiler_state ()
40+ def boiler_on (cur_s ):
3841 if cur_s == tconf .relay_on :
3942 return
4043
41- subprocess .check_output ([tconf .relay_cmd , "{0}={1}" .format (tconf .relay ,tconf .relay_on )])
44+ subprocess .check_output ([tconf .relay_cmd , "{0}={1}" .format (tconf .relay ,tconf .relay_on )],
45+ stderr = devnull )
4246
43- def boiler_off ():
44- cur_s = boiler_state ()
47+ def boiler_off (cur_s ):
4548 if cur_s == tconf .relay_off :
4649 return
4750
48- subprocess .check_output ([tconf .relay_cmd , "{0}={1}" .format (tconf .relay ,tconf .relay_off )])
51+ subprocess .check_output ([tconf .relay_cmd , "{0}={1}" .format (tconf .relay ,tconf .relay_off )],
52+ subprocess .devnull )
4953
5054def now_day ():
5155 now = datetime .datetime .now ()
@@ -55,19 +59,19 @@ def now_day():
5559 return 1
5660
5761
58- def run_cmd (cur_t , cmd ):
62+ def run_cmd (cur_t , cmd , cur_s ):
5963 target_t = cmd .get ('target' , tconf .def_temp )
6064 # command mode: 0 - always off; 1 - maintain target; 2 - target at night, 5 at day
6165 mode = cmd .get ('heating' , 1 )
6266 if mode == 0 :
63- boiler_off ();
67+ boiler_off (cur_s );
6468 else :
6569 if mode == 2 and now_day ():
6670 target_t = tconf .def_temp
6771 if cur_t < target_t :
68- boiler_on ()
72+ boiler_on (cur_s )
6973 else :
70- boiler_off ()
74+ boiler_off (cur_s )
7175
7276
7377
@@ -84,21 +88,22 @@ boiler = bstate.Boiler(thermo_name)
8488# Connect to Dynamodb
8589db = dyndb .Tempdb (tconf .url ,tconf .region )
8690
87-
91+ sensor = W1ThermSensor ()
8892
8993while True :
9094 boiler .read_state ()
9195 temp_in_c1 = sensor .get_temperature ()
9296 temp_in_c2 = sensor .get_temperature ()
97+ cur_s = boiler_state ()
9398 if temp_in_c1 :
94- print (time .time (),temp_in_c1 , temp_in_c2 , boiler .state ['target' ],boiler .state ['heating' ])
99+ print (time .time (),temp_in_c1 , temp_in_c2 , boiler .state ['target' ],boiler .state ['heating' ], cur_s )
95100 db .put_values (temp_in_c1 , temp_in_c2 , thermo_name ,boiler .state ['target' ],
96- boiler .state ['heating' ])
101+ boiler .state ['heating' ], cur_s )
97102 else :
98103 print ("ERR read invalid data from wired thermometr: '" )
99104
100105 boiler_cmd = db2local (boiler , db )
101- run_cmd (temp_in_c1 , boiler_cmd )
106+ run_cmd (temp_in_c1 , boiler_cmd , cur_s )
102107
103108 time .sleep (tconf .therm_rate )
104109
0 commit comments