diff --git a/html/js/thermostat.js b/html/js/thermostat.js
index 9f7c85b..136b9ff 100644
--- a/html/js/thermostat.js
+++ b/html/js/thermostat.js
@@ -2,6 +2,10 @@ function celsiusToFahrenheit(degree) {
return degree * 1.8 + 32;
}
+function fahrenheitToCelsius(degree) {
+ return (degree - 32) * 5 / 9;
+}
+
function renderThermostats() {
$.ajax({
url: jsconfig.baseurl + "/api/status/"
@@ -35,7 +39,7 @@ function renderThermostats() {
var statustext = "Idle"
}
var statusp = $("
").html(statustext);
- var statusdiv = $("").addClass("three columns").append(statusp);
+ var statusdiv = $("").addClass("two columns").append(statusp);
rowdiv.append(statusdiv);
// Display sensor config
@@ -43,23 +47,69 @@ function renderThermostats() {
url: jsconfig.baseurl + "/api/config/sensors/" + data[key].alias
}).then(function(configData){
if (jsconfig.fahrenheit) {
- var hightemp = celsiusToFahrenheit(parseFloat(configData.hightemp)).toFixed(1) + "°F";
- var lowtemp = celsiusToFahrenheit(parseFloat(configData.lowtemp)).toFixed(1) + "°F";
+ var degUnit = "°F";
+ var hightemp = celsiusToFahrenheit(parseFloat(configData.hightemp)).toFixed(1);
+ var lowtemp = celsiusToFahrenheit(parseFloat(configData.lowtemp)).toFixed(1);
} else {
- var hightemp = parseFloat(configData.hightemp).toFixed(1) + "°C";
- var lowtemp = parseFloat(configData.lowtemp).toFixed(1) + "°C";
+ var hightemp = parseFloat(configData.hightemp).toFixed(1);
+ var lowtemp = parseFloat(configData.lowtemp).toFixed(1);
}
- configText = "Chills for " + configData.coolminutes + " minutes when > " + hightemp + ".
";
- configText += "Heats for " + configData.heatminutes + " minutes when < " + lowtemp + ".";
- var configp = $("").html(configText);
- var configdiv = $("").addClass("seven columns").append(configp);
+ rp = '[0-9]+(\.[0-9]+)?'
+
+ var cmIn = $("").attr("id", "cm" + configData.alias).val(configData.coolminutes).attr("size", "2").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)});
+ var htIn = $("").attr("id", "ht" + configData.alias).val(hightemp).attr("size", "4").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)});
+ var hmIn = $("").attr("id", "hm" + configData.alias).val(configData.heatminutes).attr("size", "2").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)});
+ var ltIn = $("").attr("id", "lt" + configData.alias).val(lowtemp).attr("size", "4").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)});
+
+ var configp = $("").text("Chills for ").append(cmIn).append(" minutes when > ").append(htIn).append(degUnit).append($("
"));
+ configp.append("Heats for ").append(hmIn).append(" minutes when < ").append(ltIn).append(degUnit);
+
+ var configdiv = $("").addClass("five columns").append(configp);
rowdiv.append(configdiv);
- });
- // Add things back to the thermostat list
- $("#thermostats").append(titlediv);
- $("#thermostats").append(rowdiv);
+ var yesButton = $("").addClass("button button-primary").text("✔").css("margin-right", "5px").click(function() {
+ if (jsconfig.fahrenheit) {
+ var newHT = fahrenheitToCelsius(parseFloat(htIn.val()));
+ var newLT = fahrenheitToCelsius(parseFloat(ltIn.val()));
+ } else {
+ var newHT = parseFloat(htIn.val());
+ var newLT = parseFloat(ltIn.val());
+ }
+ $.ajax({
+ type: "POST",
+ url: jsconfig.baseurl + "/api/config/sensors",
+ data: JSON.stringify([{
+ "id": configData.id,
+ "alias": configData.alias,
+ "hightemp": newHT,
+ "lowtemp": newLT,
+ "heatgpio": configData.heatgpio,
+ "heatinvert": configData.heatInvert,
+ "heatminutes": parseFloat(hmIn.val()),
+ "coolgpio": configData.coolgpio,
+ "coolinvert": configData.coolinvert,
+ "coolminutes": parseFloat(cmIn.val()),
+ "verbose": configData.verbose
+ }])
+ })
+ window.setInterval(renderThermostats, 60000);
+ renderThermostats();
+ });
+
+ var noButton = $("").addClass("button").text("✘").click(function() {
+ window.setInterval(renderThermostats, 60000);
+ renderThermostats();
+ });
+
+ var buttonDiv = $("").addClass("three columns").append(yesButton).append(noButton);
+ rowdiv.append(buttonDiv);
+ //var confForm = $("").append(rowdiv);
+
+ // Add things back to the thermostat list
+ $("#thermostats").append(titlediv);
+ $("#thermostats").append(rowdiv);
+ });
};
});
};
@@ -75,4 +125,4 @@ function renderVersion() {
$(document).ready(renderVersion);
$(document).ready(renderThermostats);
-setInterval(renderThermostats, 60000)
+var rtHandle = window.setInterval(renderThermostats, 60000);
diff --git a/html/jsconfig.js b/html/jsconfig.js
index d435468..ca5fbc6 100644
--- a/html/jsconfig.js
+++ b/html/jsconfig.js
@@ -1,4 +1,4 @@
var jsconfig = {
- baseurl: "http://foo.bar",
+ baseurl: "http://beerpi.home.shoup.io:8080",
fahrenheit: true
};