Skip to content

Instantly share code, notes, and snippets.

Created March 6, 2018 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c709b0acba5f0244543872b129c63606 to your computer and use it in GitHub Desktop.
Save anonymous/c709b0acba5f0244543872b129c63606 to your computer and use it in GitHub Desktop.
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