mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-31 22:04:30 +01:00
Compare commits
1 Commits
MSA-1361-1
...
MSA-1370-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b285ec93b |
@@ -1,34 +0,0 @@
|
|||||||
definition(
|
|
||||||
name: "Beep, When Closed",
|
|
||||||
namespace: "smartthings",
|
|
||||||
author: "SmartThings",
|
|
||||||
description: "Beep presence sensor when open/close sensor closes.",
|
|
||||||
category: "Convenience",
|
|
||||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
|
||||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png",
|
|
||||||
)
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
section ("When closes...") {
|
|
||||||
input "contact1", "capability.contactSensor", title: "Which open/contact sensor?"
|
|
||||||
}
|
|
||||||
section("Beep the presence sensor..") {
|
|
||||||
input "presence", "capability.presenceSensor", title: "Which sensor beep?"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def installed()
|
|
||||||
{
|
|
||||||
subscribe(contact1, "contact.closed", contactClosedHandler)
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated()
|
|
||||||
{
|
|
||||||
unsubscribe()
|
|
||||||
subscribe(contact1, "contact.closed", contactClosedHandler)
|
|
||||||
}
|
|
||||||
|
|
||||||
def contactClosedHandler(evt) {
|
|
||||||
|
|
||||||
presence.beep()
|
|
||||||
}
|
|
||||||
@@ -824,17 +824,51 @@ def deviceHandler(evt) {
|
|||||||
|
|
||||||
def sendToHarmony(evt, String callbackUrl) {
|
def sendToHarmony(evt, String callbackUrl) {
|
||||||
def callback = new URI(callbackUrl)
|
def callback = new URI(callbackUrl)
|
||||||
def host = callback.port != -1 ? "${callback.host}:${callback.port}" : callback.host
|
if(isIP(callback.host)){
|
||||||
def path = callback.query ? "${callback.path}?${callback.query}".toString() : callback.path
|
def host = callback.port != -1 ? "${callback.host}:${callback.port}" : callback.host
|
||||||
sendHubCommand(new physicalgraph.device.HubAction(
|
def path = callback.query ? "${callback.path}?${callback.query}".toString() : callback.path
|
||||||
method: "POST",
|
sendHubCommand(new physicalgraph.device.HubAction(
|
||||||
path: path,
|
method: "POST",
|
||||||
headers: [
|
path: path,
|
||||||
"Host": host,
|
headers: [
|
||||||
"Content-Type": "application/json"
|
"Host": host,
|
||||||
],
|
"Content-Type": "application/json"
|
||||||
body: [evt: [deviceId: evt.deviceId, name: evt.name, value: evt.value]]
|
],
|
||||||
))
|
body: [evt: [deviceId: evt.deviceId, name: evt.name, value: evt.value]]
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
def params = [
|
||||||
|
uri: callbackUrl,
|
||||||
|
body: [evt: [deviceId: evt.deviceId, name: evt.name, value: evt.value]]
|
||||||
|
]
|
||||||
|
try {
|
||||||
|
log.debug "Sending data to Harmony Cloud: $params"
|
||||||
|
httpPostJson(params) { resp ->
|
||||||
|
log.debug "Harmony Cloud - Response: ${resp.status}"
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error "Harmony Cloud - Something went wrong: $e"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isIP(String str) {
|
||||||
|
try {
|
||||||
|
String[] parts = str.split("\\.");
|
||||||
|
if (parts.length != 4) return false;
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
int p
|
||||||
|
try {
|
||||||
|
p = Integer.parseInt(parts[i]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (p > 255 || p < 0) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def listHubs() {
|
def listHubs() {
|
||||||
|
|||||||
Reference in New Issue
Block a user