Compare commits

..

10 Commits

Author SHA1 Message Date
Vinay Rao
6349f95141 Merge pull request #2710 from SmartThingsCommunity/staging
Rolling up staging to production
2018-01-17 10:44:41 -08:00
Ingvar Marstorp
2be6e5f655 PROB-1869 Zen thermostat connecting with no battery state (#2671)
* PROB-1869 Zen thermostat connecting with no battery state
Changing algorithm for calculating battery % so it no longer need the check
for upper/lower limit of the received voltage.

* Update zen-thermostat.groovy
2018-01-16 13:15:52 -08:00
Bob Florian
cc2cd987ad Merge pull request #2698 from SmartThingsCommunity/production
Rolling production down to staging
2018-01-15 07:38:26 -08:00
Bob Florian
1716bcba2b Merge pull request #2694 from juano2310/lifx_hotfix
ICP-2947 - HOTFIX - Remove invalid token
2018-01-15 07:22:34 -08:00
juano2310
de8740d5e0 ICP-2947 - HOTFIX - Remove invalid token
Update

Update2
2018-01-13 15:24:29 -05:00
Bob Florian
be89b7dbe9 Merge pull request #2682 from juano2310/lifx_response_check
ICP-2750 - State after cutting off power
2018-01-08 20:28:13 -05:00
juano2310
263b0deeaa ICP-2750 - State after cutting off power
2** check
2018-01-08 18:16:52 -05:00
Vinay Rao
22b141416d Merge pull request #2675 from SmartThingsCommunity/master
Rolling up master to staging
2018-01-05 13:00:36 -08:00
Vinay Rao
9365b166d0 Merge pull request #2619 from SmartThingsCommunity/staging
Rolling up staging to production
2017-12-12 15:33:37 -08:00
Vinay Rao
0fc84dafda Merge pull request #2594 from SmartThingsCommunity/staging
Rolling up staging to production
2017-12-05 14:37:50 -08:00
4 changed files with 32 additions and 16 deletions

View File

@@ -181,7 +181,8 @@ def setColorTemperature(kelvin) {
def on() {
log.debug "Device setOn"
parent.logErrors() {
if (parent.apiPUT("/lights/${selector()}/state", [power: "on"]) != null) {
def value = parent.apiPUT("/lights/${selector()}/state", [power: "on"])
if (value.status == 207 && value.data.results.status[0] == "ok") {
sendEvent(name: "switch", value: "on")
}
}
@@ -191,7 +192,8 @@ def on() {
def off() {
log.debug "Device setOff"
parent.logErrors() {
if (parent.apiPUT("/lights/${selector()}/state", [power: "off"]) != null) {
def value = parent.apiPUT("/lights/${selector()}/state", [power: "off"])
if (value.status == 207 && value.data.results.status[0] == "ok") {
sendEvent(name: "switch", value: "off")
}
}

View File

@@ -110,7 +110,8 @@ def setColorTemperature(kelvin) {
def on() {
log.debug "Device setOn"
parent.logErrors() {
if (parent.apiPUT("/lights/${selector()}/state", [power: "on"]) != null) {
def value = parent.apiPUT("/lights/${selector()}/state", [power: "on"])
if (value.status == 207 && value.data.results.status[0] == "ok") {
sendEvent(name: "switch", value: "on")
}
}
@@ -120,7 +121,8 @@ def on() {
def off() {
log.debug "Device setOff"
parent.logErrors() {
if (parent.apiPUT("/lights/${selector()}/state", [power: "off"]) != null) {
def value = parent.apiPUT("/lights/${selector()}/state", [power: "off"])
if (value.status == 207 && value.data.results.status[0] == "ok") {
sendEvent(name: "switch", value: "off")
}
}

View File

@@ -153,7 +153,7 @@ def updated() {
// make sure supporedModes are in sync
sendEvent(name: "supportedThermostatModes", value: supportedModes, eventType: "ENTITY_UPDATE", displayed: false)
// Make sure we poll all attributes from the device
state.pollAdditionalData = state.pollAdditionalData - (24 * 60 * 60 * 1000)
state.pollAdditionalData = state.pollAdditionalData ? state.pollAdditionalData - (24 * 60 * 60 * 1000) : null
// initialize() needs to be called after device details has been updated() but as installed() also calls this method and
// that LiveLogging shows updated is being called more than one time, try avoiding multiple config/poll be done us runIn ;o(
runIn(3, "initialize", [overwrite: true])
@@ -419,14 +419,14 @@ def updateBatteryStatus(rawValue) {
// customAttribute in order to change UI icon/label
def eventMap = [name: "batteryIcon", value: "err_battery", displayed: false]
def linkText = getLinkText(device)
if (volts < 62 && volts != 0 && volts != 255) {
def minVolts = 34 // voltage when device UI starts to die
def maxVolts = 61 // 4 batteries at 1.5V should be 6.0V, however logs from users show 6,1 as well
def pct = (volts - minVolts) / (maxVolts - minVolts)
eventMap.value = Math.min(100, (int) pct * 100)
if (volts != 255) {
def minVolts = 34 // voltage when device UI starts to die, ie. when battery fails
def maxVolts = 60 // 4 batteries at 1.5V (6.0V)
def pct = (volts > minVolts) ? ((volts - minVolts) / (maxVolts - minVolts)) : 0
eventMap.value = Math.min(100, (int)(pct * 100))
// Update capability "Battery"
sendEvent(name: "battery", value: eventMap.value, descriptionText: "${getLinkText(device)} battery was ${eventMap.value}%")
eventMap.value = eventMap.value > 10 ? eventMap.value : "low_battery"
eventMap.value = eventMap.value > 15 ? eventMap.value : "low_battery"
}
sendEvent(eventMap)
} else {

View File

@@ -51,7 +51,11 @@ def getClientId() { return appSettings.clientId }
private getVendorName() { "LIFX" }
def authPage() {
log.debug "authPage test1"
if (state.lifxAccessToken) {
def validateToken = locationOptions() ?: []
}
if (!state.lifxAccessToken) {
log.debug "no LIFX access token"
// This is the SmartThings access token
@@ -61,9 +65,6 @@ def authPage() {
}
def description = "Tap to enter LIFX credentials"
def redirectUrl = "${serverUrl}/oauth/initialize?appId=${app.id}&access_token=${state.accessToken}&apiServerUrl=${apiServerUrl}" // this triggers oauthInit() below
// def redirectUrl = "${apiServerUrl}"
// log.debug "app id: ${app.id}"
// log.debug "redirect url: ${redirectUrl}"s
return dynamicPage(name: "Credentials", title: "Connect to LIFX", nextPage: null, uninstall: true, install:true) {
section {
href(url:redirectUrl, required:true, title:"Connect to LIFX", description:"Tap here to connect your LIFX account")
@@ -322,7 +323,7 @@ def logErrors(options = [errorReturn: null, logObject: log], Closure c) {
} catch (groovyx.net.http.HttpResponseException e) {
options.logObject.error("got error: ${e}, body: ${e.getResponse().getData()}")
if (e.statusCode == 401) { // token is expired
state.remove("lifxAccessToken")
state.lifxAccessToken = null
options.logObject.warn "Access token is not valid"
}
return options.errorReturn
@@ -335,6 +336,10 @@ def logErrors(options = [errorReturn: null, logObject: log], Closure c) {
def apiGET(path) {
try {
httpGet(uri: apiURL(path), headers: apiRequestHeaders()) {response ->
if (response.status == 401) { // token is expired
log.warn "Access token is not valid"
state.lifxAccessToken = null
}
logResponse(response)
return response
}
@@ -348,6 +353,10 @@ def apiPUT(path, body = [:]) {
try {
log.debug("Beginning API PUT: ${path}, ${body}")
httpPutJson(uri: apiURL(path), body: new groovy.json.JsonBuilder(body).toString(), headers: apiRequestHeaders(), ) {response ->
if (response.status == 401) { // token is expired
log.warn "Access token is not valid"
state.lifxAccessToken = null
}
logResponse(response)
return response
}
@@ -361,6 +370,9 @@ def devicesList(selector = '') {
def resp = apiGET("/lights/${selector}")
if (resp.status == 200) {
return resp.data
} else if (resp.status == 401) {
log.warn "Access token is not valid"
state.lifxAccessToken = null
} else {
log.debug("No response from device list call. ${resp.status} ${resp.data}")
return []