Skip to content

Commit

Permalink
add upload event monitoring, #112
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed Dec 26, 2020
1 parent 14ff5ee commit 8b87c96
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
38 changes: 36 additions & 2 deletions octoprint_tasmota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self):
self._skipIdleTimer = False
self.powerOffWhenIdle = False
self._idleTimer = None
self._autostart_file = None

##~~ StartupPlugin mixin

Expand Down Expand Up @@ -164,7 +165,8 @@ def get_settings_defaults(self):
powerOffWhenIdle=False,
idleTimeout=30,
idleIgnoreCommands='M105',
idleTimeoutWaitTemp=50
idleTimeoutWaitTemp=50,
event_on_upload_monitoring=False
)

def on_settings_save(self, data):
Expand Down Expand Up @@ -217,7 +219,7 @@ def on_settings_save(self, data):
self.poll_status.start()

def get_settings_version(self):
return 8
return 9

def on_settings_migrate(self, target, current=None):
if current is None or current < 6:
Expand All @@ -239,6 +241,13 @@ def on_settings_migrate(self, target, current=None):
plug["event_on_disconnect"] = False
arrSmartplugs_new.append(plug)
self._settings.set(["arrSmartplugs"], arrSmartplugs_new)
if current < 9:
# Add new fields
arrSmartplugs_new = []
for plug in self._settings.get(['arrSmartplugs']):
plug["event_on_upload"] = False
arrSmartplugs_new.append(plug)
self._settings.set(["arrSmartplugs"], arrSmartplugs_new)

##~~ AssetPlugin mixin

Expand Down Expand Up @@ -294,6 +303,31 @@ def on_event(self, event, payload):
dict(powerOffWhenIdle=self.powerOffWhenIdle, type="timeout",
timeout_value=self._timeout_value))
return
# Printer Connected Event
if event == Events.CONNECTED:
if self._autostart_file:
self._tasmota_logger.debug("printer connected starting print of %s" % self._autostart_file)
self._printer.select_file(self._autostart_file, False, printAfterSelect=True)
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", ""))
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():
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")

# Print Started Event
if event == Events.PRINT_STARTED and self.powerOffWhenIdle == True:
if self._abort_timer is not None:
Expand Down
3 changes: 2 additions & 1 deletion octoprint_tasmota/static/js/tasmota.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ $(function() {
'thermal_runaway':ko.observable(false),
'automaticShutdownEnabled':ko.observable(false),
'event_on_error':ko.observable(false),
'event_on_disconnect':ko.observable(false)});
'event_on_disconnect':ko.observable(false),
'event_on_upload':ko.observable(false)});
self.settings.settings.plugins.tasmota.arrSmartplugs.push(self.selectedPlug());
$("#TasmotaEditor").modal("show");
}
Expand Down
11 changes: 10 additions & 1 deletion octoprint_tasmota/templates/tasmota_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@
</div>
</div>
</div>
<div class="row-fluid">
<div class="control-group">
<div class="controls">
<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>
</div>
</div>
</div>
<div class="row-fluid">
<div class="control-group">
<div class="controls">
Expand Down Expand Up @@ -191,9 +200,9 @@
<td><div class="controls"><label class="control-label">{{ _('Sensor Identifier') }}</label><input type="text" class="input-block-level" data-bind="value: sensor_identifier" /><div></td>
</tr>
<tr>
<td><div class="controls"><label class="checkbox"><input type="checkbox" data-bind="checked: event_on_upload, enable: $root.settings.settings.plugins.tasmota.event_on_upload_monitoring()" title="Automatically power on when file is uploaded." /> On with Upload</label></div></td>
<td><div class="controls"><label class="checkbox"><input type="checkbox" data-bind="checked: automaticShutdownEnabled, enable: $root.settings.settings.plugins.tasmota.powerOffWhenIdle()" title="Automatically power off when printer is idle." /> Off on Idle</label></div></td>
<td></td>
<td></td>
<td><div class="controls"><label class="checkbox"><input type="checkbox" data-bind="checked: thermal_runaway" title="Power off if temperature exceeds configured max temperatures." /> Thermal Runaway</label></div></td>
<td><div class="controls"><label class="checkbox"><input type="checkbox" title="{{ _('Automatically power off this relay when Error Event Monitoring is enabled.') }}" data-toggle="tooltip" data-bind="checked: event_on_error, enable: $root.settings.settings.plugins.tasmota.event_on_error_monitoring(), tooltip: {}" disabled /> {{ _('Off on Error') }}</label></div></td>
<td><div class="controls"><label class="checkbox"><input type="checkbox" title="{{ _('Automatically power off this relay when Disconnect Event Monitoring is enabled.') }}" data-toggle="tooltip" data-bind="checked: event_on_disconnect, enable: $root.settings.settings.plugins.tasmota.event_on_disconnect_monitoring(), tooltip: {}" disabled /> {{ _('Off on Disconnect') }}</label></div></td>
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 = "OctoPrint-Tasmota"

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

# 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 8b87c96

Please sign in to comment.