Skip to content

Commit 70b5796

Browse files
authored
Merge pull request #96 from LazeMSS/develop
0.0.2.3 release
2 parents 684655b + 7f5fc61 commit 70b5796

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

octoprint_toptemp/__init__.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# coding=utf-8
32
from __future__ import absolute_import
43

@@ -18,6 +17,7 @@
1817
import threading
1918
import queue
2019
import time
20+
import math
2121

2222
class TopTempPlugin(octoprint.plugin.StartupPlugin,
2323
octoprint.plugin.SettingsPlugin,
@@ -253,7 +253,7 @@ def on_settings_initialized(self):
253253
# make sure changed customMons are returned
254254
def on_settings_load(self):
255255
returnData = self._settings.get([],merged=True, asdict=True)
256-
returnData['customMon'] = self.customMon;
256+
returnData['customMon'] = self.customMon
257257
return returnData
258258

259259
# Save handler - has a bit of hack to cleanup remove custom monitors
@@ -336,7 +336,7 @@ def on_settings_save(self,data):
336336
data['customMon'] = newCust.copy()
337337

338338
data['firstRun'] = False
339-
self.customMon = newCust.copy();
339+
self.customMon = newCust.copy()
340340

341341
#Needed to write all the data
342342
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
@@ -573,8 +573,9 @@ def setGcodeMonNeed(self):
573573
# Trigger by the timer
574574
def runCustomMon(self,indx,cmd):
575575
code, out, err = self.runcommand(cmd)
576-
self.debugOut(cmd + " returned: " +out + " for index :"+indx)
576+
self.debugOut(cmd + "("+indx+") returned: " +out + " for index :"+indx)
577577
if code or err:
578+
self.debugOut(cmd + " failed with code: " + code + " error: " + error)
578579
self._plugin_manager.send_plugin_message(self._identifier, dict(success=False,error=err,returnCode=code,result=None,key=indx,type="custom"))
579580
else:
580581
self.handleCustomData(indx,out,time.time())
@@ -727,19 +728,23 @@ def runPSUtil(self,indx,cmd,returnData = False):
727728
return None
728729

729730
def handleCustomData(self,indx,out,time):
730-
self.debugOut("Got custom data: " + str(out))
731731
# Check
732732
if isinstance(out,(float, int)) or self.checkStringIsVal(out):
733+
self.debugOut("Got good custom data for "+indx+": " + str(out))
733734
resultData = [time,float(out)]
734735
if indx not in self.customHistory:
735736
self.customHistory[indx] = []
736737
self.customHistory[indx].append(resultData)
737-
# slice of 300
738-
self.customHistory[indx] = self.customHistory[indx][-300:]
738+
# we keep the history for double the needed just for fun
739+
sliceMe = math.ceil(0 - ((int(self.customMon[indx]['gHisSecs'])/int(self.customMon[indx]['interval']))))*2
740+
self.debugOut(indx + " only wants " + str(self.customMon[indx]['gHisSecs']) + " seconds of data - we need to slice: " + str(sliceMe))
741+
self.customHistory[indx] = self.customHistory[indx][sliceMe:]
739742

740743
# send to the frontend
741744
self.debugOut("Sending data to UI, " + indx + " : " + str(out))
742745
self._plugin_manager.send_plugin_message(self._identifier, dict(success=True,error=None,returnCode=0,result=resultData,key=indx,type="custom"))
746+
else:
747+
self.debugOut("Got BAD custom data for "+indx+": " + str(out))
743748

744749
# Available commands and parameters
745750
# testCmd: will run any command
@@ -775,7 +780,7 @@ def on_api_command(self, command, data):
775780
self._logger.info("Sending items monitored")
776781
sortOrder = self._settings.get(["sortOrder"],merged=True,asdict=True)
777782
custom = self._settings.get(["customMon"],merged=True,asdict=True)
778-
curTemps = self._printer.get_current_temperatures();
783+
curTemps = self._printer.get_current_temperatures()
779784
returnList = {}
780785
lastValues = {}
781786
for item in sortOrder:
@@ -869,16 +874,21 @@ def _merge_dictionaries(self,dict1, dict2):
869874

870875
# run command wrapper
871876
def runcommand (self,cmd):
877+
thisExec = None
878+
if sys.platform.startswith("linux"):
879+
thisExec = '/bin/bash'
872880
proc = subprocess.Popen(cmd,
873881
stdout=subprocess.PIPE,
874882
stderr=subprocess.PIPE,
875883
shell=True,
884+
executable=thisExec,
876885
universal_newlines=True)
877886
try:
878887
std_out, std_err = proc.communicate(timeout=self.cmdTimeout)
879888
except subprocess.TimeoutExpired:
880889
proc.kill()
881-
return -1, "\""+cmd+"\" timed out", "Maximum execution time, 5 seconds, exceeded!"
890+
self._logger.warning("\""+cmd+"\" timed out")
891+
return -1, "\""+cmd+"\" timed out", "Maximum execution time, "+self.cmdTimeout+" seconds, exceeded!"
882892

883893
return proc.returncode, std_out.strip(), std_err
884894

@@ -948,6 +958,10 @@ def gCodeHandlerSent(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **
948958
self.gcodeQue.put(dataSet)
949959

950960
def checkStringIsVal(self,inputStr):
961+
if inputStr == "":
962+
self.debugOut("input is empty")
963+
return False
964+
951965
inputStr = str(inputStr)
952966
if inputStr[0] in ["+", "-"]:
953967
inputStr = inputStr[1:]

octoprint_toptemp/static/js/TopTemp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ $(function() {
113113
}
114114
}else{
115115
var reval = 0;
116-
graphData = {'series' : [self.tempModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]};
116+
graphData = {'series' : [self.tempModel.temperatures[name].actual.slice((0-iSettings.gHisSecs())).map(function(val,i){return val[1]})]};
117117
}
118118

119119
var MinYVal = reval;
@@ -350,7 +350,7 @@ $(function() {
350350
self.customHistory[data.key] = [];
351351
}
352352
self.customHistory[data.key].push(data.result);
353-
self.customHistory[data.key] = self.customHistory[data.key].slice(-300);
353+
//self.customHistory[data.key] = self.customHistory[data.key].slice(-300);
354354
self.FormatTempHTML(data.key,{'actual' : data.result[1]},true);
355355
}
356356

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "Top Temp"
1515

1616
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17-
plugin_version = "0.0.2.2"
17+
plugin_version = "0.0.2.3"
1818

1919
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
2020
# module

0 commit comments

Comments
 (0)