diff --git a/config.go b/config.go index 53120b1..5670b70 100644 --- a/config.go +++ b/config.go @@ -6,6 +6,7 @@ import ( "os" "syscall" + "github.com/jinzhu/copier" "gopkg.in/yaml.v2" ) @@ -64,16 +65,7 @@ func UpdateSensorConfig(s Sensor) error { for i := range config.Sensors { if config.Sensors[i].ID == s.ID { - config.Sensors[i].Alias = s.Alias - config.Sensors[i].HighTemp = s.HighTemp - config.Sensors[i].LowTemp = s.LowTemp - config.Sensors[i].HeatGPIO = s.HeatGPIO - config.Sensors[i].HeatInvert = s.HeatInvert - config.Sensors[i].HeatMinutes = s.HeatMinutes - config.Sensors[i].CoolGPIO = s.CoolGPIO - config.Sensors[i].CoolInvert = s.CoolInvert - config.Sensors[i].CoolMinutes = s.CoolMinutes - config.Sensors[i].Verbose = s.Verbose + copier.Copy(&config.Sensors[i], &s) } } diff --git a/config_test.go b/config_test.go index 86a20a6..052190a 100644 --- a/config_test.go +++ b/config_test.go @@ -14,13 +14,14 @@ func Test_UpdateSensorConfig(t *testing.T) { testConfig := Config{ Sensors: []Sensor{ Sensor{ - Alias: "foo", + Alias: "foo", + CoolDisable: true, }, }, Users: []User{}, ListenAddr: ":8080", } - newSensor := Sensor{Alias: "bar"} + newSensor := Sensor{Alias: "bar", CoolDisable: false} // Create a temp file tmpfile, err := ioutil.TempFile("", "tempgopher") diff --git a/html/css/custom.css b/html/css/custom.css new file mode 100644 index 0000000..d1cff1b --- /dev/null +++ b/html/css/custom.css @@ -0,0 +1,7 @@ +label { + font-weight: normal; +} + +input[type="checkbox"] { + margin-right: 0.5em; +} diff --git a/html/index.html b/html/index.html index 714e9ee..66b5c92 100644 --- a/html/index.html +++ b/html/index.html @@ -7,6 +7,7 @@ + diff --git a/html/js/thermostat.js b/html/js/thermostat.js index d159e7a..6cc1741 100644 --- a/html/js/thermostat.js +++ b/html/js/thermostat.js @@ -69,6 +69,7 @@ function appendData(data) { var rowdiv = $("
"); rowdiv.addClass("row"); + //////////////////////////////////////////////////////////////////////////// // Display temperature if (jsconfig.fahrenheit) { var temp = celsiusToFahrenheit(parseFloat(data.temp)).toFixed(1) + "°F"; @@ -79,6 +80,7 @@ function appendData(data) { var tempdiv = $("
").addClass("two columns").append(temph); rowdiv.append(tempdiv); + //////////////////////////////////////////////////////////////////////////// // Display status if (data.cooling) { var statustext = "Cooling" @@ -88,14 +90,16 @@ function appendData(data) { var statustext = "Idle" } var statusp = $("

").html(statustext); - var statusdiv = $("
").addClass("two columns").append(statusp); + var statusdiv = $("
").addClass("one columns").append(statusp); rowdiv.append(statusdiv); - // Display sensor config + // Make AJAX call to get current configuration of the sensor $.ajax({ url: jsconfig.baseurl + "/api/config/sensors/" + data.alias, beforeSend: authHeaders }).then(function(configData){ + //////////////////////////////////////////////////////////////////////// + // Display current configuration if (jsconfig.fahrenheit) { var degUnit = "°F"; var hightemp = celsiusToFahrenheit(parseFloat(configData.hightemp)).toFixed(1); @@ -125,10 +129,32 @@ function appendData(data) { configp.append("Heats for ").append(hmIn).append(" minutes when < ").append(ltIn).append(degUnit); } - var configdiv = $("
").addClass("five columns").append(configp); + var configdiv = $("
").addClass("six columns").append(configp); rowdiv.append(configdiv); - var yesButton = $("").addClass("button button-primary").text("✔").css("margin-right", "5px").click(function() { + //////////////////////////////////////////////////////////////////////// + // Display options to turn heating/cooling on/off + var conChecked = false; + if (!configData.cooldisable) { + conChecked = true; + } + var con = $('').attr("id", "con" + configData.alias).prop('checked', conChecked).on('input', function(){window.clearInterval(rtHandle)}) + var coolCheck = $('').text("❄️").prepend(con); + + var honChecked = false; + if (!configData.heatdisable) { + honChecked = true; + } + var hon = $('').attr("id", "hon" + configData.alias).prop('checked', honChecked).on('input', function(){window.clearInterval(rtHandle)}) + var heatCheck = $('').text("🔥").prepend(hon); + + + var offOnDiv = $("
").addClass("one columns").append(coolCheck).append(heatCheck); + rowdiv.append(offOnDiv); + + //////////////////////////////////////////////////////////////////////// + // Create yes and no buttons + var yesButton = $("").addClass("button button-primary").text("✔").click(function() { if (jsconfig.fahrenheit) { var newHT = fahrenheitToCelsius(parseFloat(htIn.val())); var newLT = fahrenheitToCelsius(parseFloat(ltIn.val())); @@ -148,9 +174,11 @@ function appendData(data) { "heatgpio": configData.heatgpio, "heatinvert": configData.heatInvert, "heatminutes": parseFloat(hmIn.val()), + "heatdisable": !hon.is(":checked"), "coolgpio": configData.coolgpio, "coolinvert": configData.coolinvert, "coolminutes": parseFloat(cmIn.val()), + "cooldisable": !con.is(":checked"), "verbose": configData.verbose }]) }); @@ -165,10 +193,8 @@ function appendData(data) { renderThermostats(); }); - if (!configData.heatdisable || !configData.cooldisable) { - var buttonDiv = $("
").addClass("three columns").append(yesButton).append(noButton); - rowdiv.append(buttonDiv); - } + var buttonDiv = $("
").addClass("two columns").append(yesButton).append($("
")).append(noButton); + rowdiv.append(buttonDiv); // Add things back to the thermostat list $("#thermostats").append(titlediv);