|
1 |
| - |
2 | 1 | # coding=utf-8
|
3 | 2 | from __future__ import absolute_import
|
4 | 3 |
|
|
18 | 17 | import threading
|
19 | 18 | import queue
|
20 | 19 | import time
|
| 20 | +import math |
21 | 21 |
|
22 | 22 | class TopTempPlugin(octoprint.plugin.StartupPlugin,
|
23 | 23 | octoprint.plugin.SettingsPlugin,
|
@@ -253,7 +253,7 @@ def on_settings_initialized(self):
|
253 | 253 | # make sure changed customMons are returned
|
254 | 254 | def on_settings_load(self):
|
255 | 255 | returnData = self._settings.get([],merged=True, asdict=True)
|
256 |
| - returnData['customMon'] = self.customMon; |
| 256 | + returnData['customMon'] = self.customMon |
257 | 257 | return returnData
|
258 | 258 |
|
259 | 259 | # Save handler - has a bit of hack to cleanup remove custom monitors
|
@@ -336,7 +336,7 @@ def on_settings_save(self,data):
|
336 | 336 | data['customMon'] = newCust.copy()
|
337 | 337 |
|
338 | 338 | data['firstRun'] = False
|
339 |
| - self.customMon = newCust.copy(); |
| 339 | + self.customMon = newCust.copy() |
340 | 340 |
|
341 | 341 | #Needed to write all the data
|
342 | 342 | octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
@@ -573,8 +573,9 @@ def setGcodeMonNeed(self):
|
573 | 573 | # Trigger by the timer
|
574 | 574 | def runCustomMon(self,indx,cmd):
|
575 | 575 | 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) |
577 | 577 | if code or err:
|
| 578 | + self.debugOut(cmd + " failed with code: " + code + " error: " + error) |
578 | 579 | self._plugin_manager.send_plugin_message(self._identifier, dict(success=False,error=err,returnCode=code,result=None,key=indx,type="custom"))
|
579 | 580 | else:
|
580 | 581 | self.handleCustomData(indx,out,time.time())
|
@@ -727,19 +728,23 @@ def runPSUtil(self,indx,cmd,returnData = False):
|
727 | 728 | return None
|
728 | 729 |
|
729 | 730 | def handleCustomData(self,indx,out,time):
|
730 |
| - self.debugOut("Got custom data: " + str(out)) |
731 | 731 | # Check
|
732 | 732 | if isinstance(out,(float, int)) or self.checkStringIsVal(out):
|
| 733 | + self.debugOut("Got good custom data for "+indx+": " + str(out)) |
733 | 734 | resultData = [time,float(out)]
|
734 | 735 | if indx not in self.customHistory:
|
735 | 736 | self.customHistory[indx] = []
|
736 | 737 | 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:] |
739 | 742 |
|
740 | 743 | # send to the frontend
|
741 | 744 | self.debugOut("Sending data to UI, " + indx + " : " + str(out))
|
742 | 745 | 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)) |
743 | 748 |
|
744 | 749 | # Available commands and parameters
|
745 | 750 | # testCmd: will run any command
|
@@ -775,7 +780,7 @@ def on_api_command(self, command, data):
|
775 | 780 | self._logger.info("Sending items monitored")
|
776 | 781 | sortOrder = self._settings.get(["sortOrder"],merged=True,asdict=True)
|
777 | 782 | custom = self._settings.get(["customMon"],merged=True,asdict=True)
|
778 |
| - curTemps = self._printer.get_current_temperatures(); |
| 783 | + curTemps = self._printer.get_current_temperatures() |
779 | 784 | returnList = {}
|
780 | 785 | lastValues = {}
|
781 | 786 | for item in sortOrder:
|
@@ -869,16 +874,21 @@ def _merge_dictionaries(self,dict1, dict2):
|
869 | 874 |
|
870 | 875 | # run command wrapper
|
871 | 876 | def runcommand (self,cmd):
|
| 877 | + thisExec = None |
| 878 | + if sys.platform.startswith("linux"): |
| 879 | + thisExec = '/bin/bash' |
872 | 880 | proc = subprocess.Popen(cmd,
|
873 | 881 | stdout=subprocess.PIPE,
|
874 | 882 | stderr=subprocess.PIPE,
|
875 | 883 | shell=True,
|
| 884 | + executable=thisExec, |
876 | 885 | universal_newlines=True)
|
877 | 886 | try:
|
878 | 887 | std_out, std_err = proc.communicate(timeout=self.cmdTimeout)
|
879 | 888 | except subprocess.TimeoutExpired:
|
880 | 889 | 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!" |
882 | 892 |
|
883 | 893 | return proc.returncode, std_out.strip(), std_err
|
884 | 894 |
|
@@ -948,6 +958,10 @@ def gCodeHandlerSent(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **
|
948 | 958 | self.gcodeQue.put(dataSet)
|
949 | 959 |
|
950 | 960 | def checkStringIsVal(self,inputStr):
|
| 961 | + if inputStr == "": |
| 962 | + self.debugOut("input is empty") |
| 963 | + return False |
| 964 | + |
951 | 965 | inputStr = str(inputStr)
|
952 | 966 | if inputStr[0] in ["+", "-"]:
|
953 | 967 | inputStr = inputStr[1:]
|
|
0 commit comments