/* * Event / State Display * * 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 * ---- --- ---- * 2021-08-31 thebearmay Original version 0.1.0 */ import java.text.SimpleDateFormat import groovy.transform.Field static String version() { return '0.1.0' } @Field attrList = [] definition ( name: "Event-State Display", namespace: "thebearmay", author: "Jean P. May, Jr.", description: "Display all events or states for a given attribute", category: "Utility", importUrl: "https://raw.githubusercontent.com/thebearmay/hubitat/main/apps/eventStateDisplay.groovy", oauth: false, iconUrl: "", iconX2Url: "" ) preferences { page name: "mainPage" page name: "showItems" } def installed() { // log.trace "installed()" state?.isInstalled = true initialize() } def updated(){ // log.trace "updated()" if(!state?.isInstalled) { state?.isInstalled = true } if(debugEnable) runIn(1800,logsOff) } def initialize(){ } void logsOff(){ app.updateSetting("debugEnable",[value:"false",type:"bool"]) } def mainPage(){ dynamicPage (name: "mainPage", title: "", install: true, uninstall: true) { if (app.getInstallationState() == 'COMPLETE') { section("Main") { input "qryDevice", "capability.*", title: "Devices of Interest:", multiple: false, required: true, submitOnChange: true if(qryDevice!=null) buildAttrList() input "attrSelected", "enum", title: "Attribute to pull events/states for:", required: true, options: attrList if (qryDevice != null && attrSelected != null) href "showItems", title: "Event/State Information", required: false } } else { section("") { paragraph title: "Click Done", "Please click Done to install app before continuing" } } } } def showItems(){ dynamicPage (name: "showItems", title: "", install: false, uninstall: false) { section(""){ dispTable = "
" evtList = {} dName = qryDevice.displayName dispTable+="" dispTable+="" evtList=qryDevice.statesSince(attrSelected.toString(),Date.parse("yyyy-MM-dd hh:mm", "1970-01-01 00:00:00"), [max:1000000]) if(dwnldState) statePipe="$dName State Changes|Attribute:$attrSelected|[crlf]" evtList.each { dispTable += "" if(dwnldState) statePipe+="$it.date|$it.value|[crlf]" } dispTable += "
$dName State ChangesAttribute:$attrSelected
Date-TimeValue
${it.date}${it.value}
" dispTable2="" dispTable2+="" evtList=qryDevice.eventsSince(Date.parse("yyyy-MM-dd hh:mm", "1970-01-01 00:00:00"), [max:10000000]) if(dwnldEvent) eventPipe="$dName Events|Attribute:$attrSelected||[crlf]" evtList.each { if(it.properties.name == attrSelected){ if(it.properties.type == null || it.properties.type == "null") itType = "NA" else itType = it.properties.type dispTable2 += "" if(dwnldEvent) eventPipe+="$it.properties.date|$it.properties.value|$itType|[crlf]" } } dispTable2 += "
$dName EventsAttribute:$attrSelected
Date-TimeValueType
$it.properties.date$it.properties.value$itType
" section ("States", hideable: true, hidden: false) { paragraph "$dispTable" input "dwnldState", "bool", title:"Download State Data", submitOnChange:true if(dwnldState) paragraph downloadFile("state.txt",statePipe) } section ("Events", hideable: true, hidden: true) { paragraph "$dispTable2" input "dwnldEvent", "bool", title:"Download Event Data", submitOnChange:true if(dwnldEvent) paragraph downloadFile("event.txt",eventPipe) } } } } def buildAttrList(){ qryDevice.supportedAttributes.each{ attrList.add(it.toString()) } } String downloadFile(fName="download.txt",fContent="no content supplied"){ // Display the resultant string in a paragraph to execute fileContent = fContent.replace('"','\"') String jsStr = "" return jsStr } def appButtonHandler(btn) { switch(btn) { default: log.error "Undefined button $btn pushed" break } } def intialize() { }