Created
March 6, 2018 18:31
-
-
Save anonymous/c709b0acba5f0244543872b129c63606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
metadata { | |
definition (name: "Rompr2", namespace: "ngw", author: "Niv Gal Waizer") { | |
capability "Switch" | |
} | |
simulator { | |
// TODO: define status and reply messages here | |
} | |
tiles() { | |
standardTile("deviceDiscovery", "device.status", width: 1, height: 1, decoration: "flat") { | |
state "on", label:'on', action:"off", icon:"st.Electronics.electronics19", nextState:"off", backgroundColor: "#00a0dc" | |
state "off", label:'off', action:"on", icon:"st.Electronics.electronics19", nextState:"on", backgroundColor:"#ffffff" | |
} | |
main("deviceDiscovery") | |
details([ | |
"deviceDiscovery" | |
]) | |
} | |
preferences { | |
section { | |
input name: "searchTarget", type: "string", title: "Search Target", defaultValue: "urn:schemas-upnp-org:device:ZonePlayer:1", required: false, displayDuringSetup: true | |
} | |
} | |
} | |
def message(msg){ | |
// logs <server url>/my/path | |
//log.debug "apiServerUrl: ${apiServerUrl("/my/path")}" | |
log.debug("***** '${msg}'") | |
} | |
def parse(String description) { | |
// handle device messages, determine what value of the Event is | |
return createEvent(name: "switch", value: someValue) | |
} | |
// handle commands | |
def on() { | |
message("on") | |
deviceDiscovery() | |
} | |
def off() { | |
deviceDiscovery() | |
message("off") | |
} | |
//ssdp stuff below | |
def deviceDiscovery() { | |
message("Starting ssdpSubscribe") | |
ssdpSubscribe() | |
ssdpDiscover() | |
} | |
void ssdpDiscover() { | |
message("looking for devices $searchTarget") | |
sendHubCommand(new physicalgraph.device.HubAction("lan discovery $searchTarget", physicalgraph.device.Protocol.LAN)) | |
} | |
void ssdpSubscribe() { | |
message("ssdp subscribe") | |
subscribe(location, "ssdpTerm.$searchTarget", ssdpHandler) | |
} | |
def ssdpHandler(evt) { | |
message(evt) | |
def description = evt.description | |
def hub = evt?.hubId | |
message(description) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment