How to fire an event in plugin.py?

Posted on
Sun Dec 29, 2019 2:25 pm
ZachBenz offline
Posts: 163
Joined: Feb 08, 2014

How to fire an event in plugin.py?

Apologies for the fairly basic question, but I can't seem to track down an answer in the SDK docs or searching in this forum.

I've defined an event in Events.xml:

Code: Select all
<?xml version="1.0"?>
<Events>
    <Event id="videoDownloadCompleteEvent">
        <Name>Video Download Complete</Name>
    </Event>
</Events>


How do I fire off this event in plugin.py? I assume it is a call along the lines of indigo.event.fire, but can't find the correct syntax.

Thanks in advance!

ZachBenz's Plugins: RingForIndigo

Posted on
Sun Dec 29, 2019 3:14 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: How to fire an event in plugin.py?

Code: Select all
                        indigo.trigger.execute(trigger)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Dec 29, 2019 3:17 pm
ZachBenz offline
Posts: 163
Joined: Feb 08, 2014

Re: How to fire an event in plugin.py?

FlyingDiver wrote:
Code: Select all
                        indigo.trigger.execute(trigger)


Thanks! So I take it I need to create a trigger - is there handy sample code for what that looks like?

ZachBenz's Plugins: RingForIndigo

Posted on
Sun Dec 29, 2019 3:28 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: How to fire an event in plugin.py?

The user creates/defines the Trigger instances in Indigo (which exposes your "Video Download Complete" trigger type in the UI). Normal flow then is to define both of these to track when Triggers are active/enabled in Indigo's UI:

Code: Select all
   def triggerStartProcessing(self, trigger):
      if trigger.pluginTypeId == "videoDownloadCompleteEvent":
         self.activeDownloadCompleteTriggers[trigger.id] = trigger

   def triggerStopProcessing(self, trigger):
      if trigger.pluginTypeId == "videoDownloadCompleteEvent":
         del self.activeDownloadCompleteTriggers[trigger.id]

Then internally when a download is complete you can traverse your self.activeDownloadCompleteTriggers dict and call indigo.trigger.execute() on each value (trigger). So basically, you manage which triggers you are interested in manually and then execute them whenever those trigger conditions are internally met in the plugin (download complete in this case). You can store all of your plugin triggers in a single list/dict and figure out which ones "match" the given event, or have specific list/dicts for each trigger type (model I illustrated above).

Image

Posted on
Sun Dec 29, 2019 3:54 pm
ZachBenz offline
Posts: 163
Joined: Feb 08, 2014

Re: How to fire an event in plugin.py?

matt (support) wrote:
The user creates/defines the Trigger instances in Indigo (which exposes your "Video Download Complete" trigger type in the UI). Normal flow then is to define both of these to track when Triggers are active/enabled in Indigo's UI:


Thanks, Matt - I had it backwards in my mind (that I would be publishing an event, vs. handling events in terms of subscribed triggers)

ZachBenz's Plugins: RingForIndigo

Posted on
Sun Dec 29, 2019 3:56 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: How to fire an event in plugin.py?

ZachBenz wrote:
Thanks, Matt - I had it backwards in my mind (that I would be publishing an event, vs. handling events in terms of subscribed triggers)


Yeah, that is a little confusing. Only the plugin code knows if the event criteria were met in order to "fire" (execute) the trigger. So the plugin has to manage maintaining a list of active triggers, and check the list every time something happens that COULD fire a trigger.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Dec 29, 2019 4:48 pm
ZachBenz offline
Posts: 163
Joined: Feb 08, 2014

Re: How to fire an event in plugin.py?

matt (support) wrote:
Then internally when a download is complete you can traverse your self.activeDownloadCompleteTriggers dict and call indigo.trigger.execute() on each value (trigger).


And I just discovered the Triggers documentation in the Object Model Reference (now that I'm not searching on "Event" :D)

ZachBenz's Plugins: RingForIndigo

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests