New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Custom Event Support #2965

Open
tjjfvi opened this Issue Dec 22, 2018 · 5 comments

Comments

3 participants
@tjjfvi
Copy link

tjjfvi commented Dec 22, 2018

Is your feature request related to a problem? Please describe.
It is not related to a problem.

Describe the solution you'd like
If OctoPrint could support custom events, triggered by plugins, that would be great. If it already (documented or not) supports this, that's even better; I don't need to wait :)

Describe alternatives you've considered
I have not thought of any alternatives.

Additional context
I recently created a plugin for OctoPrint that notififies via IFTTT when the printer sends N or more busy signals. Obviously, that is a very specialized plugin; it would most likely be much more useful to have two plugins: one that adds a EchoBusy event and one that sends some or all events to IFTTT.

I have looked into the source/docs some and found that a plugin could run self._event_bus.fire("MyHappyCustomEvent", dict(payload_key=payload_val)) and it would (seemingly) work and not destroy OctoPrint, but I haven't thoroughly tested it.

@tjjfvi

This comment has been minimized.

Copy link

tjjfvi commented Dec 27, 2018

My example with self._event_bus doesn't work on the client-side (i.e. the client will not call a viewmodel's self.onEventMyHappyCustomEvent, but will for self.onEventPrintStarted). I don't know if there is a workaround other than manually self._plugin_manager.send_plugin_message(...)ing.

@foosel foosel added this to the 1.3.11 milestone Jan 10, 2019

@foosel

This comment has been minimized.

Copy link
Owner

foosel commented Jan 10, 2019

In theory it should work to set the new event on octoprint.events.Events, that will make it register in the client too, but I agree, a more straightforward hook or something to accomplish that is really needed.

@tjjfvi

This comment has been minimized.

Copy link

tjjfvi commented Jan 10, 2019

Ah, I hadn't seen that; maybe just throwing a paragraph about using that and the self._event_bus.fire to make custom events is enough?

@foosel

This comment has been minimized.

Copy link
Owner

foosel commented Jan 15, 2019

maybe just throwing a paragraph about using that and the self._event_bus.fire to make custom events is enough?

In theory, but monkey patching is a bit hackish. By providing a defined hook namespace collisions could also be avoided (imagine two plugins deciding they want to define an event SOMETHING_HAPPENED...).

foosel added a commit that referenced this issue Jan 15, 2019

@foosel

This comment has been minimized.

Copy link
Owner

foosel commented Jan 15, 2019

The above commit adds a new hook octoprint.events.register_custom_events that allows to register custom events by plugins. Documentation will soon be available here, once the doc build is through.

Commit is pushed to maintenance, soon devel and will be released with 1.3.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment