mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-19 13:20:53 +00:00
Modifying 'Publish a SmartApp for OpenT2T - Update sensor and subscriptions.'
This commit is contained in:
@@ -108,6 +108,12 @@ mappings {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
log.debug "Installing with settings: ${settings}"
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
def updated() {
|
def updated() {
|
||||||
log.debug "Updating with settings: ${settings}"
|
log.debug "Updating with settings: ${settings}"
|
||||||
if(state.deviceSubscriptionMap == null){
|
if(state.deviceSubscriptionMap == null){
|
||||||
@@ -115,7 +121,7 @@ def updated() {
|
|||||||
log.debug "deviceSubscriptionMap created."
|
log.debug "deviceSubscriptionMap created."
|
||||||
}
|
}
|
||||||
if( state.locationSubscriptionMap == null){
|
if( state.locationSubscriptionMap == null){
|
||||||
state.locationSubscriptionMap = [:]
|
state.locationSubscriptionMap = [:]
|
||||||
log.debug "locationSubscriptionMap created."
|
log.debug "locationSubscriptionMap created."
|
||||||
}
|
}
|
||||||
unsubscribe()
|
unsubscribe()
|
||||||
@@ -169,7 +175,7 @@ def registerDeviceChange() {
|
|||||||
if(state.deviceSubscriptionMap[deviceId] == null){
|
if(state.deviceSubscriptionMap[deviceId] == null){
|
||||||
state.deviceSubscriptionMap.put(deviceId, [subscriptionEndpt])
|
state.deviceSubscriptionMap.put(deviceId, [subscriptionEndpt])
|
||||||
log.info "Added subscription URL: ${subscriptionEndpt} for ${myDevice.displayName}"
|
log.info "Added subscription URL: ${subscriptionEndpt} for ${myDevice.displayName}"
|
||||||
}else if (!state.deviceSubscriptionMap[deviceId].contains(subscriptionEndpt)){
|
} else if (!state.deviceSubscriptionMap[deviceId].contains(subscriptionEndpt)){
|
||||||
state.deviceSubscriptionMap[deviceId] << subscriptionEndpt
|
state.deviceSubscriptionMap[deviceId] << subscriptionEndpt
|
||||||
log.info "Added subscription URL: ${subscriptionEndpt} for ${myDevice.displayName}"
|
log.info "Added subscription URL: ${subscriptionEndpt} for ${myDevice.displayName}"
|
||||||
}
|
}
|
||||||
@@ -225,7 +231,7 @@ def registerDeviceGraph() {
|
|||||||
if(state.locationSubscriptionMap[location.id] == null){
|
if(state.locationSubscriptionMap[location.id] == null){
|
||||||
state.locationSubscriptionMap.put(location.id, [subscriptionEndpt])
|
state.locationSubscriptionMap.put(location.id, [subscriptionEndpt])
|
||||||
log.info "Added subscription URL: ${subscriptionEndpt} for Location ${location.name}"
|
log.info "Added subscription URL: ${subscriptionEndpt} for Location ${location.name}"
|
||||||
}else if (!state.locationSubscriptionMap[location.id].contains(subscriptionEndpt)){
|
} else if (!state.locationSubscriptionMap[location.id].contains(subscriptionEndpt)){
|
||||||
state.locationSubscriptionMap[location.id] << subscriptionEndpt
|
state.locationSubscriptionMap[location.id] << subscriptionEndpt
|
||||||
log.info "Added subscription URL: ${subscriptionEndpt} for Location ${location.name}"
|
log.info "Added subscription URL: ${subscriptionEndpt} for Location ${location.name}"
|
||||||
}
|
}
|
||||||
@@ -320,6 +326,7 @@ def locationEventHandler(evt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*** Device Query/Update Functions ***/
|
/*** Device Query/Update Functions ***/
|
||||||
|
|
||||||
//Endpoints function: return all device data in json format
|
//Endpoints function: return all device data in json format
|
||||||
@@ -331,7 +338,7 @@ def getDevices() {
|
|||||||
deviceData << [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it, deviceType), locationMode: getLocationModeInfo()]
|
deviceData << [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it, deviceType), locationMode: getLocationModeInfo()]
|
||||||
} else {
|
} else {
|
||||||
deviceData << [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it, deviceType)]
|
deviceData << [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it, deviceType)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug "getDevices, return: ${deviceData}"
|
log.debug "getDevices, return: ${deviceData}"
|
||||||
@@ -434,15 +441,15 @@ private getDeviceType(device) {
|
|||||||
//If the device also contains "Switch Level" capability, identify it as a "light" device.
|
//If the device also contains "Switch Level" capability, identify it as a "light" device.
|
||||||
if (capabilities.any{it.name.toLowerCase() == "switch level"}){
|
if (capabilities.any{it.name.toLowerCase() == "switch level"}){
|
||||||
|
|
||||||
//If the device also contains "Power Meter" capability, identify it as a "dimmerSwitch" device.
|
//If the device also contains "Power Meter" capability, identify it as a "dimmerSwitch" device.
|
||||||
if (capabilities.any{it.name.toLowerCase() == "power meter"}){
|
if (capabilities.any{it.name.toLowerCase() == "power meter"}){
|
||||||
deviceType = "dimmerSwitch"
|
deviceType = "dimmerSwitch"
|
||||||
return deviceType
|
return deviceType
|
||||||
} else {
|
} else {
|
||||||
deviceType = "light"
|
deviceType = "light"
|
||||||
return deviceType
|
return deviceType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "garageDoorControl":
|
case "garageDoorControl":
|
||||||
deviceType = "garageDoor"
|
deviceType = "garageDoor"
|
||||||
@@ -480,24 +487,24 @@ private deviceAttributeList(device, deviceType) {
|
|||||||
def attributeList = [:]
|
def attributeList = [:]
|
||||||
def allAttributes = device.supportedAttributes
|
def allAttributes = device.supportedAttributes
|
||||||
allAttributes.each { attribute ->
|
allAttributes.each { attribute ->
|
||||||
try {
|
try {
|
||||||
def currentState = device.currentState(attribute.name)
|
def currentState = device.currentState(attribute.name)
|
||||||
if(currentState != null ){
|
if(currentState != null ){
|
||||||
switch(attribute.name){
|
switch(attribute.name){
|
||||||
case 'temperature':
|
case 'temperature':
|
||||||
attributeList.putAll([ (attribute.name): currentState.value, 'temperatureScale':location.temperatureScale ])
|
attributeList.putAll([ (attribute.name): currentState.value, 'temperatureScale':location.temperatureScale ])
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
attributeList.putAll([(attribute.name): currentState.value ])
|
attributeList.putAll([(attribute.name): currentState.value ])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( deviceType == "genericSensor" ){
|
if( deviceType == "genericSensor" ){
|
||||||
def key = attribute.name + "_lastUpdated"
|
def key = attribute.name + "_lastUpdated"
|
||||||
attributeList.putAll([ (key): currentState.isoDate ])
|
attributeList.putAll([ (key): currentState.isoDate ])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
attributeList.putAll([ (attribute.name): null ]);
|
attributeList.putAll([ (attribute.name): null ]);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
attributeList.putAll([ (attribute.name): null ]);
|
attributeList.putAll([ (attribute.name): null ]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user