Skip to content

Commit

Permalink
0.8.17 (#113)
Browse files Browse the repository at this point in the history
- fix issue introduced in 0.8.16 that broke functionality in OctoPod
- add upload event monitoring that will auto power on enabled devices when sending files from PrusaSlicer/SuperSlicer
  • Loading branch information
jneilliii authored Dec 27, 2020
1 parent c86efa5 commit 3311738
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 132 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ This plugin is to control ITead Sonoff devices that have been flashed with [Sono

**Single relay devices need to use 1 for index.**

[Changelog](changelog.md)

## Screenshots
![screenshot](screenshot.png)

Expand Down Expand Up @@ -63,6 +61,13 @@ Once installed go into settings and enter the ip address for your TP-Link Smartp
![Pi Safe Shutdown](tasmota_editor_safe_shutdown.png)
With these options the raspberry pi will be shutdown 5 seconds after the idle timeout is reached (as configured on the main settings page) and send a backlog command to your Tasmota device to power off after a 60 second delay.

## Most recent changelog
**[0.8.17](https://github.com/jneilliii/OctoPrint-Tasmota/releases/tag/0.8.17)** (12/26/2020)
- fix issue introduced in 0.8.16 that broke functionality in OctoPod
- add upload event monitoring that will auto power on enabled devices when sending files from PrusaSlicer/SuperSlicer

### [All releases](https://github.com/jneilliii/OctoPrint-Tasmota/releases)

## Get Help

If you experience issues with this plugin or need assistance please use the issue tracker by clicking issues above.
Expand Down
111 changes: 0 additions & 111 deletions changelog.md

This file was deleted.

61 changes: 50 additions & 11 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 Expand Up @@ -356,6 +390,7 @@ def turn_on(self, plugip, plugidx):
"Resetting idle timer since plug %s:%s was just turned on." % (plugip, plugidx))
self._waitForHeaters = False
self._reset_idle_timer()
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on",ip=plugip,idx=plugidx))

def turn_off(self, plugip, plugidx):
plug = self.plug_search(self._settings.get(["arrSmartplugs"]), "ip", plugip, "idx", plugidx)
Expand All @@ -372,25 +407,25 @@ def turn_off(self, plugip, plugidx):
webresponse = requests.get(backlog_url)
response = dict()
response["POWER%s" % plug["idx"]] = "OFF"

if plug["sysCmdOff"]:
self._tasmota_logger.debug(
"Running system command: %s in %s" % (plug["sysRunCmdOff"], plug["sysCmdOffDelay"]))
t = threading.Timer(int(plug["sysCmdOffDelay"]), os.system, args=[plug["sysRunCmdOff"]])
t.daemon = True
t.start()

if plug["autoDisconnect"] and self._printer.is_operational():
self._tasmota_logger.debug("Disconnnecting from printer")
self._printer.disconnect()
time.sleep(int(plug["autoDisconnectDelay"]))

if not plug["use_backlog"]:
self._tasmota_logger.debug("Not using backlog commands")
webresponse = requests.get(
"http://" + plug["ip"] + "/cm?user=" + plug["username"] + "&password=" + requests.utils.quote(
plug["password"]) + "&cmnd=Power" + str(plug["idx"]) + "%20off")
response = webresponse.json()
chk = response["POWER%s" % plug["idx"]]
if chk.upper() == "OFF":
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="off",ip=plugip,idx=plugidx))
except:
self._tasmota_logger.error('Invalid ip or unknown error connecting to %s.' % plug["ip"], exc_info=True)
response = "Unknown error turning off %s index %s." % (plugip, plugidx)
Expand Down Expand Up @@ -454,12 +489,15 @@ def check_status(self, plugip, plugidx):

self._tasmota_logger.debug("%s index %s is %s" % (plugip, plugidx, chk))
if chk.upper() == "ON":
return {"currentState": "on", "ip": plugip, "idx": plugidx, "energy_data": energy_data, "sensor_data": sensor_data}
response = {"currentState": "on", "ip": plugip, "idx": plugidx, "energy_data": energy_data, "sensor_data": sensor_data}
elif chk.upper() == "OFF":
return {"currentState": "off", "ip": plugip, "idx": plugidx, "energy_data": energy_data, "sensor_data": sensor_data}
response = {"currentState": "off", "ip": plugip, "idx": plugidx, "energy_data": energy_data, "sensor_data": sensor_data}
else:
self._tasmota_logger.debug(response)
return {"currentState": "unknown", "ip": plugip, "idx": plugidx, "energy_data": energy_data, "sensor_data": sensor_data}
response = {"currentState": "unknown", "ip": plugip, "idx": plugidx, "energy_data": energy_data, "sensor_data": sensor_data}

self._plugin_manager.send_plugin_message(self._identifier, response)
return response

def checkSetOption26(self, plugip, username, password):
webresponse = requests.get("http://" + plugip + "/cm?user=" + username + "&password=" + requests.utils.quote(
Expand Down Expand Up @@ -493,10 +531,11 @@ def on_api_command(self, command, data):

if command == 'turnOn':
self.turn_on("{ip}".format(**data), "{idx}".format(**data))
return flask.jsonify(self.check_status("{ip}".format(**data), "{idx}".format(**data)))
# return flask.jsonify(self.check_status("{ip}".format(**data), "{idx}".format(**data)))
elif command == 'turnOff':
self.turn_off("{ip}".format(**data), "{idx}".format(**data))
return flask.jsonify(self.check_status("{ip}".format(**data), "{idx}".format(**data)))
# return flask.jsonify(self.check_status("{ip}".format(**data), "{idx}".format(**data)))

elif command == 'checkStatus':
return flask.jsonify(self.check_status("{ip}".format(**data), "{idx}".format(**data)))
elif command == 'checkSetOption26':
Expand Down Expand Up @@ -819,7 +858,7 @@ def get_update_information(self):
# for details.
return dict(
tasmota=dict(
displayName="OctoPrint-Tasmota",
displayName="Tasmota",
displayVersion=self._plugin_version,

# version check: github repository
Expand Down
10 changes: 4 additions & 6 deletions 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 All @@ -273,7 +274,7 @@ $(function() {
}

self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin != "tasmota") {
if (plugin != "tasmota" || !data) {
return;
}

Expand Down Expand Up @@ -465,10 +466,7 @@ $(function() {
idx: data.idx()
}),
contentType: "application/json; charset=UTF-8"
}).done(function(data){
console.log('checkStatus', data);
self.onDataUpdaterPluginMessage('tasmota', data);
});
});
};

self.checkStatuses = function() {
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.16"
plugin_version = "0.8.17"

# 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 3311738

Please sign in to comment.