Skip to content

Commit

Permalink
add PNotify messages to thermal runaway
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed Mar 12, 2021
1 parent 6ae4705 commit a88db1d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
36 changes: 23 additions & 13 deletions octoprint_tasmota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def on_event(self, event, payload):
# Printer Connected Event
if event == Events.CONNECTED:
if self.thermal_runaway_triggered:
self._plugin_manager.send_plugin_message(self._identifier, dict(thermal_runaway=True, type="error", timeout_value=self._timeout_value))
self._tasmota_logger.debug("thermal runaway event triggered prior to last connection." % self._autostart_file)
self._plugin_manager.send_plugin_message(self._identifier, dict(thermal_runaway=True, type="connection"))
self._tasmota_logger.debug("thermal runaway event triggered prior to last connection.")
self.thermal_runaway_triggered = False
if self._autostart_file:
self._tasmota_logger.debug("printer connected starting print of %s" % self._autostart_file)
Expand Down Expand Up @@ -360,6 +360,10 @@ def on_event(self, event, payload):
if event == Events.PRINT_STARTED and self._settings.getFloat(["cost_rate"]) > 0:
self.print_job_started = True
self._tasmota_logger.debug(payload.get("path", None))
if self.thermal_runaway_triggered:
self._plugin_manager.send_plugin_message(self._identifier, dict(thermal_runaway=True, type="connection"))
self._tasmota_logger.debug("thermal runaway event triggered prior to last connection.")
self.thermal_runaway_triggered = False
for plug in self._settings.get(["arrSmartplugs"]):
status = self.check_status(plug["ip"], plug["idx"])
self.print_job_power -= float(self.deep_get(status, ["energy_data", "Total"], default=0))
Expand Down Expand Up @@ -703,17 +707,23 @@ def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwar
##~~ Temperatures received hook

def check_temps(self, parsed_temps):
for k, v in parsed_temps.items():
if k == "B" and v[0] > int(self._settings.get(["thermal_runaway_max_bed"])):
self._tasmota_logger.debug("Max bed temp reached, shutting off plugs.")
self.thermal_runaway_triggered = True
if k.startswith("T") and v[0] > int(self._settings.get(["thermal_runaway_max_extruder"])):
self._tasmota_logger.debug("Extruder max temp reached, shutting off plugs.")
self.thermal_runaway_triggered = True
if self.thermal_runaway_triggered == True:
for plug in self._settings.get(['arrSmartplugs']):
if plug["thermal_runaway"] == True:
self.turn_off(plug["ip"], plug["idx"])
process_items = parsed_temps.items()
try:
for k, v in process_items:
if k == "B" and v[0] > int(self._settings.get(["thermal_runaway_max_bed"])):
self._tasmota_logger.debug("Max bed temp reached, shutting off plugs.")
self._plugin_manager.send_plugin_message(self._identifier, dict(thermal_runaway=True, type="bed"))
self.thermal_runaway_triggered = True
if k.startswith("T") and v[0] > int(self._settings.get(["thermal_runaway_max_extruder"])):
self._tasmota_logger.debug("Extruder max temp reached, shutting off plugs.")
self._plugin_manager.send_plugin_message(self._identifier, dict(thermal_runaway=True, type="extruder"))
self.thermal_runaway_triggered = True
if self.thermal_runaway_triggered == True:
for plug in self._settings.get(['arrSmartplugs']):
if plug["thermal_runaway"] == True:
self.turn_off(plug["ip"], plug["idx"])
except BaseException as e:
self._logger.debug(e)

def monitor_temperatures(self, comm, parsed_temps):
if self._settings.get(["thermal_runaway_monitoring"]) and self.thermal_runaway_triggered == False:
Expand Down
31 changes: 26 additions & 5 deletions octoprint_tasmota/static/js/tasmota.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,32 @@ $(function() {
}

if(data.hasOwnProperty("thermal_runaway")){
self.thermal_runaway_notice = new PNotify({
title: "Tasmota Error",
type: "error",
text: "Thermal Runaway was triggered prior to the last printer connection."
});
let message = "Thermal runaway was triggered "
switch (data.type){
case "connection":
message += "prior to the last printer connection.";
break
case "bed":
message += "from the bed.";
break
case "extruder":
message += "from the extruder.";
break
default:
console.log("unknown thermal_runaway type");
}

if (self.thermal_runaway_notice !== undefined) {
self.thermal_runaway_notice.update({text: message});
self.thermal_runaway_notice.open();
} else {
self.thermal_runaway_notice = new PNotify({
title: "Tasmota Error",
type: "error",
text: message,
hide: false
});
}
return;
}

Expand Down

0 comments on commit a88db1d

Please sign in to comment.