Code by Scott שאול בן ישוע
Verified Commit ef0013f7 authored by Sha'ul ben Yeshua's avatar Sha'ul ben Yeshua 🎗
Browse files

Code changes.

parent df2e34ef
Pipeline #359 passed with stage
in 10 seconds
......@@ -39,6 +39,7 @@
*-------------------------------------------------------------------------------------------------------------------
*
* Changes:
* 2.0.2 - Added presence checking - Refresh code changed
* 2.0.1 - Code re-write for json
* - Removed all ST code
* 2.0.0 - New License -- Personal Use Only
......@@ -66,7 +67,8 @@
*/
import groovy.json.*
import groovy.transform.Field
metadata {
definition (
name: "Raspberry Pi Stats",
......@@ -80,6 +82,7 @@ metadata {
capability "Refresh"
capability "Temperature Measurement"
capability "Sensor"
capability "PresenceSensor"
attribute "cpuFrequency", "number"
attribute "freeMemory", "number"
......@@ -102,13 +105,21 @@ metadata {
}
preferences {
input("ip", "string", title:"RPi IP Address", description: "", defaultValue: "" ,required: true, displayDuringSetup: true)
def refreshRate = [:]
refreshRate << ["1 min" : "Refresh every minute"]
refreshRate << ["5 min" : "Refresh every 5 minutes"]
refreshRate << ["15 min" : "Refresh every 15 minutes"]
refreshRate << ["30 min" : "Refresh every 30 minutes"]
refreshRate << ["manual" : "Manually or Polling Only"]
input("ip", "string", title:"RPi IP Address", description: "", defaultValue: "" ,required: true, displayDuringSetup: true)
input("port", "string", title:"Port", description: "8080", defaultValue: "8080" , required: true, displayDuringSetup: true)
input "refreshEvery", "enum", title: "Enable auto refresh every XX Minutes", required: false, defaultValue: false,
options: [5:"5 minutes",10:"10 minutes",15:"15 minutes",30:"30 minutes",Polling:"Polling"]
input "locale", "enum", title: "Choose refresh date format", required: true, defaultValue: true,
input "refresh_Rate", "enum", title: "Enable auto refresh every XX Minutes", options: refreshRate, defaultValue: "5 min"
input "locale", "enum", title: "Choose refresh date format", required: true, defaultValue: true,
options: [US:"US MM/DD/YYYY",UK:"UK DD/MM/YYYY"]
input name: "debugOutput", type: "bool", title: "Enable debug logging?", defaultValue: true
input name: "debugOutput", type: "bool", title: "Enable debug logging?", defaultValue: true
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
}
}
......@@ -120,7 +131,7 @@ def installed() {
// App Version *********************************************************************************
def setVersion(){
state.Version = "2.0.1"
state.Version = "2.0.2"
state.InternalName = "RaspberryPiStats"
}
......@@ -130,13 +141,25 @@ def updated() {
log.warn "Debug logging is: ${debugOutput == true}"
unschedule()
if (refreshEvery != "Polling") {
"runEvery${refreshEvery}Minutes"(autorefresh)
log.info "Refresh set for every ${refreshEvery} Minutes"
} else {
unschedule(autorefresh)
log.info "Refresh set to polling only"
}
switch(refresh_Rate) {
case "1 min" :
runEvery1Minute(autorefresh)
break
case "5 min" :
runEvery5Minutes(autorefresh)
break
case "15 min" :
runEvery15Minutes(autorefresh)
break
case "30 min" :
runEvery30Minutes(autorefresh)
break
case "manual" :
unschedule(autorefresh)
log.info "Autorefresh disabled"
break
}
if (debugOutput) runIn(1800,logsOff)
version()
......@@ -176,6 +199,7 @@ try {
logDebug "response data: ${resp.data}"
sendEvent(name: "online", value: "Online")
sendEvent(name: "presence", value: "present")
if (json.containsKey("cpuTemperature")) {
if (getTemperatureScale() == "C") {
......@@ -235,6 +259,7 @@ try {
} // End try
} catch (e) {
sendEvent(name: "online", value: "Offline")
sendEvent(name: "presence", value: "not present")
log.error "something went wrong: $e"
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment