From b353b15004e8fa0c1b9600c0b56b569896a52f44 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Sun, 30 Sep 2018 15:07:50 -0600 Subject: [PATCH] Enable verbose output on sensor --- config.go | 1 + config_test.go | 4 +++- test_config.yml | 1 + thermostat.go | 10 ++++------ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 1bfb3b9..a0278df 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/config_test.go b/config_test.go index 0a516c4..d0b0a25 100644 --- a/config_test.go +++ b/config_test.go @@ -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}} diff --git a/test_config.yml b/test_config.yml index 3f7ef07..f2ac9d2 100644 --- a/test_config.yml +++ b/test_config.yml @@ -9,3 +9,4 @@ sensors: coolgpio: 17 coolinvert: false coolminutes: 10 + verbose: true diff --git a/thermostat.go b/thermostat.go index 2342e59..e17cc7e 100644 --- a/thermostat.go +++ b/thermostat.go @@ -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 - log.Printf("%s Temp: %.2f, Cooling: %t, Heating: %t, Duration: %.1f", sensor.Alias, s.Temp, s.Cooling, s.Heating, min) + 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: