Hi
Apologies for the basic query - I’m very new to this.
I’m using tguerena and surge919 's basic URI device handler as the basis of a new device type I’m trying to write, specifically an on/off switch for my BlueSound players.
It works as a stateless on/off switch, the device state ‘estimated’ by SmartThings based on the last thing it did.
However, I’d like to give the device handler refresh capability. That way, the device’s real status can be checked. I know the URI to get the info and how to plumb the return XML in other languages, but Groovy/SmartThings is fresh for me.
The current issue I’m having is when I call my HubAction via SendHubCommand, the Parse function is not being hit. What am I missing here?
Code as follows:
/*
- Author: tguerena and surge919
- Device Handler
*/
preferences {
section(“External Access”){
input “external_on_uri”, “text”, title: “External On URI”, required: false
input “external_off_uri”, “text”, title: “External Off URI”, required: false
input “external_state_check_uri”, “text”, title: “External State Check URI”, required: false
}
section("Internal Access"){
input "internal_ip", "text", title: "Internal IP", required: false
input "internal_port", "text", title: "Internal Port (if not 80)", required: false
input "internal_on_path", "text", title: "Internal On Path (/blah?q=this)", required: false
input "internal_off_path", "text", title: "Internal Off Path (/blah?q=this)", required: false
input "internal_state_check", "text", title:"Internal State Check (/blah?q=this", required: false
}
}
metadata {
definition (name: “URI Switch”, namespace: “tguerena”, author: “Troy Guerena”) {
capability "Actuator"
capability "Switch"
capability "Sensor"
capability “Refresh”
}
// simulator metadata
simulator {
}
// UI tile definitions
tiles {
standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: 'Off', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "on"
state "on", label: 'On', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState: "off"
}
standardTile("offButton", "device.switch", width: 1, height: 1, canChangeIcon: true) {
state "default", label: 'Force Off', action: "switch.off", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
standardTile("onButton", "device.switch", width: 1, height: 1, canChangeIcon: true) {
state "default", label: 'Force On', action: "switch.on", icon: "st.switches.switch.on", backgroundColor: "#79b821"
}
standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat", width: 1, height: 1) {
state "default", label:'Refresh', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "button"
details (["button","onButton","offButton","refresh"])
}
}
def parse(description) {
log.debug “HELLO!”
// log.debug “Parsing ‘${description}’”
// def results = []
// def result = parent.parse(this, description)
// if (result instanceof physicalgraph.device.HubAction){
// results << result
// }
}
//def parse(String description) {
//log.debug(description)
//}
def on() {
if (external_on_uri){
// sendEvent(name: “switch”, value: “on”)
// log.debug “Executing ON”
def cmd = "${settings.external_on_uri}";
log.debug "Sending request cmd[${cmd}]"
httpGet(cmd) {resp ->
if (resp.data) {
log.info "${resp.data}"
}
}
}
if (internal_on_path){
def port
if (internal_port){
port = "${internal_port}"
} else {
port = 80
}
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "${internal_on_path}",
headers: [
HOST: "${internal_ip}:${port}"
]
)
sendHubCommand(result)
sendEvent(name: "switch", value: "on")
log.debug "Executing ON"
log.debug result
}
}
def off() {
if (external_off_uri){
def cmd = “${settings.external_off_uri}”;
log.debug "Sending request cmd[${cmd}]"
httpGet(cmd) {resp ->
if (resp.data) {
log.info “${resp.data}”
}
}
}
if (internal_off_path){
def port
if (internal_port){
port = “${internal_port}”
} else {
port = 80
}
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "${internal_off_path}",
headers: [
HOST: "${internal_ip}:${port}"
]
)
sendEvent(name: "switch", value: "off")
log.debug "Executing OFF"
log.debug result
}
}
def refresh() {
if (external_state_check_uri){
// sendEvent(name: "switch", value: "on")
// log.debug "Executing ON"
def cmd = "${settings.external_state_check_uri}";
log.debug "Sending request cmd[${cmd}]"
httpGet(cmd) {resp ->
if (resp.data) {
log.info "${resp.data}"
}
}
}
if (internal_state_check){
def port
if (internal_port){
port = "${internal_port}"
} else {
port = 80
}
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "${internal_off_path}",
headers: [
HOST: "${internal_ip}:${port}"
]
)
sendHubCommand(result)
log.debug "Executing REFRESH"
log.debug result
}
}