2019-11-19 21:29:32 +01:00
|
|
|
$(function() {
|
2019-11-19 21:55:31 +01:00
|
|
|
function mystromswitchViewModel(parameters) {
|
2019-11-19 21:29:32 +01:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.loginState = parameters[0];
|
|
|
|
self.settings = parameters[1];
|
|
|
|
self.printer = parameters[2];
|
2019-11-20 20:46:04 +01:00
|
|
|
|
2019-11-24 16:38:21 +01:00
|
|
|
self.onOffButtonEnabled = ko.observable();
|
2020-02-29 16:08:03 +01:00
|
|
|
self.showShutdownOctopiOption = ko.observable();
|
|
|
|
self.showPowerOffPrintFinishOption = ko.observable();
|
2019-11-20 22:07:47 +01:00
|
|
|
self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue")
|
2019-11-25 21:00:24 +01:00
|
|
|
self.mystromswitchEnergyValue = document.getElementById("mystromswitchEnergyValue")
|
2019-11-20 22:02:01 +01:00
|
|
|
|
2019-11-24 15:14:11 +01:00
|
|
|
self.onToggleRelayEvent = function(){
|
|
|
|
$.ajax({
|
2019-11-24 15:45:12 +01:00
|
|
|
url: API_BASEURL + "plugin/mystromswitch",
|
2019-11-24 15:14:11 +01:00
|
|
|
type: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
data: JSON.stringify({
|
|
|
|
command: "toggleRelais",
|
|
|
|
}),
|
|
|
|
contentType: "application/json; charset=UTF-8"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-02-29 16:08:03 +01:00
|
|
|
//self.onmystromswitchEvent = function() {
|
2019-11-24 16:44:13 +01:00
|
|
|
|
2020-02-29 16:08:03 +01:00
|
|
|
//}
|
|
|
|
|
|
|
|
//self.onOffButtonEnabled.subscribe(self.onmystromswitchEvent, self);
|
|
|
|
|
|
|
|
self.onAutomaticShutdownEnabledChanged = function(){
|
|
|
|
var cmd = "disableShutdownAfterFinish";
|
|
|
|
if (self.automaticShutdownEnabled()) {
|
|
|
|
var cmd = "enableShutdownAfterFinish";
|
|
|
|
}
|
|
|
|
$.ajax({
|
|
|
|
url: API_BASEURL + "plugin/mystromswitch",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
data: JSON.stringify({
|
|
|
|
command: cmd
|
|
|
|
}),
|
|
|
|
contentType: "application/json; charset=UTF-8"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
self.onAutomaticPowerOffEnabledChanged = function(){
|
|
|
|
var cmd = "disablePowerOffAfterFinish";
|
|
|
|
if (self.automaticShutdownEnabled()) {
|
|
|
|
var cmd = "enablePowerOffAfterFinish";
|
|
|
|
}
|
|
|
|
$.ajax({
|
|
|
|
url: API_BASEURL + "plugin/mystromswitch",
|
|
|
|
type: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
data: JSON.stringify({
|
|
|
|
command: cmd
|
|
|
|
}),
|
|
|
|
contentType: "application/json; charset=UTF-8"
|
|
|
|
})
|
2019-11-19 21:29:32 +01:00
|
|
|
}
|
|
|
|
|
2020-02-29 16:39:59 +01:00
|
|
|
//self.automaticShutdownEnabled.subscribe(self.onAutomaticShutdownEnabledChanged,self);
|
|
|
|
//self.automaticPowerOffEnabled.subscribe(self.onAutomaticPowerOffEnabledChanged,self);
|
2019-11-19 21:29:32 +01:00
|
|
|
|
|
|
|
self.onDataUpdaterPluginMessage = function(plugin, data) {
|
2019-11-19 21:55:31 +01:00
|
|
|
if (plugin != "mystromswitch" && plugin != "octoprint_mystromswitch") {
|
2019-11-19 21:29:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-11-24 16:38:21 +01:00
|
|
|
self.onOffButtonEnabled(data.onOffButtonEnabled);
|
2020-02-29 16:28:30 +01:00
|
|
|
self.showShutdownOctopiOption(data.showShutdownOctopiOption);
|
|
|
|
self.showPowerOffPrintFinishOption(data.showPowerOffPrintFinishOption);
|
2019-11-25 21:00:24 +01:00
|
|
|
self.mystromswitchEnergyValue.innerHTML = "Energy: "+data.energy.toFixed(1)+"Wh"
|
2019-11-24 15:14:11 +01:00
|
|
|
if(data.relay == false){
|
|
|
|
self.mystromswitchPowerValue.innerHTML = "Relay is off";
|
|
|
|
} else if (data.power != null) {
|
|
|
|
self.mystromswitchPowerValue.innerHTML = "Power Consumption "+data.power.toFixed(1)+"W";
|
2020-02-29 16:28:30 +01:00
|
|
|
}else{
|
|
|
|
self.mystromswitchPowerValue.innerHTML = "myStrom switch not reachable"
|
2019-11-24 15:14:11 +01:00
|
|
|
}
|
2019-11-19 21:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OCTOPRINT_VIEWMODELS.push([
|
2019-11-19 21:55:31 +01:00
|
|
|
mystromswitchViewModel,
|
2019-11-19 21:29:32 +01:00
|
|
|
["loginStateViewModel", "settingsViewModel", "printerStateViewModel"],
|
2019-11-19 21:55:31 +01:00
|
|
|
$(".sidebar_plugin_mystromswitch").get(0)
|
2019-11-19 21:29:32 +01:00
|
|
|
]);
|
|
|
|
});
|