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"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -64,16 +65,7 @@ func UpdateSensorConfig(s Sensor) error {
|
||||||
|
|
||||||
for i := range config.Sensors {
|
for i := range config.Sensors {
|
||||||
if config.Sensors[i].ID == s.ID {
|
if config.Sensors[i].ID == s.ID {
|
||||||
config.Sensors[i].Alias = s.Alias
|
copier.Copy(&config.Sensors[i], &s)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@ func Test_UpdateSensorConfig(t *testing.T) {
|
||||||
Sensors: []Sensor{
|
Sensors: []Sensor{
|
||||||
Sensor{
|
Sensor{
|
||||||
Alias: "foo",
|
Alias: "foo",
|
||||||
|
CoolDisable: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Users: []User{},
|
Users: []User{},
|
||||||
ListenAddr: ":8080",
|
ListenAddr: ":8080",
|
||||||
}
|
}
|
||||||
newSensor := Sensor{Alias: "bar"}
|
newSensor := Sensor{Alias: "bar", CoolDisable: false}
|
||||||
|
|
||||||
// Create a temp file
|
// Create a temp file
|
||||||
tmpfile, err := ioutil.TempFile("", "tempgopher")
|
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 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/normalize.css">
|
||||||
<link rel="stylesheet" href="css/skeleton.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">
|
<link rel="icon" type="image/png" href="img/favicon.png">
|
||||||
<script src="js/jquery.min.js"></script>
|
<script src="js/jquery.min.js"></script>
|
||||||
<script src="/jsconfig.js"></script>
|
<script src="/jsconfig.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ function appendData(data) {
|
||||||
var rowdiv = $("<div></div>");
|
var rowdiv = $("<div></div>");
|
||||||
rowdiv.addClass("row");
|
rowdiv.addClass("row");
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// Display temperature
|
// Display temperature
|
||||||
if (jsconfig.fahrenheit) {
|
if (jsconfig.fahrenheit) {
|
||||||
var temp = celsiusToFahrenheit(parseFloat(data.temp)).toFixed(1) + "°F";
|
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);
|
var tempdiv = $("<div></div>").addClass("two columns").append(temph);
|
||||||
rowdiv.append(tempdiv);
|
rowdiv.append(tempdiv);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// Display status
|
// Display status
|
||||||
if (data.cooling) {
|
if (data.cooling) {
|
||||||
var statustext = "Cooling"
|
var statustext = "Cooling"
|
||||||
|
|
@ -88,14 +90,16 @@ function appendData(data) {
|
||||||
var statustext = "Idle"
|
var statustext = "Idle"
|
||||||
}
|
}
|
||||||
var statusp = $("<p></p>").html(statustext);
|
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);
|
rowdiv.append(statusdiv);
|
||||||
|
|
||||||
// Display sensor config
|
// Make AJAX call to get current configuration of the sensor
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: jsconfig.baseurl + "/api/config/sensors/" + data.alias,
|
url: jsconfig.baseurl + "/api/config/sensors/" + data.alias,
|
||||||
beforeSend: authHeaders
|
beforeSend: authHeaders
|
||||||
}).then(function(configData){
|
}).then(function(configData){
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Display current configuration
|
||||||
if (jsconfig.fahrenheit) {
|
if (jsconfig.fahrenheit) {
|
||||||
var degUnit = "°F";
|
var degUnit = "°F";
|
||||||
var hightemp = celsiusToFahrenheit(parseFloat(configData.hightemp)).toFixed(1);
|
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);
|
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);
|
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) {
|
if (jsconfig.fahrenheit) {
|
||||||
var newHT = fahrenheitToCelsius(parseFloat(htIn.val()));
|
var newHT = fahrenheitToCelsius(parseFloat(htIn.val()));
|
||||||
var newLT = fahrenheitToCelsius(parseFloat(ltIn.val()));
|
var newLT = fahrenheitToCelsius(parseFloat(ltIn.val()));
|
||||||
|
|
@ -148,9 +174,11 @@ function appendData(data) {
|
||||||
"heatgpio": configData.heatgpio,
|
"heatgpio": configData.heatgpio,
|
||||||
"heatinvert": configData.heatInvert,
|
"heatinvert": configData.heatInvert,
|
||||||
"heatminutes": parseFloat(hmIn.val()),
|
"heatminutes": parseFloat(hmIn.val()),
|
||||||
|
"heatdisable": !hon.is(":checked"),
|
||||||
"coolgpio": configData.coolgpio,
|
"coolgpio": configData.coolgpio,
|
||||||
"coolinvert": configData.coolinvert,
|
"coolinvert": configData.coolinvert,
|
||||||
"coolminutes": parseFloat(cmIn.val()),
|
"coolminutes": parseFloat(cmIn.val()),
|
||||||
|
"cooldisable": !con.is(":checked"),
|
||||||
"verbose": configData.verbose
|
"verbose": configData.verbose
|
||||||
}])
|
}])
|
||||||
});
|
});
|
||||||
|
|
@ -165,10 +193,8 @@ function appendData(data) {
|
||||||
renderThermostats();
|
renderThermostats();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!configData.heatdisable || !configData.cooldisable) {
|
var buttonDiv = $("<div></div>").addClass("two columns").append(yesButton).append($("<br>")).append(noButton);
|
||||||
var buttonDiv = $("<div></div>").addClass("three columns").append(yesButton).append(noButton);
|
|
||||||
rowdiv.append(buttonDiv);
|
rowdiv.append(buttonDiv);
|
||||||
}
|
|
||||||
|
|
||||||
// Add things back to the thermostat list
|
// Add things back to the thermostat list
|
||||||
$("#thermostats").append(titlediv);
|
$("#thermostats").append(titlediv);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue