This is probably a stupid programming error

Posted on
Wed Aug 07, 2019 3:57 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

This is probably a stupid programming error

But I can't see it.

Python script code:
Code: Select all
mqttPlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.mqtt")
if mqttPlugin.isEnabled():
    props = {
        'message_type':"#Test#"
    }
    data = mqttPlugin.executeAction("fetchQueuedMessage", deviceId=1867973662, props=props, waitUntilDone=True)

Log output:
Code: Select all
Aug 7, 2019 at 5:56:28 PM
   Script Error                    embedded script: plugin does not have a <CallbackMethod> specified for action id fetchQueuedMessage
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 6, at top level
InvalidParameter: plugin does not have a <CallbackMethod> specified for action id fetchQueuedMessage

Actions.xml:
Code: Select all
    <Action id="fetchQueuedMessage">
        <CallbackMethod>fetchQueuedMessageAction</CallbackMethod>
        <ConfigUI>
            <Field id="fetch_messageType" type="textfield">
            </Field>
        </ConfigUI>
    </Action>

plugin.py:
Code: Select all
    def fetchQueuedMessageAction(self, action, dev, callerWaitingForResult):
        messageType = action.props["message_type"]
        queue = self.queueDict.get(messageType, None)
        if not queue or queue.empty():
            return None
        self.logger.debug(u"{}: queueMessageForDispatchAction, queue = {} ({})".format(device.name, messageType, queue.qsize()))
        return queue.get()   


Where did I mess up?

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

Posted on
Wed Aug 07, 2019 4:14 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: This is probably a stupid programming error

Well isn't that interesting. If I change Actions.xml to:
Code: Select all
    <Action id="fetchQueuedMessage">
        <Name>Fetch Queued Message</Name>
        <CallbackMethod>fetchQueuedMessageAction</CallbackMethod>
        <ConfigUI>
            <Field id="fetch_messageType" type="textfield">
                <Label>Message Type:</Label>
            </Field>
        </ConfigUI>
    </Action>

Then it works. Or at least I don't get the same error.

I originally didn't have <Name> and <Label> because I was trying to hide this from the Actions list, as I was intending it to be used from scripts only.

Now I get this error:
Code: Select all
   Script Error                    embedded script: NameError -- global name 'device' is not defined
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 6, at top level
StandardError: NameError -- global name 'device' is not defined

Which is interesting because I don't have that name in the script at all. But I think I know where it's coming from. I'll work on that.

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

Posted on
Wed Aug 07, 2019 4:22 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: This is probably a stupid programming error

Ah. It's actually repeating the error from the other end of the connection. But it was reporting it as coming from the script, not the plugin. When I set wait to False, then it was reported correctly.

All fixed now.

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

Posted on
Wed Aug 07, 2019 4:22 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: This is probably a stupid programming error

Sometimes you just need to talk to yourself to figure things out.

:P :P :P :P

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

Posted on
Wed Aug 07, 2019 4:25 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: This is probably a stupid programming error

I know the feeling, and it (talking to oneself) isn't a bad technique at all. :lol:

Image

Posted on
Wed Aug 07, 2019 4:29 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: This is probably a stupid programming error

Glad you sorted it cos I’m lost!

However, what’s the purpose of having an Action listed in Actions.xml at all, if you’re not intending it being shown in the UI?

Isn’t that just what normal folk would call a “function” in your script...?


Sent from my iPad using Tapatalk Pro

Posted on
Wed Aug 07, 2019 4:34 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: This is probably a stupid programming error

howartp wrote:
Glad you sorted it cos I’m lost!

However, what’s the purpose of having an Action listed in Actions.xml at all, if you’re not intending it being shown in the UI?

Isn’t that just what normal folk would call a “function” in your script...?


Needed it to be in Actions.xml so it would be callable from another plugin or a script.

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

Posted on
Wed Aug 07, 2019 5:28 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: This is probably a stupid programming error

FlyingDiver wrote:
Sometimes you just need to talk to yourself to figure things out.

:P :P :P :P

I often find that just posting about it is all I need to spot the problem. :D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Aug 07, 2019 5:34 pm
jay (support) offline
Site Admin
User avatar
Posts: 18221
Joined: Mar 19, 2008
Location: Austin, Texas

Re: This is probably a stupid programming error

FlyingDiver wrote:
I originally didn't have <Name> and <Label> because I was trying to hide this from the Actions list, as I was intending it to be used from scripts only.


Code: Select all
<Action id="fetchQueuedMessage" uiPath="hidden">


That'll do it. Yeah, yeah, yet another developer doc update fail... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Aug 07, 2019 6:23 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: This is probably a stupid programming error

jay (support) wrote:
Code: Select all
<Action id="fetchQueuedMessage" uiPath="hidden">


That'll do it. Yeah, yeah, yet another developer doc update fail... ;)


I thought it would be this, which didn't work:
Code: Select all
<Action id="fetchQueuedMessage" hidden="true">

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

Posted on
Wed Aug 07, 2019 6:29 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: This is probably a stupid programming error

OK, that worked.

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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests