Reload, enable, disable plugin via trigger action / script?

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
BillC
Posts: 238
Joined: Sun Mar 09, 2008 4:51 pm

Reload, enable, disable plugin via trigger action / script?

Post by BillC »

How would one enable/disable/reload a plugin via a trigger action / embedded script? I can't seem to find any applescript or python equivalent to the menu items Plugins---->(specific plugin)---->[enable][disable][reload], nor are those commands available as actions.
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

Re: Reload, enable, disable plugin via trigger action / scri

Post by hamw »

Try Menu scripting.
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Reload, enable, disable plugin via trigger action / scri

Post by matt (support) »

You can, via an embedded Indigo python script, restart a plugin if (and only if) it is already enabled:

Code: Select all

plugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.easydaq-usb-relay-cards")
if plugin.isEnabled():
   plugin.restart()
Image
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Reload, enable, disable plugin via trigger action / scri

Post by berkinet »

support wrote:You can, via an embedded Indigo python script, restart a plugin if (and only if) it is already enabled:

Code: Select all

plugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.easydaq-usb-relay-cards")
if plugin.isEnabled():
   plugin.restart()
So, is there any reason that a plugin could/should not cause it self to reload by invoking the restart method on itself? This would be desirable in a case where a configuration change has been made that requires a plugin restart.
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Reload, enable, disable plugin via trigger action / scri

Post by matt (support) »

Hmmm... good question. I don't think it will be ideal. The restart call is going to block until Indigo Server has finished stopping/starting the plugin, but it won't be able to stop it while it is blocked, which will result in the Indigo Server force killing it. I could probably add an optional doNotBlock parameter to the restart method that would make it cleaner...
Image
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Reload, enable, disable plugin via trigger action / scri

Post by matt (support) »

In the next release (5.0.3, not yet available), try passing in a waitUntilDone argument of False and I think it will work smoothly:

Code: Select all

plugin.restart(waitUntilDone=False)
Image
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Reload, enable, disable plugin via trigger action / scri

Post by berkinet »

Great! That will be a nice help - its always better to have the software do something when it can instead of relying on the user to perform some required task.

Looking forward to 5.0.3
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Reload, enable, disable plugin via trigger action / scri

Post by jay (support) »

Just curious - what configuration change would require the plugin to restart rather than the plugin logic just adjust to the new change?
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Reload, enable, disable plugin via trigger action / scri

Post by berkinet »

In the ad2usb plugin users can change between USB and serial connectivity and between two modes of operation: basic and advanced (with different internal data structures). I currently support closedPrefsConfigUi() and try to do the right thing. It works generally, but still, in both cases, I have reports of error messages thrown. This happens in some installations and not others.

Given a rich test lab (OS version, ad2usb board/firmware version, and panel model), I could probably engineer around all possibilities. But, a restart is clean and avoids the chance of error.
terrydew
Posts: 258
Joined: Fri Jun 10, 2011 9:30 am

Re: Reload, enable, disable plugin via trigger action / scri

Post by terrydew »

I copied you code into an action group and it worked restarting the easydaq plugin. However when I replaced easydaq with another plugin nothing happened? Does a plugin have to allow this or some other feature to work. It is enabled and I checked the syntax and have tried on a couple of plugins.

I must be doing something wrong when I replace the plugin name (am getting from plugin file name). I have never used an embedded Indigo python script before so maybe I am missing a step? If I change the plugin name do I have to compile or something else.

I have a feeling I am going to feel very dumb when I find the problem but for now I am stumped
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Reload, enable, disable plugin via trigger action / scri

Post by jay (support) »

You have to get the right plugin object first - to get the plugin instance you have to use the plugin's complete ID. It should be specified in the plugin's documentation, but it can be found inside the Info.plist inside the plugin bundle.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
terrydew
Posts: 258
Joined: Fri Jun 10, 2011 9:30 am

Re: Reload, enable, disable plugin via trigger action / scri

Post by terrydew »

Thanks Jay

That did it (after I figured out you had to replace from the " and not just the name :D )

Indigo really is a super app!!!

Terry
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Reload, enable, disable plugin via trigger action / scri

Post by berkinet »

I guess self.restart(waitUntilDone=False) didn't make it into 5.0.3 :cry:

Jan 31, 2012 19:25:07
Starting Indigo Server version 5.0.3
... ...
<type 'exceptions.TypeError'>: restart() got an unexpected keyword argument 'waitUntilDone'
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Reload, enable, disable plugin via trigger action / scri

Post by matt (support) »

Instead of calling restart() on self, try getting the plugin via:

Code: Select all

plugin = indigo.server.getPlugin("some.plugin.id.here")
And then plugin.restart() should take the new argument.
Image
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Reload, enable, disable plugin via trigger action / scri

Post by berkinet »

support wrote:... try
plugin = indigo.server.getPlugin("some.plugin.id.here")
And then plugin.restart() should take the new argument.
Yup. That worked. Thanks!!
Locked

Return to “Extending Indigo with Plugins and Python”