Skip to content

Commit

Permalink
add optional upload power on and auto start print, #115
Browse files Browse the repository at this point in the history
adjust auto start/on connect related code, #149
  • Loading branch information
jneilliii committed Sep 4, 2021
1 parent 7315dd2 commit 184346b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Once installed go into settings and enter the ip address for your TP-Link Smartp
- When enabled if printer becomes disconnected relays with the option enabled will be automatically powered off.
- **Upload Event Monitoring**
- When enabled auto power on enabled devices when file is uploaded to OctoPrint with the option to automatically start printing.
- **Include uploads via web interface**
- Enable to auto power on when uploading via the web interface rather than from a Slicer with the option to automatically start.
- **Automtically start print after on**
- Enable to automatically start the print after the Tasmota device is powered on and printer auto connects.
- **Connect Event Monitoring**
- When enabled auto power on enabled devices when the Connect button is pressed in OctoPrint.
- **Enable polling of status.**
Expand Down
23 changes: 15 additions & 8 deletions octoprint_tasmota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def get_settings_defaults(self):
"idleTimeoutWaitTemp": 50,
"idleWaitForTimelapse": True,
"event_on_upload_monitoring": False,
"event_on_upload_monitoring_always": False,
"event_on_upload_monitoring_start_print": False,
"cost_rate": 0,
"request_timeout": 3
}
Expand Down Expand Up @@ -350,23 +352,27 @@ def on_event(self, event, payload):
self._autostart_file = None

# File Uploaded Event
if event == Events.UPLOAD and self._settings.getBoolean(["event_on_upload_monitoring"]):
if payload.get("print", False): # implemented in OctoPrint version 1.4.1
self._tasmota_logger.debug(
"File uploaded: %s. Turning enabled plugs on." % payload.get("name", ""))
if event == Events.UPLOAD and self._settings.get_boolean(["event_on_upload_monitoring"]):
if payload.get("print", False) or self._settings.get_boolean(["event_on_upload_monitoring_always"]): # implemented in OctoPrint version 1.4.1
self._tasmota_logger.debug("File uploaded: %s. Turning enabled plugs on." % payload.get("name", ""))
self._tasmota_logger.debug("Clearing autostart.")
self._autostart_file = None
self._tasmota_logger.debug(payload)
for plug in self._settings.get(['arrSmartplugs']):
self._tasmota_logger.debug(plug)
if plug["event_on_upload"] is True and not self._printer.is_ready():
if plug["event_on_upload"] is True:
self._tasmota_logger.debug("powering on %s due to %s event." % (plug["ip"], event))
self.turn_on(plug["ip"], plug["idx"])
response = self.check_status(plug["ip"], plug["idx"])
if response["currentState"] == "on":
self._tasmota_logger.debug(
"power on successful for %s attempting connection in %s seconds" % (
plug["ip"], plug.get("autoConnectDelay", "0")))
if payload.get("path", False) and payload.get("target") == "local":
self._autostart_file = payload.get("path")
if payload.get("path", False) and payload.get("target") == "local" and (payload.get("print", False) or self._settings.get_boolean(["event_on_upload_monitoring_start_print"])):
if self._printer.is_ready():
self._printer.select_file(payload.get("path"), False, printAfterSelect=True)
else:
self._autostart_file = payload.get("path")

# Print Started Event
if event == Events.PRINT_STARTED and self._settings.getFloat(["cost_rate"]) > 0:
Expand Down Expand Up @@ -895,6 +901,7 @@ def _idle_poweroff(self):
self._timer_start()
else:
self._tasmota_logger.debug("Aborted power off due to activity.")
self._reset_idle_timer()

##~~ Timelapse Monitoring

Expand Down Expand Up @@ -1092,5 +1099,5 @@ def __plugin_load__():
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.process_echo,
"octoprint.comm.protocol.temperatures.received": __plugin_implementation__.monitor_temperatures,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
}
6 changes: 6 additions & 0 deletions octoprint_tasmota/templates/tasmota_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<label class="checkbox">
<input type="checkbox" title="{{ _('When enabled auto power on enabled devices when file is uploaded to OctoPrint with the option to automatically start printing.') }}" data-toggle="tooltip" data-bind="checked: settings.settings.plugins.tasmota.event_on_upload_monitoring, tooltip: {}" /> {{ _('Upload Event Monitoring') }}
</label>
<label class="checkbox" data-bind="visible: settings.settings.plugins.tasmota.event_on_upload_monitoring()" style="margin-left: 20px;">
<input type="checkbox" title="{{ _('Enable to auto power on when uploading via the web interface rather than from a Slicer with the option to automatically start.') }}" data-toggle="tooltip" data-bind="checked: settings.settings.plugins.tasmota.event_on_upload_monitoring_always, tooltip: {}" /> {{ _('Include uploads via web interface') }}
</label>
<label class="checkbox" data-bind="visible: settings.settings.plugins.tasmota.event_on_upload_monitoring_always()" style="margin-left: 20px;">
<input type="checkbox" title="{{ _('Enable to automatically start the print after the Tasmota device is powered on and printer auto connects.') }}" data-toggle="tooltip" data-bind="checked: settings.settings.plugins.tasmota.event_on_upload_monitoring_start_print, tooltip: {}" /> {{ _('Automtically start print after on') }}
</label>
</div>
</div>
</div>
Expand Down

0 comments on commit 184346b

Please sign in to comment.