Skip to content

Commit

Permalink
Merge pull request #96 from LazeMSS/develop
Browse files Browse the repository at this point in the history
0.0.2.3 release
  • Loading branch information
LazeMSS authored Jan 15, 2023
2 parents 684655b + 7f5fc61 commit 70b5796
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
32 changes: 23 additions & 9 deletions octoprint_toptemp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# coding=utf-8
from __future__ import absolute_import

Expand All @@ -18,6 +17,7 @@
import threading
import queue
import time
import math

class TopTempPlugin(octoprint.plugin.StartupPlugin,
octoprint.plugin.SettingsPlugin,
Expand Down Expand Up @@ -253,7 +253,7 @@ def on_settings_initialized(self):
# make sure changed customMons are returned
def on_settings_load(self):
returnData = self._settings.get([],merged=True, asdict=True)
returnData['customMon'] = self.customMon;
returnData['customMon'] = self.customMon
return returnData

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

data['firstRun'] = False
self.customMon = newCust.copy();
self.customMon = newCust.copy()

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

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

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

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

# run command wrapper
def runcommand (self,cmd):
thisExec = None
if sys.platform.startswith("linux"):
thisExec = '/bin/bash'
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
executable=thisExec,
universal_newlines=True)
try:
std_out, std_err = proc.communicate(timeout=self.cmdTimeout)
except subprocess.TimeoutExpired:
proc.kill()
return -1, "\""+cmd+"\" timed out", "Maximum execution time, 5 seconds, exceeded!"
self._logger.warning("\""+cmd+"\" timed out")
return -1, "\""+cmd+"\" timed out", "Maximum execution time, "+self.cmdTimeout+" seconds, exceeded!"

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

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

def checkStringIsVal(self,inputStr):
if inputStr == "":
self.debugOut("input is empty")
return False

inputStr = str(inputStr)
if inputStr[0] in ["+", "-"]:
inputStr = inputStr[1:]
Expand Down
4 changes: 2 additions & 2 deletions octoprint_toptemp/static/js/TopTemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ $(function() {
}
}else{
var reval = 0;
graphData = {'series' : [self.tempModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]};
graphData = {'series' : [self.tempModel.temperatures[name].actual.slice((0-iSettings.gHisSecs())).map(function(val,i){return val[1]})]};
}

var MinYVal = reval;
Expand Down Expand Up @@ -350,7 +350,7 @@ $(function() {
self.customHistory[data.key] = [];
}
self.customHistory[data.key].push(data.result);
self.customHistory[data.key] = self.customHistory[data.key].slice(-300);
//self.customHistory[data.key] = self.customHistory[data.key].slice(-300);
self.FormatTempHTML(data.key,{'actual' : data.result[1]},true);
}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Top Temp"

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

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

0 comments on commit 70b5796

Please sign in to comment.