Open shadow578 opened 1 year ago
Ok, so i did some digging and it seems like OctoPrint does not raise a ERROR
event when the serial connection fails (at all).
Since the plugin only checks for the ERROR
event, it cannot do anything when the serial connection does fail.
However, OctoPrint does raise a DISCONNECTED
event.
when handling this event*, the printer does turn of as expected:
def on_event(self, event, payload):
if event == Events.CLIENT_OPENED:
self._plugin_manager.send_plugin_message(self._identifier, dict(isPSUOn=self.isPSUOn))
return
elif event == Events.ERROR and self.config['turnOffWhenError']:
self._logger.info("Firmware or communication error detected. Turning PSU Off")
self.turn_psu_off()
return
elif event == Events.DISCONNECTED and self.isPSUOn: # <- added branch
self._logger.info("Printer disconnect detected. Turning PSU Off")
self.turn_psu_off()
return
* event handling was botched directly into the installed plugin, in init.py. Will break on next update, but good enough for testing i guess.
is this expected behaviour (by the plugin and OctoPrint)? if yes, this should be clearly mentioned in the docs.
additionally, would it make sense to add an config option like 'Turn off on printer disconnect' that turns off the psu on DISCONNECTED
event?
additionally, i saw that OctoPrint has the following events too (see https://docs.octoprint.org/en/master/events/index.html#printer-communication):
PRINT_FAILED
: seems to be raised on a print failure (idk what qualifies as such tho)SHUTDOWN
: seems to be raised when octoprint shuts downMaybe adding (configurable) options to turn off the psu on those events could be helpful too?
What were you doing?
Turn off when an unrecoverable firmware or communication error occurs
optionWhat did you expect to happen?
I'd expect the psu to shut down when a communication error occurs.
What happened instead?
Printer is disconnected (with error), but psu stays on.
Version of OctoPrint-PSUControl
1.0.6
Operating System running OctoPrint
OctoPrint 1.8.6, Python 3.9.2, Linux
Printer model & used firmware incl. version
Link to octoprint.log with octoprnt.plugins.psucontrol set to DEBUG
https://gist.github.com/shadow578/b7cb8de193a29c4435b81cf0c9be9529