mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-30 06:13:05 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb3d2d001d | ||
|
|
a4ebe87f4e | ||
|
|
f84e21d83a | ||
|
|
85175eb298 | ||
|
|
c75568bcf1 | ||
|
|
fb6cbcc35e | ||
|
|
097584944e | ||
|
|
9263107f0e |
@@ -45,7 +45,16 @@ metadata {
|
|||||||
valueTile("temperature", "device.temperature", width: 2, height: 2) {
|
valueTile("temperature", "device.temperature", width: 2, height: 2) {
|
||||||
state("temperature", label:'${currentValue}°', unit:"F",
|
state("temperature", label:'${currentValue}°', unit:"F",
|
||||||
backgroundColors:[
|
backgroundColors:[
|
||||||
[value: 31, color: "#153591"],
|
// Celsius
|
||||||
|
[value: 0, color: "#153591"],
|
||||||
|
[value: 7, color: "#1e9cbb"],
|
||||||
|
[value: 15, color: "#90d2a7"],
|
||||||
|
[value: 23, color: "#44b621"],
|
||||||
|
[value: 28, color: "#f1d801"],
|
||||||
|
[value: 35, color: "#d04e00"],
|
||||||
|
[value: 37, color: "#bc2323"],
|
||||||
|
// Fahrenheit
|
||||||
|
[value: 40, color: "#153591"],
|
||||||
[value: 44, color: "#1e9cbb"],
|
[value: 44, color: "#1e9cbb"],
|
||||||
[value: 59, color: "#90d2a7"],
|
[value: 59, color: "#90d2a7"],
|
||||||
[value: 74, color: "#44b621"],
|
[value: 74, color: "#44b621"],
|
||||||
@@ -103,7 +112,7 @@ metadata {
|
|||||||
state "humidity", label:'${currentValue}%'
|
state "humidity", label:'${currentValue}%'
|
||||||
}
|
}
|
||||||
main "temperature"
|
main "temperature"
|
||||||
details(["temperature", "upButtonControl", "thermostatSetpoint", "currentStatus", "downButtonControl", "mode", "fanMode","resumeProgram", "humidity", "refresh"])
|
details(["temperature", "upButtonControl", "thermostatSetpoint", "currentStatus", "downButtonControl", "mode", "fanMode","humidity", "resumeProgram", "refresh"])
|
||||||
}
|
}
|
||||||
|
|
||||||
preferences {
|
preferences {
|
||||||
@@ -421,6 +430,10 @@ def heat() {
|
|||||||
generateStatusEvent()
|
generateStatusEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def emergencyHeat() {
|
||||||
|
auxHeatOnly()
|
||||||
|
}
|
||||||
|
|
||||||
def auxHeatOnly() {
|
def auxHeatOnly() {
|
||||||
log.debug "auxHeatOnly"
|
log.debug "auxHeatOnly"
|
||||||
def deviceId = device.deviceNetworkId.split(/\./).last()
|
def deviceId = device.deviceNetworkId.split(/\./).last()
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -39,7 +39,7 @@ private getFriendlyName(String deviceNetworkId) {
|
|||||||
sendHubCommand(new physicalgraph.device.HubAction("""GET /setup.xml HTTP/1.1
|
sendHubCommand(new physicalgraph.device.HubAction("""GET /setup.xml HTTP/1.1
|
||||||
HOST: ${deviceNetworkId}
|
HOST: ${deviceNetworkId}
|
||||||
|
|
||||||
""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))
|
""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}", [callback: "setupHandler"]))
|
||||||
}
|
}
|
||||||
|
|
||||||
private verifyDevices() {
|
private verifyDevices() {
|
||||||
@@ -52,6 +52,13 @@ private verifyDevices() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ssdpSubscribe() {
|
||||||
|
subscribe(location, "ssdpTerm.urn:Belkin:device:insight:1", ssdpSwitchHandler)
|
||||||
|
subscribe(location, "ssdpTerm.urn:Belkin:device:controllee:1", ssdpSwitchHandler)
|
||||||
|
subscribe(location, "ssdpTerm.urn:Belkin:device:sensor:1", ssdpMotionHandler)
|
||||||
|
subscribe(location, "ssdpTerm.urn:Belkin:device:lightswitch:1", ssdpLightSwitchHandler)
|
||||||
|
}
|
||||||
|
|
||||||
def firstPage()
|
def firstPage()
|
||||||
{
|
{
|
||||||
if(canInstallLabs())
|
if(canInstallLabs())
|
||||||
@@ -62,7 +69,7 @@ def firstPage()
|
|||||||
|
|
||||||
log.debug "REFRESH COUNT :: ${refreshCount}"
|
log.debug "REFRESH COUNT :: ${refreshCount}"
|
||||||
|
|
||||||
subscribe(location, null, locationHandler, [filterEvents:false])
|
ssdpSubscribe()
|
||||||
|
|
||||||
//ssdp request every 25 seconds
|
//ssdp request every 25 seconds
|
||||||
if((refreshCount % 5) == 0) {
|
if((refreshCount % 5) == 0) {
|
||||||
@@ -105,9 +112,7 @@ def devicesDiscovered() {
|
|||||||
def motions = getWemoMotions()
|
def motions = getWemoMotions()
|
||||||
def lightSwitches = getWemoLightSwitches()
|
def lightSwitches = getWemoLightSwitches()
|
||||||
def devices = switches + motions + lightSwitches
|
def devices = switches + motions + lightSwitches
|
||||||
def list = []
|
devices?.collect{ [app.id, it.ssdpUSN].join('.') }
|
||||||
|
|
||||||
list = devices?.collect{ [app.id, it.ssdpUSN].join('.') }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def switchesDiscovered() {
|
def switchesDiscovered() {
|
||||||
@@ -176,7 +181,8 @@ def updated() {
|
|||||||
def initialize() {
|
def initialize() {
|
||||||
unsubscribe()
|
unsubscribe()
|
||||||
unschedule()
|
unschedule()
|
||||||
subscribe(location, null, locationHandler, [filterEvents:false])
|
|
||||||
|
ssdpSubscribe()
|
||||||
|
|
||||||
if (selectedSwitches)
|
if (selectedSwitches)
|
||||||
addSwitches()
|
addSwitches()
|
||||||
@@ -313,6 +319,127 @@ def addLightSwitches() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def ssdpSwitchHandler(evt) {
|
||||||
|
def description = evt.description
|
||||||
|
def hub = evt?.hubId
|
||||||
|
def parsedEvent = parseDiscoveryMessage(description)
|
||||||
|
parsedEvent << ["hub":hub]
|
||||||
|
log.debug parsedEvent
|
||||||
|
|
||||||
|
def switches = getWemoSwitches()
|
||||||
|
if (!(switches."${parsedEvent.ssdpUSN.toString()}")) {
|
||||||
|
//if it doesn't already exist
|
||||||
|
switches << ["${parsedEvent.ssdpUSN.toString()}":parsedEvent]
|
||||||
|
} else {
|
||||||
|
log.debug "Device was already found in state..."
|
||||||
|
def d = switches."${parsedEvent.ssdpUSN.toString()}"
|
||||||
|
boolean deviceChangedValues = false
|
||||||
|
log.debug "$d.ip <==> $parsedEvent.ip"
|
||||||
|
if(d.ip != parsedEvent.ip || d.port != parsedEvent.port) {
|
||||||
|
d.ip = parsedEvent.ip
|
||||||
|
d.port = parsedEvent.port
|
||||||
|
deviceChangedValues = true
|
||||||
|
log.debug "Device's port or ip changed..."
|
||||||
|
def child = getChildDevice(parsedEvent.mac)
|
||||||
|
child.subscribe(parsedEvent.ip, parsedEvent.port)
|
||||||
|
child.poll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def ssdpMotionHandler(evt) {
|
||||||
|
log.info("ssdpMotionHandler")
|
||||||
|
def description = evt.description
|
||||||
|
def hub = evt?.hubId
|
||||||
|
def parsedEvent = parseDiscoveryMessage(description)
|
||||||
|
parsedEvent << ["hub":hub]
|
||||||
|
log.debug parsedEvent
|
||||||
|
|
||||||
|
def motions = getWemoMotions()
|
||||||
|
if (!(motions."${parsedEvent.ssdpUSN.toString()}")) {
|
||||||
|
//if it doesn't already exist
|
||||||
|
motions << ["${parsedEvent.ssdpUSN.toString()}":parsedEvent]
|
||||||
|
} else { // just update the values
|
||||||
|
log.debug "Device was already found in state..."
|
||||||
|
|
||||||
|
def d = motions."${parsedEvent.ssdpUSN.toString()}"
|
||||||
|
boolean deviceChangedValues = false
|
||||||
|
|
||||||
|
if(d.ip != parsedEvent.ip || d.port != parsedEvent.port) {
|
||||||
|
d.ip = parsedEvent.ip
|
||||||
|
d.port = parsedEvent.port
|
||||||
|
deviceChangedValues = true
|
||||||
|
log.debug "Device's port or ip changed..."
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceChangedValues) {
|
||||||
|
def children = getChildDevices()
|
||||||
|
log.debug "Found children ${children}"
|
||||||
|
children.each {
|
||||||
|
if (it.getDeviceDataByName("mac") == parsedEvent.mac) {
|
||||||
|
log.debug "updating ip and port, and resubscribing, for device ${it} with mac ${parsedEvent.mac}"
|
||||||
|
it.subscribe(parsedEvent.ip, parsedEvent.port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def ssdpLightSwitchHandler(evt) {
|
||||||
|
log.info("ssdpLightSwitchHandler")
|
||||||
|
def description = evt.description
|
||||||
|
def hub = evt?.hubId
|
||||||
|
def parsedEvent = parseDiscoveryMessage(description)
|
||||||
|
parsedEvent << ["hub":hub]
|
||||||
|
log.debug parsedEvent
|
||||||
|
|
||||||
|
def lightSwitches = getWemoLightSwitches()
|
||||||
|
|
||||||
|
if (!(lightSwitches."${parsedEvent.ssdpUSN.toString()}")) {
|
||||||
|
//if it doesn't already exist
|
||||||
|
lightSwitches << ["${parsedEvent.ssdpUSN.toString()}":parsedEvent]
|
||||||
|
} else {
|
||||||
|
log.debug "Device was already found in state..."
|
||||||
|
|
||||||
|
def d = lightSwitches."${parsedEvent.ssdpUSN.toString()}"
|
||||||
|
boolean deviceChangedValues = false
|
||||||
|
|
||||||
|
if(d.ip != parsedEvent.ip || d.port != parsedEvent.port) {
|
||||||
|
d.ip = parsedEvent.ip
|
||||||
|
d.port = parsedEvent.port
|
||||||
|
deviceChangedValues = true
|
||||||
|
log.debug "Device's port or ip changed..."
|
||||||
|
def child = getChildDevice(parsedEvent.mac)
|
||||||
|
log.debug "updating ip and port, and resubscribing, for device with mac ${parsedEvent.mac}"
|
||||||
|
child.subscribe(parsedEvent.ip, parsedEvent.port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupHandler(hubResponse) {
|
||||||
|
String contentType = hubResponse?.headers['Content-Type']
|
||||||
|
if (contentType != null && contentType == 'text/xml') {
|
||||||
|
def body = hubResponse.xml
|
||||||
|
def wemoDevices = []
|
||||||
|
String deviceType = body?.device?.deviceType?.text() ?: ""
|
||||||
|
if (deviceType.startsWith("urn:Belkin:device:controllee:1") || deviceType.startsWith("urn:Belkin:device:insight:1")) {
|
||||||
|
wemoDevices = getWemoSwitches()
|
||||||
|
} else if (deviceType.startsWith("urn:Belkin:device:sensor")) {
|
||||||
|
wemoDevices = getWemoMotions()
|
||||||
|
} else if (deviceType.startsWith("urn:Belkin:device:lightswitch")) {
|
||||||
|
wemoDevices = getWemoLightSwitches()
|
||||||
|
}
|
||||||
|
|
||||||
|
def wemoDevice = wemoDevices.find {it?.key?.contains(body?.device?.UDN?.text())}
|
||||||
|
if (wemoDevice) {
|
||||||
|
wemoDevice.value << [name:body?.device?.friendlyName?.text(), verified: true]
|
||||||
|
} else {
|
||||||
|
log.error "/setup.xml returned a wemo device that didn't exist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
def locationHandler(evt) {
|
def locationHandler(evt) {
|
||||||
def description = evt.description
|
def description = evt.description
|
||||||
def hub = evt?.hubId
|
def hub = evt?.hubId
|
||||||
@@ -459,6 +586,7 @@ def locationHandler(evt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private def parseXmlBody(def body) {
|
private def parseXmlBody(def body) {
|
||||||
def decodedBytes = body.decodeBase64()
|
def decodedBytes = body.decodeBase64()
|
||||||
def bodyString
|
def bodyString
|
||||||
|
|||||||
Reference in New Issue
Block a user