forked from SANdood/smartthings-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpollsterAppWithRefresh.groovy
128 lines (116 loc) · 3.91 KB
/
pollsterAppWithRefresh.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
/**
* Pollster - The SmartThings Polling Daemon.
*
* Many SmartThings devices rely on polling to update their status
* periodically. Pollster works behind the scenes and calls poll()
* function for selected devices so you don't have to rely on SmartThings
* built-in polling engine. Devices can be arranged in four groups with
* configurable polling intervals. The polling interval can be as short as
* one minute.
*
* Copyright (c) 2014 Statusbits.com
*
* 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.
*
*
* Revision History
* ----------------
*
* 2014-08-23: Version: 1.1.0
* Allow 4 device groups with different polling interval.
*
* 2014-07-14: Version: 1.0.0
* Published to SmartThings shared apps directory.
*
* 2014-11-11: Version: 1.0.1 (Mike Maxwell)
* Added ability to select devices that support the refresh method.
*
*/
definition(
name: "PollsterWithRefresh",
namespace: "statusbits",
author: "[email protected]",
description: "Calls poll() function periodically for selected devices.",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]")
preferences {
section("About") {
paragraph "Pollster is a polling daemon that calls poll() function " +
"periodically for selected devices. You can arrange your devices " +
"into four polling groups with different polling intervals."
paragraph "Version 1.1.0.\nCopyright (c) 2014 Statusbits.com"
}
for (int n = 1; n <= 4; n++) {
section("Polling Group ${n}") {
input "group_${n}", "capability.polling", title:"Select devices to be polled", multiple:true, required:false
input "groupRefresh_${n}", "capability.refresh", title:"Select devices to be refreshed", multiple:true, required:false
input "interval_${n}", "number", title:"Set interval (in minutes)", defaultValue:5
}
}
}
def installed() {
initialize()
}
def updated() {
unschedule()
initialize()
}
def pollingTask1() {
TRACE("pollingTask1()")
settings.group_1*.poll()
settings.groupRefresh_1*.refresh()
}
def pollingTask2() {
TRACE("pollingTask2()")
settings.group_2*.poll()
settings.groupRefresh_2*.refresh()
}
def pollingTask3() {
TRACE("pollingTask3()")
settings.group_3*.poll()
settings.groupRefresh_3*.refresh()
}
def pollingTask4() {
TRACE("pollingTask4()")
settings.group_4*.poll()
settings.groupRefresh_4*.refresh()
}
private def initialize() {
TRACE("initialize() with settings: ${settings}")
for (int n = 1; n <= 4; n++) {
def minutes = settings."interval_${n}".toInteger()
def group = settings."group_${n}"
if (minutes > 0 && group?.size()) {
TRACE("Scheduling polling task ${n} to run every ${minutes} minutes.")
def sched = "0 0/${minutes} * * * ?"
switch (n) {
case 1:
schedule(sched, pollingTask1)
break;
case 2:
schedule(sched, pollingTask2)
break;
case 3:
schedule(sched, pollingTask3)
break;
case 4:
schedule(sched, pollingTask4)
break;
}
}
}
}
private def TRACE(message) {
//log.debug message
}