1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 16:49:42 +00:00

Enable verbose output on sensor

This commit is contained in:
Emma 2018-09-30 15:07:50 -06:00
parent 31ffadd2cf
commit b353b15004
4 changed files with 9 additions and 7 deletions

View file

@ -18,6 +18,7 @@ type Sensor struct {
CoolGPIO int32 `yaml:"coolgpio"`
CoolInvert bool `yaml:"coolinvert"`
CoolMinutes float64 `yaml:"coolminutes"`
Verbose bool `yaml:"verbose"`
}
// Config contains the applications configuration

View file

@ -17,7 +17,9 @@ func Test_LoadConfig(t *testing.T) {
HeatMinutes: 5,
CoolGPIO: 17,
CoolInvert: false,
CoolMinutes: 10}
CoolMinutes: 10,
Verbose: true,
}
testConfig := Config{Sensors: []Sensor{testSensor}}

View file

@ -9,3 +9,4 @@ sensors:
coolgpio: 17
coolinvert: false
coolminutes: 10
verbose: true

View file

@ -76,29 +76,25 @@ func RunThermostat(sensor Sensor, sc chan<- State, run *bool, wg *sync.WaitGroup
switch {
case t > sensor.HighTemp && t < sensor.HighTemp:
log.Panic("Invalid state! Temperature is too high AND too low!")
log.Println("Invalid state! Temperature is too high AND too low!")
case t > sensor.HighTemp && s.Heating:
PinSwitch(hpin, false, sensor.HeatInvert)
log.Printf("%s Turned off heat", sensor.Alias)
s.Heating = false
s.Changed = time.Now()
case t > sensor.HighTemp && s.Cooling:
break
case t > sensor.HighTemp && min > sensor.CoolMinutes:
PinSwitch(cpin, true, sensor.CoolInvert)
log.Printf("%s Turned on cool", sensor.Alias)
s.Cooling = true
s.Changed = time.Now()
case t < sensor.LowTemp && s.Cooling:
PinSwitch(cpin, false, sensor.CoolInvert)
log.Printf("%s Turned off cool", sensor.Alias)
s.Cooling = false
s.Changed = time.Now()
case t < sensor.LowTemp && s.Heating:
break
case t < sensor.LowTemp && min > sensor.HeatMinutes:
PinSwitch(hpin, true, sensor.HeatInvert)
log.Printf("%s Turned on heat", sensor.Alias)
s.Heating = true
s.Changed = time.Now()
default:
@ -106,7 +102,9 @@ func RunThermostat(sensor Sensor, sc chan<- State, run *bool, wg *sync.WaitGroup
}
s.Temp = t
if sensor.Verbose {
log.Printf("%s Temp: %.2f, Cooling: %t, Heating: %t, Duration: %.1f", sensor.Alias, s.Temp, s.Cooling, s.Heating, min)
}
select {
case sc <- s: