Is there a way to invoke a device command or do a sendHubCommand from device type code?
From my understanding, commands can return a hubAction, which is then invoked in the platform. I have a need to perform the equivalent of a sendHubCommand as the result of the parse() function.
In my specific case, my LAN device type code needs to negotiate a session id with the device. I have no idea when this session id expires. I basically try to perform the command that the user pressed from the device tile, and then, if I get an unauthorized response back, I clear the session id. Then on the next command, I see that the session id is blank, and instead of performing the command, I request a session id. So only the third command will actually do the action, as that is when the session id is available. I am trying to simplify this exchange to get a better user experience.
I have defined a refresh command that will request a session id. So if I press that first, the device will work “first” time. What I actually want to do, is cache the command, try it, if I get a unauthorized back in the parse function, then perform the sendHubCommand equivalent to request the session id, and when I have that (from the parse funtion), then perform the cached command.
I tried sending a refresh event from the parse function, hoping that will fire the refresh command, but no luck.
Another option would be to get a hook into when the user opens the device page. I have not seen any examples or documentation that makes me believe that is possible.
Any suggestions from the code gurus here?