mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 08:39:43 +00:00
Add ability to enable/disable heating/cooling via UI
Also fixes a bug that the new value wasn't getting copied to the new config Fixes #18
This commit is contained in:
parent
924473090e
commit
8aebae0ebe
5 changed files with 47 additions and 20 deletions
12
config.go
12
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
7
html/css/custom.css
Normal file
7
html/css/custom.css
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
label {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="css/normalize.css">
|
||||
<link rel="stylesheet" href="css/skeleton.css">
|
||||
<link rel="stylesheet" href="css/custom.css">
|
||||
<link rel="icon" type="image/png" href="img/favicon.png">
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="/jsconfig.js"></script>
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ function appendData(data) {
|
|||
var rowdiv = $("<div></div>");
|
||||
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 = $("<div></div>").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 = $("<p></p>").html(statustext);
|
||||
var statusdiv = $("<div></div>").addClass("two columns").append(statusp);
|
||||
var statusdiv = $("<div></div>").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 = $("<div></div>").addClass("five columns").append(configp);
|
||||
var configdiv = $("<div></div>").addClass("six columns").append(configp);
|
||||
rowdiv.append(configdiv);
|
||||
|
||||
var yesButton = $("<button></button>").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 = $('<input type="checkbox">').attr("id", "con" + configData.alias).prop('checked', conChecked).on('input', function(){window.clearInterval(rtHandle)})
|
||||
var coolCheck = $('<label></label>').text("❄️").prepend(con);
|
||||
|
||||
var honChecked = false;
|
||||
if (!configData.heatdisable) {
|
||||
honChecked = true;
|
||||
}
|
||||
var hon = $('<input type="checkbox">').attr("id", "hon" + configData.alias).prop('checked', honChecked).on('input', function(){window.clearInterval(rtHandle)})
|
||||
var heatCheck = $('<label></label>').text("🔥").prepend(hon);
|
||||
|
||||
|
||||
var offOnDiv = $("<div></div>").addClass("one columns").append(coolCheck).append(heatCheck);
|
||||
rowdiv.append(offOnDiv);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Create yes and no buttons
|
||||
var yesButton = $("<button></button>").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 = $("<div></div>").addClass("three columns").append(yesButton).append(noButton);
|
||||
rowdiv.append(buttonDiv);
|
||||
}
|
||||
var buttonDiv = $("<div></div>").addClass("two columns").append(yesButton).append($("<br>")).append(noButton);
|
||||
rowdiv.append(buttonDiv);
|
||||
|
||||
// Add things back to the thermostat list
|
||||
$("#thermostats").append(titlediv);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue