/*
* Uptime Widget
*
* Licensed Virtual the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 21Dec2023 thebearmay Initialize at install
* Add text color option
*
*/
import java.text.SimpleDateFormat
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.transform.Field
@SuppressWarnings('unused')
static String version() {return "1.0.2"}
metadata {
definition (
name: "Uptime Widget",
namespace: "thebearmay",
author: "Jean P. May, Jr.",
importUrl:"https://raw.githubusercontent.com/thebearmay/hubitat/main/upTimeWidget.groovy"
) {
capability "Actuator"
capability "Initialize"
attribute "html", "string"
}
}
preferences {
//input("upTimeDesc", "enum", title: "Uptime Descriptors", defaultValue:"d/h/m/s", options:["d/h/m/s"," days/ hrs/ min/ sec"," days/ hours/ minutes/ seconds"])
input("textColor","string",title: "Text Color", submitOnChange:true)
}
@SuppressWarnings('unused')
void installed() {
log.trace "Uptime Widget v${version()} installed()"
initialize()
}
void initialize() {
log.info "Uptime Widget v${version()} initialized"
state.hubStart = now()-(location.hub.uptime*1000)
uploadHubFile("upTimeWidget.html",genHtml(state.hubStart).getBytes("UTF-8"))
updateAttr('html',"")
}
void updated(){
if(debugEnable) log.debug "updated"
initialize()
}
void updateAttr(String aKey, aValue, String aUnit = ""){
aValue = aValue.toString()
if(aValue.contains("Your hub is starting up"))
return
sendEvent(name:aKey, value:aValue, unit:aUnit)
if(attrLogging) log.info "$aKey : $aValue$aUnit"
}
def genHtml(sTime){
//utD=upTimeDesc.split("/")
html="""
Initializing...
"""
return html
}