Hi All,
I’ve been thinking about cross application integration now for a few weeks, partially as I am developing my own app, I know we can use dummy switches (but that’s painful) and I know that there are now a couple of applications specifically integrated or planning on integrating with CoRE.
However I have a proposal, that potentially makes bespoke integration needless and would then hopefully mean that a developer could integrate with any other capable application easily, however this would require key developers and the community as a whole to contribute, discuss and come to an agreement…
Do you think that this could work?
.
My proposal is:
- Harness sendLocationEvent in the same way CoRE already is with AskAlexa
- but make this a generic community event
- Each triggering app will listen for events on this LocationEvent for new events to trigger
- All apps using this community interface will have a small method, which is generic across all apps, to ensure consistent experience across all apps.
Starting point:
So rather than coming to the community with an idea, I have written some proposed code.
This code is a working idea, it may not be the best way to achieve this as I code for a hobby not a job, it may not meet everyone’s requirements, it may be completely deleted and re-written by someone else, and any feedback / changes / pull requests or even just saying it’s a bad idea are welcome… but it is a start!
What it does:
- It is a handler for the LocationEvent name:“appLink”
- It listens for (add) / (del) events from other apps
- It has in built handling to generate the (list) of all available apps and events to trigger
- It can send a LocationEvent directly to the app that should receive it, with an event ID to trigger
- It could if required also act as a response handler for success or failure, but I have not coded this as I didn’t want to spend a lot of time potentially writing some code that may not even be accepted by the community, and there may not be demand for it.
Data Structure:
- Data is held in a nested map [AppName: [TriggerID : TriggerDescription]]
- The AppName and TriggerID combined are the unique globally
- The TriggerID is unique within the target app
- The ID can be anything, but I would suggest if triggering child apps that you use the app ID, but could equally be any string.
- The list function returns the “[AppName] Trigger Description” producing something like the below, and is very simply called by appLinkHandler(value: “list”)
Code:
Essentially the core handler is the below 10 lines of code (depending on how creative you get with the return button)
def appLinkHandler(evt){
if(!state.appLink) state.appLink = [:]
switch(evt.value) { //[appLink V0.0.1 2016-11-23]
case "add": state.appLink << evt.jsonData; break;
case "del": state.appLink.remove(evt.jsonData.app); break;
case "list": def list = [:]; state.appLink.each {key, value -> value.each { skey, svalue -> list << ["${key}:${skey}" : "[${key}] ${svalue}"]}};
return list.sort { a, b -> a.value.toLowerCase() <=> b.value.toLowerCase() }; break;
case "send": sendLocationEvent(name: "${evt.data.split(":")[0]}", value: evt.data.split(":")[1] , isStateChange: true, descriptionText: "appLink Action")
}
state.appLink.remove("$app.name") // removes this app from list - optional/editable
}
Sand Pit Source:
I have a very rough outline of the code, with many comments throughout, showing how it can be used! The app itself from the front end is uninspiring as it is just a sand pit to play, I’ve just left code commented out which you can un-comment to activate when the app is run, and as it’s a demo it has dummy data just to show you what it’s doing (you will need to save the app exit and re-inter to populate the list for the first run)
Code can be integrated via GitHub in to ST
https://github.com/jebbett/appLink
https://github.com/jebbett/appLink/blob/master/smartapps/jebbett/applink.src/applink.groovy