Page 1 of 1

Trouble with starting an event from inside a script

Posted: Fri Aug 17, 2012 1:39 am
by mukow
Hi,

I am having some trouble and wondering if anyone was able to help me find a way around what I am looking to do.

I currently have a script that is actioned when a network based xPL message is received.
The script will figure out the details of the message and perform an action based on that.

In the below script eg.TriggerEvent(GetTvStatus) triggers an event which updates eg.globals.tvStatus with the latest information.
What I have found is that the GetTVStatus event is triggered after this script has completed and therefore the eg.globals.tvStatus is not the latest information.
I am aware that this is caused by the way EG uses queues but was wondering if anyone is aware of a way I can accomplish the desired effect.

Code: Select all

import re

# split up the event components
xPLSplit = eg.event.suffix.split(':')

# make the pieces easy to remember
xPLType = xPLSplit[0]
xPLSchema = xPLSplit[1]
xPLSource = xPLSplit[2]
xPLTarget = xPLSplit[3]
xPLBody = xPLSplit[4]

# we only want xpl-trig messages
if xPLType == "xpl-trig":
    # only want messages from blabber
    if re.search('doghouse-blabber',xPLSource):
        bodySplit = xPLBody.split(',')
        # extract the components of the message body
        for i in range(3):
            if re.search('device',bodySplit[i]):
                senderSplit = bodySplit[i].split('=')
            elif re.search('type',bodySplit[i]):
                typeSplit = bodySplit[i].split('=')
            elif re.search('current',bodySplit[i]):
                currentSplit = bodySplit[i].split('=')
        # we only want the message type and messages that
        # contain the word 'test'
        if typeSplit[1] == "message" and currentSplit[1]=="tv":
            # if we get 'test' we'll reply back to the sender
            # that we got his message
            
           eg.TriggerEvent(GetTvStatus)
           tvStat = eg.globals.tvStatus

            returnMsg = "device="+senderSplit[1]+"\n"+"current="+tvStat
            eg.plugins.xPL.sendxPL(u'xpl-cmnd', u'control.basic', xPLSource, \
            returnMsg)