I’m looking to get a reference to the SmartApp that called a command on my device type handler so that I can get it’s “app” object to reference the id (vs. having to ask people to pass that id in each time the command is called).
I went around in circles trying to leverage Java and Groovy solutions, but they are all blocked by the ST flavor of the language.
1 Like
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
2
Curious to know “why” (i.e., as an analyst, I really like to understand the underlying problem / use case; because it might lead to an outside-the-box solution).
My only off-the-cuff guess is to see if there is any information you can get from querying the Event log?
The idea is I have a device type that will take messages from a number of SmartApps. The device type will manage those messages to automatically expire old ones from the same SmartApp. eg. if you opened and closed your front door 5 times, and you left your garage door open (2 different apps), the last message about the front door would be the one that stuck around since it would’ve expired the previous ones.
Not super sure how to answer this one other than under “SOURCE” for the device I see “COMMAND” and “APP_COMMAND”. The live logging also doesn’t help me much in this department either. Maybe there is a method you’re talking about that exposes more data, but I’m not sure how to view it!
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
4
Hmmm… I gotta think about your use case and figure out what ideas / questions I have.
Meanwhile, the Event object does seem to have installedAppId in it, but not sure of the context. i.e., Is this stored in the Device Event as it receives the Command? Maybe…?
Is there a hidden parameter within a command call? I thought it had to be defined in the DTH: command "message", ["string"] and I don’t see a way for me to pass any sort of event to the command itself.
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
6
The Event occurs intrinsically (or doesn’t occur at all).
ie, I believe, but not documented or tested, that every Command call fires an Event in the Device Object. The Notification page seems to indicate this… I’ll try to find an example.
But you could also see what types of events are returned if you immediately query inside the Command method.
Not sure why it’s an array, but oh well! works fine now!
edit: It was bugging me why the code was working, so I went back and re-read it and came up with the correct solution that I edited above. The reason is that that device.events returns a list, even though I only wanted 1, it’s still a list! So moving the index selector to device_events made the code work AND make sense.