Plugin startup order question

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

Posted on
Wed Nov 30, 2011 12:43 am
jcrides offline
Posts: 26
Joined: Oct 23, 2010
Location: Concord, CA

Plugin startup order question

I working on a plugin for the ELK M1G alarm panel. It's still a few weeks away from being functional although I'm getting closer. This being the first time I've really written anything this complex. Most of my previous programming has been administrative scripting type stuff. Because of that I've actually completely scrapped and rewritten the thing at least 3 times :oops: .

Each time I start anew on the plugin I completely remove the previous version. Deleting the plugin bundle and preferences file. In the latest version I'm doing some things in startup that are necessary for my plugin to work. I'm relying on the plugin config UI to have been run, settings configured and saved. It looks the first time the plugin is run (with no previous prefs file) the startup method is getting run before the config UI diaglog is closed.

Long preamble to a couple questions.
1. Is it possible to have a plugin not run it's startup method until after the plugin config dialog has been closed?

2. If not, have others run into this issue and how have they gotten around it?

I've been thinking of just adding an errorlog to say you have to reload the plugin after you first save the settings. That's a pretty clunky way to do it though. I supposed I could check that things are set up properly in the plugin config validation method. I just wonder if calling startup again from that function would cause anything weird to happen. Like maybe two instances of runConcurrentThread or something like that.

~JC

Posted on
Wed Nov 30, 2011 1:26 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Plugin startup order question

I ran into a similar problem. In my case, I put a small loop in runConcurrentThreads that waits for a device to exist before continuing. Here is the core of the code I used.
Code: Select all
while len(self.deviceList) == 0:
   prId = "com.berkinet.ProliphixControl"
   proliphixPlugin = indigo.server.getPlugin("com.berkinet.ProliphixControl")
   for tstat in indigo.devices.iter(prId):
      if proliphixPlugin.isEnabled():
         self.deviceList += [tstat.id]
       self.sleep(2)


I guess you could also look to see if the config file had been created if you didn't need any devices. The EasyDAQ plugin seems to do something similar, shortcutting a loop until a list of device IDs is > 0 length.

BTW, I am sure there are other, and probably better ways to do this than what I did and I'd like to hear what others are doing.

Posted on
Wed Nov 30, 2011 10:32 am
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Plugin startup order question

jcrides wrote:
1. Is it possible to have a plugin not run it's startup method until after the plugin config dialog has been closed?


Nope - startup will always be called regardless of the plugin's config state.

jcrides wrote:
2. If not, have others run into this issue and how have they gotten around it?

I've been thinking of just adding an errorlog to say you have to reload the plugin after you first save the settings. That's a pretty clunky way to do it though. I supposed I could check that things are set up properly in the plugin config validation method. I just wonder if calling startup again from that function would cause anything weird to happen. Like maybe two instances of runConcurrentThread or something like that.


I think you're on the right track - except you wouldn't call startup again. Rather, when startup is called, check your plugin preferences to see if the required elements are present. If they are, then call some other method (pluginIsConfigured() maybe) that does whatever startup processing you need.

