Skip to content

Commit

Permalink
0.9.19
Browse files Browse the repository at this point in the history
Hide tab if there are no energy monitoring capable plugs configured
Fix countdown related issues
Fix gcode processing related issues
Abort power off now clears countdown timers
Polling moved to server side code
Added German translations
Changed automatic power off option to an idle timeout
Added cooldown option 
Added calculated cost per print job, **highly experimental, and possibly inaccurate**
  • Loading branch information
jneilliii authored Mar 15, 2020
1 parent 8439e60 commit 00f8aa0
Show file tree
Hide file tree
Showing 12 changed files with 2,116 additions and 315 deletions.
432 changes: 360 additions & 72 deletions octoprint_tplinksmartplug/__init__.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions octoprint_tplinksmartplug/static/css/tplinksmartplug.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ body #navbar_plugin_tplinksmartplug > a > span {
line-height: 34px;
}

#TPLinkPlugEditor div.modal-body {
overflow: visible !important;
}

@media (max-width: 800px) {
#touch body #tab_plugin_tplinksmartplug_link {
display:none;
Expand Down
81 changes: 52 additions & 29 deletions octoprint_tplinksmartplug/static/js/tplinksmartplug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,41 @@ $(function() {

self.settings = parameters[0];
self.loginState = parameters[1];
self.filesViewModel = parameters[2];

self.filesViewModel.getAdditionalData = function(data) {
var output = "";
if (data["gcodeAnalysis"]) {
if (data["gcodeAnalysis"]["dimensions"]) {
var dimensions = data["gcodeAnalysis"]["dimensions"];
output += gettext("Model size") + ": " + _.sprintf("%(width).2fmm × %(depth).2fmm × %(height).2fmm", dimensions);
output += "<br>";
}
if (data["gcodeAnalysis"]["filament"] && typeof(data["gcodeAnalysis"]["filament"]) === "object") {
var filament = data["gcodeAnalysis"]["filament"];
if (_.keys(filament).length === 1) {
output += gettext("Filament") + ": " + formatFilament(data["gcodeAnalysis"]["filament"]["tool" + 0]) + "<br>";
} else if (_.keys(filament).length > 1) {
_.each(filament, function(f, k) {
if (!_.startsWith(k, "tool") || !f || !f.hasOwnProperty("length") || f["length"] <= 0) return;
output += gettext("Filament") + " (" + gettext("Tool") + " " + k.substr("tool".length)
+ "): " + formatFilament(f) + "<br>";
});
}
}
output += gettext("Estimated print time") + ": " + (self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(data["gcodeAnalysis"]["estimatedPrintTime"]) : formatDuration(data["gcodeAnalysis"]["estimatedPrintTime"])) + "<br>";
}
if (data["prints"] && data["prints"]["last"]) {
output += gettext("Last printed") + ": " + formatTimeAgo(data["prints"]["last"]["date"]) + "<br>";
if (data["prints"]["last"]["printTime"]) {
output += gettext("Last print time") + ": " + formatDuration(data["prints"]["last"]["printTime"]) + "<br>";
}
}
if (data["statistics"] && data["statistics"]["lastPowerCost"]) {
output += gettext("Last power cost") + ": " + data["statistics"]["lastPowerCost"]["_default"] + "<br>";
}
return output;
};

self.arrSmartplugs = ko.observableArray();
self.isPrinting = ko.observable(false);
Expand All @@ -20,7 +55,7 @@ $(function() {
self.plotted_graph_records_offset = ko.observable(0);
self.dictSmartplugs = ko.observableDictionary();
self.refreshVisible = ko.observable(true);
self.automaticShutdownEnabled = ko.observable(false);
self.powerOffWhenIdle = ko.observable(false);
self.filteredSmartplugs = ko.computed(function(){
return ko.utils.arrayFilter(self.dictSmartplugs.items(), function(item) {
return "err_code" in item.value().emeter.get_realtime;
Expand All @@ -42,7 +77,7 @@ $(function() {
})

self.toggleShutdownTitle = ko.pureComputed(function() {
return self.automaticShutdownEnabled() ? 'Disable Automatic Power Off' : 'Enable Automatic Power Off';
return self.settings.settings.plugins.tplinksmartplug.powerOffWhenIdle() ? 'Disable Automatic Power Off' : 'Enable Automatic Power Off';
})

// Hack to remove automatically added Cancel button
Expand All @@ -57,7 +92,7 @@ $(function() {
confirm: {
confirm: true,
buttons: [{
text: 'Cancel Power Off',
text: gettext('Cancel Power Off'),
addClass: 'btn-block btn-danger',
promptTrigger: true,
click: function(notice, value){
Expand All @@ -75,14 +110,14 @@ $(function() {
}
};

self.onAutomaticShutdownEvent = function() {
if (self.automaticShutdownEnabled()) {
self.onToggleAutomaticShutdown = function(data) {
if (self.settings.settings.plugins.tplinksmartplug.powerOffWhenIdle()) {
$.ajax({
url: API_BASEURL + "plugin/tplinksmartplug",
type: "POST",
dataType: "json",
data: JSON.stringify({
command: "enableAutomaticShutdown"
command: "disableAutomaticShutdown"
}),
contentType: "application/json; charset=UTF-8"
})
Expand All @@ -92,23 +127,13 @@ $(function() {
type: "POST",
dataType: "json",
data: JSON.stringify({
command: "disableAutomaticShutdown"
command: "enableAutomaticShutdown"
}),
contentType: "application/json; charset=UTF-8"
})
}
}

self.automaticShutdownEnabled.subscribe(self.onAutomaticShutdownEvent, self);

self.onToggleAutomaticShutdown = function(data) {
if (self.automaticShutdownEnabled()) {
self.automaticShutdownEnabled(false);
} else {
self.automaticShutdownEnabled(true);
}
}

self.abortShutdown = function(abortShutdownValue) {
self.timeoutPopup.remove();
self.timeoutPopup = undefined;
Expand Down Expand Up @@ -192,10 +217,6 @@ $(function() {
var plugs_updated = (ko.toJSON(self.arrSmartplugs()) !== ko.toJSON(self.settings.settings.plugins.tplinksmartplug.arrSmartplugs()));
self.arrSmartplugs(self.settings.settings.plugins.tplinksmartplug.arrSmartplugs());
if(plugs_updated){
/* console.log('onEventSettingsUpdated:');
console.log('arrSmartplugs: ' + ko.toJSON(self.arrSmartplugs()));
console.log('settings.settings.plugins.tplinksmartplug.arrSmartplugs: ' + ko.toJSON(self.settings.settings.plugins.tplinksmartplug.arrSmartplugs()));
console.log('arrSmartplugs changed, checking statuses'); */
self.checkStatuses();
}
}
Expand Down Expand Up @@ -265,15 +286,20 @@ $(function() {
return;
}

if(/* data.currentState || */ data.check_status){
if(data.currentState){
self.updateDictionary(data);
}

if(data.check_status){
self.checkStatus(data.ip);
}

if(data.updatePlot && window.location.href.indexOf('tplinksmartplug') > 0){
self.plotEnergyData();
}

if(data.automaticShutdownEnabled) {
self.automaticShutdownEnabled(data.automaticShutdownEnabled);
if(data.hasOwnProperty("powerOffWhenIdle")) {
self.settings.settings.plugins.tplinksmartplug.powerOffWhenIdle(data.powerOffWhenIdle);

if (data.type == "timeout") {
if ((data.timeout_value != null) && (data.timeout_value > 0)) {
Expand Down Expand Up @@ -509,15 +535,12 @@ $(function() {
self.checkStatus(item.ip());
}
});
if (self.settings.settings.plugins.tplinksmartplug.pollingEnabled() && parseInt(self.settings.settings.plugins.tplinksmartplug.pollingInterval(),10) > 0) {
setTimeout(function() {self.checkStatuses();}, (parseInt(self.settings.settings.plugins.tplinksmartplug.pollingInterval(),10) * 60000));
};
};
}

OCTOPRINT_VIEWMODELS.push([
tplinksmartplugViewModel,
["settingsViewModel","loginStateViewModel"],
["#navbar_plugin_tplinksmartplug","#settings_plugin_tplinksmartplug","#sidebar_plugin_tplinksmartplug_wrapper","#tab_plugin_tplinksmartplug"]
["settingsViewModel","loginStateViewModel", "filesViewModel"],
["#navbar_plugin_tplinksmartplug","#settings_plugin_tplinksmartplug","#sidebar_plugin_tplinksmartplug_wrapper","#tab_plugin_tplinksmartplug","#tab_plugin_tplinksmartplug_link"]
]);
});
Loading

0 comments on commit 00f8aa0

Please sign in to comment.