@@ -3,23 +3,28 @@ var temperature = require("../modules/temperature");
3
3
var display = require ( "../modules/display/display" ) ;
4
4
5
5
const controlModes = {
6
- MANUAL : 'user ' ,
6
+ MANUAL : 'manual ' ,
7
7
SCHEDULE : "schedule"
8
8
} ;
9
9
10
10
const climateModes = {
11
11
OFF : 'off' ,
12
12
HEAT : 'heat' ,
13
13
COOL : 'cool' ,
14
- FAN : 'fan' ,
15
14
} ;
16
15
17
- let controlMode = controlModes . SCHEDULE ;
18
- let climateMode = climateModes . OFF ; // save/load this from a file later
16
+ const fanModes = {
17
+ OFF : 'off' ,
18
+ ON : 'on' ,
19
+ } ;
20
+
21
+ var controlMode = controlModes . SCHEDULE ;
22
+ var climateMode = climateModes . OFF ; // save/load this from a file later
23
+ var fanMode = fanModes . OFF ; // save/load this from a file later
19
24
20
- let targetTemp = - 1 ;
21
- let running = 0 ;
22
- let overshootRange = 2 ;
25
+ var targetTemp = - 1 ;
26
+ var climateRunning = 0 ;
27
+ var overshootRange = 2 ;
23
28
24
29
const displayCycles = {
25
30
CURRENT : "current" ,
@@ -32,22 +37,49 @@ let displayCycle = displayCycles.CURRENT;
32
37
function watchTemperature ( ) {
33
38
temperature . getTemp ( ) . then ( function ( temp ) {
34
39
35
- if ( running ) { // If heat or cool is running, check if it's time to shut off
40
+ temp = parseFloat ( temp ) ;
41
+
42
+ console . log ( ) ;
43
+ console . log ( "Current temp: " + temp ) ;
44
+ console . log ( "Target temp: " + targetTemp ) ;
45
+ console . log ( "Control Mode: " + controlMode ) ;
46
+ console . log ( "Climate Mode: " + climateMode ) ;
47
+ console . log ( "Running: " + climateRunning ) ;
48
+
49
+ if ( climateRunning ) { // If heat or cool is running, check if it's time to shut off
36
50
if ( climateMode === climateModes . HEAT ) {
51
+ console . log ( targetTemp + overshootRange ) ;
52
+ console . log ( temp > targetTemp + overshootRange ) ;
37
53
if ( temp > targetTemp + overshootRange ) {
38
54
// Shut off heat
55
+ console . log ( "Heat off" ) ;
39
56
thermostat . heatOff ( ) ;
57
+ climateRunning = 0 ;
40
58
}
41
59
} else if ( climateMode === climateModes . COOL ) {
42
60
if ( temp < targetTemp - overshootRange ) {
43
61
// Shut off AC
62
+ console . log ( "AC off" ) ;
44
63
thermostat . acOff ( ) ;
64
+ climateRunning = 0 ;
45
65
}
46
66
}
47
67
48
68
} else { // If not, check if it should be
49
- if ( temp < targetTemp - overshootRange ) {
50
-
69
+ if ( climateMode === climateModes . HEAT ) {
70
+ if ( temp < targetTemp - overshootRange ) {
71
+ // Turn on heat
72
+ console . log ( "Heat on" ) ;
73
+ thermostat . heatOn ( ) ;
74
+ climateRunning = 1 ;
75
+ }
76
+ } else if ( climateMode === climateModes . COOL ) {
77
+ if ( temp > targetTemp + overshootRange ) {
78
+ // Turn off AC
79
+ console . log ( "AC on" ) ;
80
+ thermostat . acOn ( ) ;
81
+ climateRunning = 1 ;
82
+ }
51
83
}
52
84
}
53
85
@@ -101,30 +133,69 @@ module.exports = {
101
133
} ) ;
102
134
} ,
103
135
104
- setMode : function ( m ) {
136
+ setControlMode : function ( m ) {
137
+ switch ( m ) {
138
+ case ( "manual" ) :
139
+ controlMode = controlModes . MANUAL ;
140
+ break ;
141
+ case ( "schedule" ) :
142
+ controlMode = controlModes . SCHEDULE ;
143
+ break ;
144
+ }
145
+ watchTemperature ( ) ;
146
+ return true ;
147
+
148
+ } ,
149
+
150
+ setClimateMode : function ( m ) {
105
151
if ( controlMode !== controlModes . MANUAL ) {
106
152
return false ;
107
153
} else {
154
+ climateRunning = 0 ;
155
+ thermostat . heatOff ( ) ;
156
+ thermostat . acOff ( ) ;
108
157
switch ( m ) {
109
158
case ( "heat" ) :
110
159
climateMode = climateModes . HEAT ;
111
160
break ;
112
161
case ( "cool" ) :
113
162
climateMode = climateModes . COOL ;
114
163
break ;
115
- case ( "fan" ) :
116
- climateMode = climateModes . FAN ;
117
- break ;
118
164
case ( "off" ) :
119
165
climateMode = climateModes . OFF ;
120
166
break ;
121
167
}
168
+ watchTemperature ( ) ;
169
+ return true ;
170
+ }
171
+ } ,
172
+
173
+ setFanMode : function ( m ) {
174
+ if ( controlMode !== controlModes . MANUAL ) {
175
+ return false ;
176
+ } else {
177
+ switch ( m ) {
178
+ case ( "on" ) :
179
+ fanMode = fanModes . ON ;
180
+ thermostat . fanOn ( ) ;
181
+ break ;
182
+ case ( "off" ) :
183
+ fanMode = fanModes . OFF ;
184
+ thermostat . fanOff ( ) ;
185
+ break ;
186
+ }
122
187
return true ;
123
188
}
124
189
} ,
125
190
126
191
setTemp : function ( temp ) {
127
- targetTemp = temp ;
192
+ if ( controlMode !== controlModes . MANUAL ) {
193
+ return false ;
194
+ } else {
195
+ targetTemp = parseInt ( temp ) ;
196
+ watchTemperature ( ) ;
197
+ return true ;
198
+ }
128
199
}
129
200
130
201
} ;
0 commit comments