/* * * * 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, WIyTHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License * for the specific language governing permissions and limitations under the License. * * Date Who Description * ------------- ------------------- --------------------------------------------------------- * 05Jan2025 thebearmay capture privateF and actRuleMain */ import groovy.transform.Field import groovy.json.JsonSlurper static String version() { return '0.0.11' } definition ( name: "Rule References Rule Table", namespace: "thebearmay", author: "Jean P. May, Jr.", description: "Simple Table Display for Rules referencing other Rules", category: "Utility", importUrl: "https://raw.githubusercontent.com/thebearmay/hubitat/main/apps/ruleRruleList.groovy", installOnOpen: true, oauth: false, iconUrl: "", iconX2Url: "" ) preferences { page name: "mainPage" } 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("debugEnabled",[value:"false",type:"bool"]) } def mainPage(){ dynamicPage (name: "mainPage", title: "", install: true, uninstall: true) { section("

Settings

", hideable:true, hidden: true){ input "debugEnabled", "bool", title: "Enable Debug Logging", defaultValue: false, submitOnChange:true input "nameOverride", "text", title: "New Name for Application", multiple: false, required: false, submitOnChange: true, defaultValue: app.getLabel() if(nameOverride != app.getLabel()) app.updateLabel(nameOverride) } section("") { if(debugEnabled) runIn(1800,logsOff) if(minVerCheck("2.4.0.0")) { input "getRules", "button", title: "Create Tables" if(state.getRules){ state.getRules = false childApps = getRuleList() rule2Runner=[] oTable = "$tableStyle"//" childApps.each { ca -> jData=readJsonPage("http://127.0.0.1:8080/installedapp/statusJson/${ca.key}") aSHold=[] oTable += "' } oTable += '
Rule Affects
Rule Name(id)Rules Affected(id)
Related Rules
${ca.value}(${ca.key})" jData.appSettings.each { aS -> if(aS.name.toString().contains('ruleAct') || aS.name.toString().contains('pauseRule.') || aS.name.toString().contains('valFunction.') || aS.name.toString().contains('privateT') || aS.name.toString().contains('privateF') || aS.name.toString().contains('stopAct')){ vSplit = aS.value.toString().replace('\"','').replace('[','').replace(']','').split(',') //log.debug "${aS.value} ${vSplit}" vSplit.each{ if(ca.key != it) aSHold.add("\"$it\"") } } } if(debugEnabled) log.debug "$aSHold" i=0 aSHold.sort().unique().each { sInx = it.toString().indexOf('\"')+1 eInx = it.toString().indexOf('\"',sInx) aKey=it.toString().substring(sInx,eInx) if(aKey != 'null' && aKey != ca.key ){ if(i>0) oTable += ",
" i++ aName=getName(aKey,childApps) oTable+= "${aName}(${aKey})" rule2Runner.add([key:"$aKey", value:"${ca.key}", name:"$aName"]) } } oTable += '
' paragraph oTable r2r = rule2Runner.sort{it.name+it.key}.unique() oTable = "$tableStyle" lastKey = 0 holdR=[] r2r.each { r -> if(lastKey != r.key && r.key !='null' ){ i=0 holdR.sort().each{ if(i>0) oTable+= ',
' oTable+="${getName(it,childApps)}(${it})" i++ } if(i>0){ oTable+='' } oTable+="
In Use
Rule Name(id)In Use By(id)
${r.name}(${r.key})" holdR=[] holdR.add(r.value) lastKey = r.key } else if(r.key != 'null'){ holdR.add(r.value) } } i=0 holdR.sort().each{ if(i>0) oTable+= ', ' oTable+="${getName(it,childApps)}(${it})" i++ } oTable+='
' paragraph oTable } } else paragraph "Must be on HE v2.4.0.0 or Higher" } } } String getName(keyVal, appList){ rVal = '' appList.each{ if(debugEnabled) log.debug "$keyVal ${it.key}" if(it.key == keyVal) rVal = it.value } return rVal } ArrayList getRuleList() { Map requestParams = [ uri: "http://127.0.0.1:8080", path:"/hub2/appsList" ] httpGet(requestParams) { resp -> wrkList = [] resp.data.apps.each{ if(it.data.type.contains("Rule")){ it.children.each{ if(it.data.disabled) wrkMap =[key:"${it.data.id}",value:"${it.data.name}"] else wrkMap =[key:"${it.data.id}",value:"${it.data.name}"] wrkList.add(wrkMap) } } } return wrkList } } def readJsonPage(fName){ def params = [ uri: fName, contentType: "application/json", //textParser: false, headers: [ "Connection-Timeout":600 ] ] try { httpGet(params) { resp -> if(resp!= null) { return resp.data } else { log.error "Read External - Null Response" return null } } } catch (exception) { log.error "Read JFile Error: ${exception.message}" return null } } Boolean minVerCheck(vStr){ //check if HE is >= to the requirement fwTokens = location.hub.firmwareVersionString.split("\\.") vTokens = vStr.split("\\.") if(fwTokens.size() != vTokens.size()) return false rValue = true for(i=0;i fwTokens[i].toInteger()) rValue=false } return rValue } def appButtonHandler(btn) { switch(btn) { case "getRules": state.getRules = true break default: log.error "Undefined button $btn pushed" break } } @Field static String tableStyle = ""