If not (and if it's not possible to insert usable default values) then set a boolean property (like self.configured or something) to false. Then use that boolean at the appropriate places to skip normal processing (startDeviceComm, runConcurrentThread, etc.). This isn't much different than just testing a specific config value to see if it's present, but if you have a bunch of different fields that have to be configured for the plugin to function correctly then this may save some coding.

Then, when closedPrefsConfigUi(self, valuesDict, userCancelled) is called with userCancelled == False, you can set self.configured to True and call your pluginIsConfigured() method.

There are in fact a bunch of different ways to handle this case (and I can already think of refinements to the approach above) but the bottom line is that you can't be guaranteed that the plugin's config dialog has ever been successfully filled out (the user can cancel the dialog when it's thrown up the first time the plugin is enabled). So you either figure out how to insert good default values or if that's not possible then skip normal processing until the plugin is configured correctly.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Nov 30, 2011 1:06 pm
jcrides offline
Posts: 26
Joined: Oct 23, 2010
Location: Concord, CA

Re: Plugin startup order question

Thanks for the quick replies as always :) . Some sort of boolean state property is the direction I was leaning. The idea of moving most everything out of startup and into another method is something I hadn't considered. It does make a lot of sense though.

Posted on
Mon Dec 26, 2011 9:17 am
bobo offline
Posts: 5
Joined: Apr 19, 2006

Re: Plugin startup order question

Hi there,

I just got an M1G that I'm looking to integrate with indigo, I'm a developer and am pretty strong with python. Let me know if you need any help with that as I'm pretty interested in getting something up and running for my home office. I was planning to use the serial 2414s interface to talk to my elk system, is that what your plugin will support?

Posted on
Thu Dec 29, 2011 2:34 pm
jcrides offline
Posts: 26
Joined: Oct 23, 2010
Location: Concord, CA

Re: Plugin startup order question

I'm using the M1XEP interface on my system. So I have it setup to use a network connection right now. What I've got now is functional for the way I use the system. It's still not got much error checking/handling.

The logic of processing sending/receiving messages from the M1 should be pretty much the same for serial or network. I'll put a copy of what I've got and put a link here later this evening. If you want to work on this then maybe we could set it up on github or something like that so we can both work from a consistent set of source files.

Edit to add link:

Just drop in your Plugins (Disabled) directory and restart Indigo.

http://www.jeremycarey.net/elkplug/Elk% ... digoPlugin

Posted on
Sat Dec 31, 2011 12:28 am
bobo offline
Posts: 5
Joined: Apr 19, 2006

Re: Plugin startup order question

Awesome! So I just installed my M1G today and after confirming that it worked I went ahead and ordered the M1XEP ethernet module for it from smarthome so we'll be on the same page. So I'll be able to start messing around with this in a week or two when it arrives.

I for one can't wait to rig my alarm system so that indigo throws all the lights on and starts blasting Klaus Nomi's "Simple Man" at the would be burglers. That would make me leave!

Also, my wife also got me a usb controlled nerf dart turret for christmas that would be fun to integrate into the mix!

Posted on
Sat Mar 17, 2012 12:20 pm
majortom offline
Posts: 69
Joined: Mar 01, 2006

Re: Plugin startup order question

jcrides wrote:
I'm using the M1XEP interface on my system. So I have it setup to use a network connection right now. What I've got now is functional for the way I use the system. It's still not got much error checking/handling.


Would you say your Plug-in is ready for general use at this point? I am about to get an M1G and I would really like to be able to integrate it with Indigo. What functionality does/will your interface provide?

Posted on
Sun Apr 22, 2012 12:52 pm
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: Plugin startup order question

The plugin does not load on my system - Indigo says it is an invalid plugin and I also cannot browse the package. Download size is around 45k.

Posted on
Sun Apr 22, 2012 1:19 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Plugin startup order question

Please copy/paste the Event Log window contents showing exactly what is logged when you try to enable the plugin.

Image

Posted on
Sun Apr 22, 2012 3:54 pm
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: Plugin startup order question

Error plugin "Elk Plugin.indigoPlugin" is missing file: /Library/Application Support/Perceptive Automation/Indigo 5/Plugins (Disabled)/Elk Plugin.indigoPlugin/Contents/Info.plist

Posted on
Mon Apr 23, 2012 9:20 am
Swancoat offline
Posts: 503
Joined: Nov 20, 2009
Location: Houston

Re: Plugin startup order question

Just stumbled across this...

I've been dying for an Elk plugin. I'm trying to do my own plugin for my NuVo Grand Concerto, and it's already beyond my abilities (i.e. I'm totally NOT a programmer or developer), so I knew this ELK one was going to be well beyond what I can do myself.

Does it recognize arms/disarms from varying codes (i.e. when *I* disarm vs. when my wife uses HER code)?

Do I get access to all of my sensors for use in Indigo?

(I'm so excited to get home and try this thing!!)

http://nerdhome.jimdo.com

Posted on
Mon Apr 23, 2012 7:57 pm
Swancoat offline
Posts: 503
Joined: Nov 20, 2009
Location: Houston

Re: Plugin startup order question

I can't seem to get it to load either. It's in the plugin directory, but just won't show up in the plugins menu.

http://nerdhome.jimdo.com

Posted on
Mon Apr 23, 2012 8:26 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Plugin startup order question

It appears to be corrupt or not download correctly because it isn't in a .zip. I just emailed jcrides and asked him to try zipping it and reposting it.

Image

Posted on
Tue Apr 24, 2012 12:11 am
jcrides offline
Posts: 26
Joined: Oct 23, 2010
Location: Concord, CA

Re: Plugin startup order question

Sorry about the download troubles. I thought it was working before. I uploaded it as a .zip as Matt suggested. Try this and let me know if it's still not downloadable.

~JC

http://www.jeremycarey.net/elkplug/Elk%20Plugin.indigoPlugin.zip

Who is online

Users browsing this forum: No registered users and 0 guests