mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 16:49:42 +00:00
Correctly account for future time
This commit is contained in:
parent
df8dbc6146
commit
f8765783c4
1 changed files with 6 additions and 10 deletions
|
|
@ -83,11 +83,9 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
|
||||||
// Temperature is too high and the cooling switch is still on, do nothing
|
// Temperature is too high and the cooling switch is still on, do nothing
|
||||||
case temp > sensor.HighTemp && state.Cooling:
|
case temp > sensor.HighTemp && state.Cooling:
|
||||||
break
|
break
|
||||||
// Temperature is too high, but duration hasn't been met
|
// Temperature is too high, but duration hasn't been counted
|
||||||
case temp > sensor.HighTemp:
|
case temp > sensor.HighTemp && duration < 0:
|
||||||
if state.Changed.After(time.Now()) {
|
state.Changed = time.Now()
|
||||||
state.Changed = time.Now()
|
|
||||||
}
|
|
||||||
// Temperature is too high and the duration has been long enough, start cooling
|
// Temperature is too high and the duration has been long enough, start cooling
|
||||||
case temp > sensor.HighTemp && duration > sensor.CoolMinutes:
|
case temp > sensor.HighTemp && duration > sensor.CoolMinutes:
|
||||||
PinSwitch(cpin, true, sensor.CoolInvert)
|
PinSwitch(cpin, true, sensor.CoolInvert)
|
||||||
|
|
@ -101,11 +99,9 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
|
||||||
// Temperature is too low and the heating switch is on, do nothing
|
// Temperature is too low and the heating switch is on, do nothing
|
||||||
case temp < sensor.LowTemp && state.Heating:
|
case temp < sensor.LowTemp && state.Heating:
|
||||||
break
|
break
|
||||||
// Temperature is too low, but duration hasn't been met
|
// Temperature is too low, but duration hasn't been counted
|
||||||
case temp < sensor.LowTemp:
|
case temp < sensor.LowTemp && duration < 0:
|
||||||
if state.Changed.After(time.Now()) {
|
state.Changed = time.Now()
|
||||||
state.Changed = time.Now()
|
|
||||||
}
|
|
||||||
// Temperature is too low and the duration has been long enough, start heating
|
// Temperature is too low and the duration has been long enough, start heating
|
||||||
case temp < sensor.LowTemp && duration > sensor.HeatMinutes:
|
case temp < sensor.LowTemp && duration > sensor.HeatMinutes:
|
||||||
PinSwitch(hpin, true, sensor.HeatInvert)
|
PinSwitch(hpin, true, sensor.HeatInvert)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue