Skip to content

Commit

Permalink
Message for /status when not printing is now also customizable and fi…
Browse files Browse the repository at this point in the history
…lled via TelegramPlugin#on_event.
  • Loading branch information
fabianonline committed Feb 18, 2016
1 parent a5290e9 commit c079e86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
20 changes: 5 additions & 15 deletions octoprint_telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,9 @@ def run(self):
elif command=="/status":
if self.main._printer.is_printing():
status = self.main._printer.get_current_data()
self.main.on_event("TelegramSendStatus", {'z': (status['currentZ'] or 0.0)})
self.main.on_event("TelegramSendPrintingStatus", {'z': (status['currentZ'] or 0.0)})
else:
temps = self.main._printer.get_current_temperatures()
# {'bed': {'actual': 1.0, 'target': 1.0, 'offset': 0}, 'tool0': {'actual': 164.76, 'target': 220.0, 'offset': 0}}
# {'bed': {'actual': 0.0, 'target': 0.0, 'offset': 0}, 'tool0': {'actual': 18.7, 'target': 0.0, 'offset': 0}}
msg = "Not printing."
msg+="\n\nTemperatures:\n"
if not (temps['bed']['actual']==0.0 and temps['bed']['target']==0.0) and not (temps['bed']['actual']==1.0 and temps['bed']['target']==1.0):
msg += "Bed: " + str(temps['bed']['actual']) + "/" + str(temps['bed']['target']) + "\n"
if "tool0" in temps:
msg += "Extruder 1: {0} (Target {1})\n".format(temps['tool0']['actual'], temps['tool0']['target'])
if "tool1" in temps:
msg += "Extruder 2: {0} (Target {1})".format(temps['tool1']['actual'], temps['tool1']['target'])
self.main.send_msg(msg)
self.main.on_event("TelegramSendNotPrintingStatus", {})
elif command=="/help":
msg = "You can use following commands:\n"
msg+= "/photo - Sends a current photo.\n"
Expand Down Expand Up @@ -194,6 +183,7 @@ def get_settings_defaults(self):
PrintFailed = "Printing {file} failed.",
ZChange = "Printing at Z={z}.\nBed {bed_temp}/{bed_target}, Extruder {e1_temp}/{e1_target}.\n{time_done}, {percent}% done, {time_left} remaining.",
PrintDone = "Finished printing {file}.",
TelegramSendNotPrintingStatus = "Not printing.\nBed {bed_temp}/{bed_target}, Extruder {e1_temp}/{e1_target}."
)
)

Expand Down Expand Up @@ -221,7 +211,7 @@ def is_notification_necessary(self, new_z, old_z):

def on_event(self, event, payload, *args, **kwargs):
try:
if event != "PrintDone" and event != "PrintStarted" and event != "ZChange" and event!="PrintFailed" and event!="TelegramSendStatus":
if event != "PrintDone" and event != "PrintStarted" and event != "ZChange" and event!="PrintFailed" and event!="TelegramSendPrintingStatus" and event!="TelegramSendNotPrintingStatus":
# return as fast as possible
return

Expand Down Expand Up @@ -260,7 +250,7 @@ def on_event(self, event, payload, *args, **kwargs):
return
if not self._settings.get_boolean(["message_at_print_failed"]):
return
elif event=="TelegramSendStatus":
elif event=="TelegramSendPrintingStatus":
z = payload['z']
# Change the event type in order to generate a ZChange message
event = "ZChange"
Expand Down
7 changes: 6 additions & 1 deletion octoprint_telegram/templates/telegram_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
<textarea rows="4" class="block" data-bind="value: settings.settings.plugins.telegram.messages.ZChanged"></textarea>
</div>
</div>

<div class="control-group">
<label class="control-label">{{ _('Message for /status when not printing') }}</label>
<div class="controls">
<textarea rows="4" class="block" data-bind="value: settings.settings.plugins.telegram.messages.TelegramSendNotPrintingStatus"></textarea>
</div>
</div>

</form>

0 comments on commit c079e86

Please sign in to comment.