Skip to content

Commit

Permalink
set port more correctly in main
Browse files Browse the repository at this point in the history
send preimg and postimg command only when there should be image
  • Loading branch information
giloser committed Feb 5, 2021
1 parent 3ee239f commit 4aa09b6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
67 changes: 34 additions & 33 deletions octoprint_telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def on_after_startup(self):

def on_startup(self, host, port):
try:
self.tcmd.port = port
self.tcmd.port = self._settings.global_get(["server","port"])
#self.main.tcmd.port = port
except Exception as ex:
self._logger.error("Exception on_startup: "+ str(ex) )
Expand Down Expand Up @@ -1141,21 +1141,21 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,
self._logger.debug("start _send_msg")

try:
##find a way to decide if should and what command to light on
premethod = self._settings.get(["PreImgMethod"])
self._logger.debug("PreImgMethod {}".format(premethod))
precommand = self._settings.get(["PreImgCommand"])
if premethod == "GCODE":
self._logger.debug("PreImgCommand {}".format(precommand))
self._printer.commands(precommand)
elif premethod == "SYSTEM":
self._logger.debug("PreImgCommand {}".format(precommand))
p = subprocess.Popen(precommand, shell=True)
self._logger.debug("PreImg system command executed. PID={}, Command={}".format(p.pid, precommand))
while p.poll() is None:
time.sleep(0.1)
r = p.returncode
self._logger.debug("PreImg system command returned: {}".format(r))
if with_image or with_gif:
premethod = self._settings.get(["PreImgMethod"])
self._logger.debug("PreImgMethod {}".format(premethod))
precommand = self._settings.get(["PreImgCommand"])
if premethod == "GCODE":
self._logger.debug("PreImgCommand {}".format(precommand))
self._printer.commands(precommand)
elif premethod == "SYSTEM":
self._logger.debug("PreImgCommand {}".format(precommand))
p = subprocess.Popen(precommand, shell=True)
self._logger.debug("PreImg system command executed. PID={}, Command={}".format(p.pid, precommand))
while p.poll() is None:
time.sleep(0.1)
r = p.returncode
self._logger.debug("PreImg system command returned: {}".format(r))
except Exception as ex:
self._logger.exception("Exception PreImgMethod: "+ str(ex) )

Expand Down Expand Up @@ -1325,7 +1325,7 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,

try:
thumbnail_data = None
if kwargs['thumbnail'] != None:
if 'thumbnail' in kwargs and kwargs['thumbnail'] != None:
self._logger.debug("send_file thumbnail whithout message: "+str(kwargs['thumbnail']))
url = "http://localhost:"+str(self.tcmd.port)+ "/" + str(kwargs['thumbnail'])

Expand Down Expand Up @@ -1402,21 +1402,22 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None,
self._logger.exception("Caught an exception in _send_msg(): " + str(ex))

try:
##find a way to decide if should and what command to light on
postmethod = self._settings.get(["PostImgMethod"])
self._logger.debug("PostImgMethod {}".format(postmethod))
postcommand = self._settings.get(["PostImgCommand"])
if postmethod == "GCODE":
self._logger.debug("PostImgCommand {}".format(postcommand))
self._printer.commands(postcommand)
elif postmethod == "SYSTEM":
self._logger.debug("PostImgCommand {}".format(postcommand))
p = subprocess.Popen(postcommand, shell=True)
self._logger.debug("PostImg system command executed. PID={}, Command={}".format(p.pid, postcommand))
while p.poll() is None:
time.sleep(0.1)
r = p.returncode
self._logger.debug("PostImg system command returned: {}".format(r))
if with_image or with_gif:
##find a way to decide if should and what command to light on
postmethod = self._settings.get(["PostImgMethod"])
self._logger.debug("PostImgMethod {}".format(postmethod))
postcommand = self._settings.get(["PostImgCommand"])
if postmethod == "GCODE":
self._logger.debug("PostImgCommand {}".format(postcommand))
self._printer.commands(postcommand)
elif postmethod == "SYSTEM":
self._logger.debug("PostImgCommand {}".format(postcommand))
p = subprocess.Popen(postcommand, shell=True)
self._logger.debug("PostImg system command executed. PID={}, Command={}".format(p.pid, postcommand))
while p.poll() is None:
time.sleep(0.1)
r = p.returncode
self._logger.debug("PostImg system command returned: {}".format(r))
except Exception as ex:
self._logger.exception("Exception PostImgMethod: "+ str(ex) )

Expand Down Expand Up @@ -1598,7 +1599,7 @@ def get_current_layers(self):
if self._plugin_manager.get_plugin("DisplayLayerProgress",True):
headers = { 'X-Api-Key' : self._settings.global_get(['api','key']),}
#r = requests.get("http://localhost:"+ str(self.tcmd.port) + "/plugin/DisplayLayerProgress/value", headers=headers)
r = requests.get("http://localhost:5000/plugin/DisplayLayerProgress/values", headers=headers,timeout=3)
r = requests.get("http://localhost:"+ str(self.tcmd.port) +"/plugin/DisplayLayerProgress/values", headers=headers,timeout=3)
self._logger.debug("get_current_layers : r=" +str(r) )
if (r.status_code >= 300):
return None
Expand Down
2 changes: 2 additions & 0 deletions octoprint_telegram/telegramCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging, sarge, hashlib, datetime, time, operator, socket
import octoprint.filemanager
import requests
import base64
from flask_babel import gettext
from subprocess import Popen, PIPE
from .telegramNotifications import telegramMsgDict
Expand Down Expand Up @@ -1412,6 +1413,7 @@ def fileDetails(self,pathHash,page,cmd,fileHash,chat_id,from_id,wait=0):
msg += "\n<b>"+self.main.emojis['money bag']+"Cost:</b> -"
else:
msg += "\n<b>"+self.main.emojis['money bag']+"Cost:</b> -"

keyPrint = [self.main.emojis['rocket']+" Print","/print_"+fileHash]
keyDetails = [self.main.emojis['left-pointing magnifying glass']+" Details",cmd+"_"+pathHash+"|"+str(page)+"|"+fileHash+"|inf"]
keyDownload = [self.main.emojis['save']+" Download",cmd+"_"+pathHash+"|"+str(page)+"|"+fileHash+"|dl"]
Expand Down
2 changes: 1 addition & 1 deletion octoprint_telegram/telegramNotifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _sendNotification(self, payload, **kwargs):
if event == "PrintStarted":
#get additionnal metadata and thumbnail
self._logger.info("get thumbnail url for path=" + str(path))
meta = self.main._file_manager.get_metadata("local", path)
meta = self.main._file_manager.get_metadata(octoprint.filemanager.FileDestinations.LOCAL, path)
if 'thumbnail' in meta:
kwargs['thumbnail'] = meta['thumbnail']
else:
Expand Down

0 comments on commit 4aa09b6

Please sign in to comment.