Compare commits
10 Commits
user186_7
...
PROD_2018.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6349f95141 | ||
|
|
2be6e5f655 | ||
|
|
cc2cd987ad | ||
|
|
1716bcba2b | ||
|
|
de8740d5e0 | ||
|
|
be89b7dbe9 | ||
|
|
263b0deeaa | ||
|
|
22b141416d | ||
|
|
9365b166d0 | ||
|
|
0fc84dafda |
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 []
|
||||
|
||||
Reference in New Issue
Block a user