-
Notifications
You must be signed in to change notification settings - Fork 1
/
debugHarness.groovy
executable file
·173 lines (152 loc) · 4.92 KB
/
debugHarness.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* helper methods */
/* _logger
* This is a debug logging function
*
* Example out put
* <example here>
* Parameters:
* methodName - The name of the method that is calling the _logger
* lineMarker - Due to the smartthings limition to get the current line number it is intended to be a unique location identifyer
* text - this is the text to be displayed
* Returns:
* None
* Comments:
* The SmartThings execution envirmount has some limitions these are mainly due to security concerns understandability. One side effect
* if that most introspection abilities are out of scope for use and tend to return jave security exceptions. The example code below would
* return a valid line number without these limitions.
*
* --- Logging Utils ---
* def getCurrentMethodName(){
* def marker = new Throwable()
* return StackTraceUtils.sanitize(marker).stackTrace[1].methodName
* }
* public static int getLineNumber() {
* return Thread.currentThread().getStackTrace()[2].getLineNumber();
* }
*/
def _logger(methodName, lineMarker, text)
{
def line = "${methodName}:${lineMarker} - ${text}"
println line
}
def makeValue(value)
{
return ["value":value]
}
def getStates(state,dev,rollUps)
{
def states = [:]
def value
def total = 0
def stateIdx
def unAccountedTotal = 0
def childTotal = 0
def x = 0
def finished = false
while (finished == false)
{
switch(x)
{
case 0 :
stateIdx = state
/*_logger("getStates","A.20","else(${x}) state->${state} - dev.${state}.value")*/
break
default:
stateIdx = "${state}${x}"
/*_logger("getStates","A.25","(${x}>0) state->${state} - dev.${state}.value")*/
break
}
_logger("getStates", "A.27", "passed case")
if (dev.currentState("${stateIdx}")!=null)
{
_logger("getStates", "A.28", "In if")
_logger("getStates", "A.28", "dev->${dev}")
value = dev.currentState("${stateIdx}")
_logger("getStates","A.30","stateIdx->${stateIdx}, value -> ${value}")
states[stateIdx] = value
if (x>0 && value!=null)
{
_logger("getStates","A.32", "(${stateIdx}) - value + childTotal(${childTotal} + ${value})")
childTotal = childTotal + value
}
x = x + 1
}
else
{
_logger("getStates","A.40","Value is null")
finished = true
}
_logger("getStates", "A.45", "x->${x}")
}
if(rollUps)
{
_logger("getStates","A.50","total->${total}")
_logger("getStates","A.52", "childTotal->${childTotal}")
states["total"] = total
states["unAccountedTotal"] = total - childTotal
states["childTotal"] = childTotal
}
_logger("getStates", "A.50","states->${states}")
return states
}
/* SmartThings simulation classes
*
* Class Device - This simulates an SmartThings SmartApp Device
*
*/
class device
{
def name = ""
def label = ""
def id = ""
def states = []
public def device(name, label, id, states)
{
this.name = name
this.label = label
this.states = states
}
def addState(stateName, state)
{
this.states[stateName] = state
}
def currentState(stateIdx)
{
_logger("class device - currentState ", "A.10", "this.states[" + "${stateIdx}" +"] -> ${this.states[stateIdx]}")
def value = this.states[stateIdx].value
_logger("class device - returning ", "A.20", "${value}")
return value
}
def _logger(methodName, lineMarker, text)
{
def line = "${methodName}:${lineMarker} - ${text}"
println line
}
}
def getStatesDebug()
{
_logger("getStatesDebug", "A.10", "Start of debug Session")
/* Data setup */
def id = "abe801ad-b07e-4bcc-9b8c-b26bae2cb099"
def name = "Aeon SmartStrip"
def label ="Aeon Ss 01"
def states = [energyState:[value:236.32],
energyState1:[value:51.31],
energyState2:[value:17.49],
energyState3:[value:27.7],
energyState4:[value:53.23],
powerState:[value:256],
powerState1:[value:119],
powerState2:[value:17],
powerState3:[value:40],
powerState4:[value:82],
switchState:[value:"on"],
switchState1:[value:"on"],
switchState2:[value:"on"],
switchState3:["value":"on"],
switchState4:[value:"on"]
]
def dev = new device(name, label, id, states)
println "${getStates("energyState",dev,true)}"
}
getStatesDebug()