-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
zooz-zen71-700-switch.groovy
714 lines (557 loc) · 18.7 KB
/
zooz-zen71-700-switch.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
/*
* Zooz ZEN71 700 Switch VER. 1.0.1
*
* Changelog:
*
* 1.0.1 (02/07/2021)
* - Added patch workaround to presentation for supportedButtonValues support in Automations.
*
* 1.0 (12/31/2020)
* - Initial Release
*
*
* Copyright 2021 Zooz
*
* Licensed under 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.
*
*/
import groovy.json.JsonOutput
import groovy.transform.Field
@Field static Map commandClassVersions = [
0x20: 1, // Basic
0x25: 1, // Switch Binary
0x55: 1, // Transport Service
0x59: 1, // AssociationGrpInfo
0x5A: 1, // DeviceResetLocally
0x5B: 1, // CentralScene (3)
0x5E: 2, // ZwaveplusInfo
0x6C: 1, // Supervision
0x70: 1, // Configuration
0x7A: 2, // FirmwareUpdateMd
0x72: 2, // ManufacturerSpecific
0x73: 1, // Powerlevel
0x85: 2, // Association
0x86: 1, // Version (2)
0x87: 1, // Indicator
0x8E: 2, // Multi Channel Association
0x98: 1, // Security S0
0x9F: 1 // Security S2
]
@Field static Map assocGroups = [2:"associationGroupTwo"]
@Field static int assocMaxNodes = 5
@Field static BigDecimal assocMinFirmware = 1.03
@Field static Map autoOnOffOptions = [0:"Timer Disabled [DEFAULT]", 1:"1 Minute", 2:"2 Minutes", 3:"3 Minutes", 4:"4 Minutes", 5:"5 Minutes", 6:"6 Minutes", 7:"7 Minutes", 8:"8 Minutes", 9:"9 Minutes", 10:"10 Minutes", 15:"15 Minutes", 20:"20 Minutes", 25:"25 Minutes", 30:"30 Minutes", 45:"45 Minutes", 60:"1 Hour", 120:"2 Hours", 180:"3 Hours", 240:"4 Hours", 300:"5 Hours", 360:"6 Hours", 420:"7 Hours", 480:"8 Hours", 540:"9 Hours", 600:"10 Hours", 720:"12 Hours", 1080:"18 Hours", 1440:"1 Day", 2880:"2 Days", 4320:"3 Days", 5760:"4 Days", 7200:"5 Days", 8640:"6 Days", 10080:"1 Week", 20160:"2 Weeks", 30240:"3 Weeks", 40320:"4 Weeks", 50400:"5 Weeks", 60480:"6 Weeks"]
metadata {
definition (
name: "Zooz ZEN71 700 Switch",
namespace: "Zooz",
author: "Kevin LaFramboise (@krlaframboise)",
ocfDeviceType: "oic.d.switch",
mnmn: "SmartThingsCommunity",
vid: "2dd64fd2-480a-378b-8df2-bc59f865fa13"
) {
capability "Actuator"
capability "Sensor"
capability "Switch"
capability "Light"
capability "Configuration"
capability "Refresh"
capability "Health Check"
capability "Button"
capability "platemusic11009.firmware"
capability "platemusic11009.associationGroupTwo"
capability "platemusic11009.syncStatus"
attribute "lastCheckIn", "string"
fingerprint mfr:"027A", prod:"7000", model: "A001", deviceJoinName:"Zooz ZEN71 700 Switch"
command "ledIndicatorOn"
// command "ledIndicatorOff" // not supported by firmware, but should be...
}
simulator { }
preferences {
configParams.each { param ->
createEnumInput("configParam${param.num}", "${param.name}:", param.value, param.options)
}
createEnumInput("debugOutput", "Enable Debug Logging?", 1, [0:"No", 1:"Yes [DEFAULT]"])
input "assocInstructions", "paragraph",
title: "Device Associations (MINIMUM FIRMWARE ${assocMinFirmware})",
description: "Associations are an advance feature that allow you to establish direct communication between Z-Wave devices. To make this remote control another Z-Wave device, get that device's Device Network Id from the My Devices section of the IDE and enter the id in one of the settings below. The group(s) support up to ${assocMaxNodes} associations and you can use commas to separate the device network ids.",
required: false
input "assocInstructions2", "paragraph",
title: "Associations Require S2 Security",
description: "If the device fails to join with S2 Security you won't be able to use Associations. The 'networkSecurityLevel' field in the IDE will show 'ZWAVE_S2_FAILED' if it failed.",
required: false
input "assocDisclaimer", "paragraph",
title: "WARNING",
description: "If you add a device's Device Network ID to the list below and then remove that device from SmartThings, you MUST come back and remove it from the list below. Failing to do this will substantially increase the number of z-wave messages being sent by this device and could affect the stability of your z-wave mesh.",
required: false
assocGroups.each { group, name ->
input "group${group}AssocDNIs", "string",
title: "Enter Device Network IDs for Group ${group} Association:",
required: false
}
}
}
void createEnumInput(String name, String title, Integer defaultVal, Map options) {
input name, "enum",
title: title,
required: false,
defaultValue: defaultVal.toString(),
options: options
}
def installed() {
logDebug "installed()..."
initialize()
return []
}
def updated() {
if (!isDuplicateCommand(state.lastUpdated, 2000)) {
state.lastUpdated = new Date().time
logDebug "updated()..."
initialize()
runIn(2, executeConfigureCmds)
}
return []
}
void initialize() {
if (!device.currentValue("checkInterval")) {
def checkInterval = ((60 * 60 * 3) + (5 * 60))
sendEvent([name: "checkInterval", value: checkInterval, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"]])
}
state.debugLoggingEnabled = (safeToInt(settings?.debugOutput, 1) != 0)
if (!device.currentValue("supportedButtonValues")) {
sendEvent(name:"supportedButtonValues", value: ["down","down_hold","down_2x","down_3x","down_4x","down_5x","up","up_hold","up_2x","up_3x","up_4x","up_5x"].encodeAsJSON(), displayed:false)
}
if (!device.currentValue("numberOfButtons")) {
sendEvent(name:"numberOfButtons", value:1, displayed:false)
}
if (!device.currentValue("button")) {
sendButtonEvent("up")
}
assocGroups.each { group, name ->
if (device.currentValue(name) == null) {
sendEvent(name: name, value: "")
}
}
}
def configure() {
logDebug "configure()..."
runIn(60, executeConfigureCmds)
return []
}
void executeConfigureCmds() {
runIn(6, refreshSyncStatus)
List<String> cmds = []
if (!device.currentValue("switch")) {
cmds << switchBinaryGetCmd()
}
if (!device.currentValue("firmwareVersion")) {
cmds << versionGetCmd()
}
configParams.each { param ->
Integer storedVal = getParamStoredValue(param.num)
if (state.resyncAll || storedVal != param.value) {
if (state.resyncAll != null) {
logDebug "Changing ${param.name}(#${param.num}) from ${storedVal} to ${param.value}"
cmds << configSetCmd(param, param.value)
}
cmds << configGetCmd(param)
}
}
if (state.resyncAll != null) {
cmds += getConfigureAssocsCmds()
}
state.resyncAll = false
if (cmds) {
sendCommands(cmds)
}
}
private getConfigureAssocsCmds() {
List<String> cmds = []
assocGroups.each { group, name ->
boolean changes = false
def stateNodeIds = state["${name}NodeIds"]
def settingNodeIds = getAssocDNIsSettingNodeIds(group)
def newNodeIds = settingNodeIds?.findAll { !(it in stateNodeIds) }
if (newNodeIds) {
logDebug "Adding Nodes ${newNodeIds} to Association Group ${group}"
cmds << associationSetCmd(group, newNodeIds)
changes = true
}
def oldNodeIds = stateNodeIds?.findAll { !(it in settingNodeIds) }
if (oldNodeIds) {
logDebug "Removing Nodes ${oldNodeIds} from Association Group ${group}"
cmds << associationRemoveCmd(group, oldNodeIds)
changes = true
}
if (changes || state.resyncAll) {
cmds << associationGetCmd(group)
}
}
if (cmds) {
if (device.currentValue("firmwareVersion") < assocMinFirmware) {
log.warn "Firmware must be ${assocMinFirmware} or above to use Associations"
cmds = []
}
else if (device.getDataValue("networkSecurityLevel") == "ZWAVE_S2_FAILED") {
log.warn "Associations can't be used when S2 Security Failed"
cmds = []
}
}
return cmds
}
List<Integer> getAssocDNIsSettingNodeIds(int group) {
String assocSetting = settings["group${group}AssocDNIs"] ?: ""
List<Integer> nodeIds = convertHexListToIntList(assocSetting?.split(","))
if (assocSetting && !nodeIds) {
log.warn "'${assocSetting}' is not a valid value for the 'Device Network Ids for Association Group ${group}' setting. All z-wave devices have a 2 character Device Network Id and if you're entering more than 1, use commas to separate them."
}
else if (nodeIds?.size() > assocMaxNodes) {
log.warn "The 'Device Network Ids for Association Group ${group}' setting contains more than ${assocMaxNodes} Ids so only the first ${assocMaxNodes} will be associated."
}
return nodeIds
}
def ping() {
logDebug "ping()..."
return [ switchBinaryGetCmd() ]
}
def ledIndicatorOn() {
logDebug "ledIndicatorOn()..."
return delayBetween([
indicatorSetCmd(0xFF),
indicatorGetCmd()
], 200)
}
def ledIndicatorOff() {
logDebug "ledIndicatorOff()..."
return delayBetween([
indicatorSetCmd(0x00),
indicatorGetCmd()
], 200)
}
def on() {
logDebug "on()..."
return delayBetween([
switchBinarySetCmd(0xFF),
switchBinaryGetCmd()
], 200)
}
def off() {
logDebug "off()..."
return delayBetween([
switchBinarySetCmd(0x00),
switchBinaryGetCmd()
], 200)
}
def refresh() {
logDebug "refresh()..."
refreshSyncStatus()
sendCommands([
switchBinaryGetCmd(),
versionGetCmd()
])
if (isDuplicateCommand(state.lastRefresh, 2000)) {
state.resyncAll = true
runIn(3, executeConfigureCmds)
}
state.lastRefresh = new Date().time
return []
}
void sendCommands(List<String> cmds, Integer delay=500) {
if (cmds) {
def actions = []
cmds.each {
actions << new physicalgraph.device.HubAction(it)
}
sendHubCommand(actions, delay)
}
}
String associationSetCmd(int group, nodes) {
return secureCmd(zwave.associationV2.associationSet(groupingIdentifier: group, nodeId: nodes))
}
String associationRemoveCmd(int group, nodes) {
return secureCmd(zwave.associationV2.associationRemove(groupingIdentifier: group, nodeId: nodes))
}
String associationGetCmd(int group) {
return secureCmd(zwave.associationV2.associationGet(groupingIdentifier: group))
}
String versionGetCmd() {
return secureCmd(zwave.versionV1.versionGet())
}
String switchBinaryGetCmd() {
return secureCmd(zwave.switchBinaryV1.switchBinaryGet())
}
String switchBinarySetCmd(val) {
return secureCmd(zwave.switchBinaryV1.switchBinarySet(switchValue: val))
}
String indicatorGetCmd() {
return secureCmd(zwave.indicatorV1.indicatorGet())
}
String indicatorSetCmd(int value) {
return secureCmd(zwave.indicatorV1.indicatorSet(value: value))
}
String configSetCmd(Map param, int value) {
return secureCmd(zwave.configurationV1.configurationSet(parameterNumber: param.num, size: param.size, scaledConfigurationValue: value))
}
String configGetCmd(Map param) {
return secureCmd(zwave.configurationV1.configurationGet(parameterNumber: param.num))
}
String secureCmd(cmd) {
try {
if (zwaveInfo?.zw?.contains("s") || ("0x98" in device?.rawDescription?.split(" "))) {
return zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
}
else {
return cmd.format()
}
}
catch (ex) {
return cmd.format()
}
}
def parse(String description) {
def cmd = zwave.parse(description, commandClassVersions)
if (cmd) {
zwaveEvent(cmd)
}
else {
log.warn "Unable to parse: $description"
}
updateLastCheckIn()
return []
}
void updateLastCheckIn() {
if (!isDuplicateCommand(state.lastCheckInTime, 60000)) {
state.lastCheckInTime = new Date().time
sendEvent(name: "lastCheckIn", value: convertToLocalTimeString(new Date()), displayed: false)
}
}
String convertToLocalTimeString(dt) {
try {
def timeZoneId = location?.timeZone?.ID
if (timeZoneId) {
return dt.format("MM/dd/yyyy hh:mm:ss a", TimeZone.getTimeZone(timeZoneId))
}
else {
return "$dt"
}
}
catch (ex) {
return "$dt"
}
}
void zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCmd = cmd.encapsulatedCommand(commandClassVersions)
if (encapsulatedCmd) {
zwaveEvent(encapsulatedCmd)
}
else {
log.warn "Unable to extract encapsulated cmd from $cmd"
}
}
void zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
logTrace "${cmd}"
runIn(4, refreshSyncStatus)
Map param = configParams.find { it.num == cmd.parameterNumber }
if (param) {
Integer val = cmd.scaledConfigurationValue
logDebug "${param.name}(#${param.num}) = ${val}"
setParamStoredValue(param.num, val)
}
else {
logDebug "Parameter #${cmd.parameterNumber} = ${cmd.scaledConfigurationValue}"
}
}
void zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationReport cmd) {
logTrace "${cmd}"
runIn(3, refreshSyncStatus)
logDebug "Group ${cmd.groupingIdentifier} Association: ${cmd.nodeId}"
String name = assocGroups.get(safeToInt(cmd.groupingIdentifier))
if (name) {
state["${name}NodeIds"] = cmd.nodeId
def dnis = convertIntListToHexList(cmd.nodeId)?.join(", ") ?: ""
if (dnis) {
dnis = "[${dnis}]" // wrapping it with brackets prevents ST from attempting to convert the value into a date.
}
sendEventIfNew(name, dnis, false)
}
}
void zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) {
String subVersion = String.format("%02d", cmd.applicationSubVersion)
String fullVersion = "${cmd.applicationVersion}.${subVersion}"
logDebug "Firmware Version: ${fullVersion}"
sendEventIfNew("firmwareVersion", fullVersion.toBigDecimal())
}
void zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
logTrace "${cmd}"
sendSwitchEvents(cmd.value)
}
void zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
logTrace "${cmd}"
sendSwitchEvents(cmd.value)
}
void sendSwitchEvents(rawVal) {
sendEventIfNew("switch", (rawVal ? "on" : "off"))
}
void zwaveEvent(physicalgraph.zwave.commands.indicatorv1.IndicatorReport cmd) {
logTrace "${cmd}"
}
void zwaveEvent(physicalgraph.zwave.commands.centralscenev1.CentralSceneNotification cmd){
if (state.lastSequenceNumber != cmd.sequenceNumber) {
state.lastSequenceNumber = cmd.sequenceNumber
logTrace "${cmd}"
String paddle = (cmd.sceneNumber == 1) ? "up" : "down"
String btnVal
switch (cmd.keyAttributes){
case 0:
btnVal = paddle
break
case 1:
logDebug "${paddle}_released is not supported by SmartThings"
btnVal = paddle + "_released"
break
case 2:
btnVal = paddle + "_hold"
break
default:
btnVal = paddle + "_${cmd.keyAttributes - 1}x"
}
sendButtonEvent(btnVal)
}
}
void sendButtonEvent(String value) {
String desc = "paddle ${value}"
logDebug(desc)
sendEvent(name: "button", value: value, data:[buttonNumber: 1], isStateChange: true, descriptionText: "${device.displayName} ${desc}")
}
void zwaveEvent(physicalgraph.zwave.Command cmd) {
logDebug "Unhandled zwaveEvent: $cmd"
}
void refreshSyncStatus() {
int changes = pendingChanges
sendEventIfNew("syncStatus", (changes ? "${changes} Pending Changes" : "Synced"), false)
}
int getPendingChanges() {
int configChanges = safeToInt(configParams.count { it.value != getParamStoredValue(it.num) })
int pendingAssocs = (getConfigureAssocsCmds()?.size() ? 1 : 0)
return (configChanges + pendingAssocs)
}
Integer getParamStoredValue(Integer paramNum) {
return safeToInt(state["configVal${paramNum}"] , null)
}
void setParamStoredValue(Integer paramNum, Integer value) {
state["configVal${paramNum}"] = value
}
List<Map> getConfigParams() {
return [
paddleOrientationParam,
ledIndicatorParam,
ledColorParam,
ledBrightnessParam,
autoOffParam,
autoOnParam,
powerFailureRecoveryParam,
threeWaySwitchTypeParam,
relayControlParam,
disabledRelayBehaviorParam,
sceneControlParam
]
}
Map getPaddleOrientationParam() {
return getParam(1, "Paddle Orientation", 1, 0, [0:"Up for On, Down for Off [DEFAULT]", 1:"Up for Off, Down for On", 2:"Up or Down for On/Off"])
}
Map getLedIndicatorParam() {
return getParam(2, "LED Indicator", 1, 0, [0:"LED On When Switch Off [DEFAULT]", 1:"LED On When Switch On", 2:"LED Always Off", 3:"LED Always On"])
}
Map getAutoOffParam() {
return getParam(3, "Auto Turn-Off Timer", 4, 0, autoOnOffOptions)
}
Map getAutoOnParam() {
return getParam(5, "Auto Turn-On Timer", 4, 0, autoOnOffOptions)
}
Map getPowerFailureRecoveryParam() {
return getParam(8, "Behavior After Power Outage", 1, 2, [0:"Forced to Off", 1:"Forced to On", 2:"Restores Last Status [DEFAULT]"])
}
Map getSceneControlParam() {
return getParam(9, "Scene Control", 1, 0, [0:"Disabled [DEFAULT]", 1:"Enabled"])
}
Map getRelayControlParam() {
return getParam(11, "Relay Control", 1, 1, [1:"Enable paddle and Z-Wave [DEFAULT]", 0:"Disable Paddle", 2:"Disable Paddle and Z-Wave"])
}
Map getThreeWaySwitchTypeParam() {
return getParam(12, "3-Way Switch Type", 1, 0, [0:"Toggle On/Off Switch [DEFAULT]", 1:"Momentary Switch (ZAC99)"])
}
Map getDisabledRelayBehaviorParam() {
return getParam(13, "Disabled Relay Behavior", 1, 0, [0: "Reports Status / Changes LED [DEFAULT]", 1: "Doesn't Report Status / Change LED"])
}
Map getLedColorParam() {
return getParam(14, "LED Indicator Color", 1, 1, [0:"White", 1:"Blue [DEFAULT]", 2:"Green", 3:"Red"])
}
Map getLedBrightnessParam() {
return getParam(15, "LED Indicator Brightness", 1, 1, [0:"Bright (100%)", 1:"Medium (60%) [DEFAULT]", 2:"Low (30%)"])
}
Map getParam(Integer num, String name, Integer size, Integer defaultVal, Map options) {
Integer val = safeToInt((settings ? settings["configParam${num}"] : null), defaultVal)
return [num: num, name: name, size: size, value: val, options: options]
}
void sendEventIfNew(String name, value, boolean displayed=true) {
String desc = "${name} is ${value}"
if (device.currentValue(name) != value) {
if (name != "syncStatus") {
logDebug(desc)
}
sendEvent(name: name, value: value, descriptionText: "${device.displayName} ${desc}", displayed: displayed)
}
else {
logTrace(desc)
}
}
List<String> convertIntListToHexList(List<Integer> intList) {
List<String> hexList = []
intList?.each {
hexList.add(Integer.toHexString(it).padLeft(2, "0").toUpperCase())
}
return hexList
}
List<Integer> convertHexListToIntList(String[] hexList) {
List<Integer> intList = []
hexList?.each {
try {
it = it.trim()
intList.add(Integer.parseInt(it, 16))
}
catch (e) { }
}
return intList
}
Integer safeToInt(val, Integer defaultVal=0) {
if ("${val}"?.isInteger()) {
return "${val}".toInteger()
}
else if ("${val}".isDouble()) {
return "${val}".toDouble()?.round()
}
else {
return defaultVal
}
}
boolean isDuplicateCommand(lastExecuted, allowedMil) {
!lastExecuted ? false : (lastExecuted + allowedMil > new Date().time)
}
void logDebug(String msg) {
if (state.debugLoggingEnabled != false) {
log.debug "$msg"
}
}
void logTrace(String msg) {
// log.trace "$msg"
}