forked from alexking/StatusThing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.groovy
102 lines (80 loc) · 2.2 KB
/
app.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
/**
* StatusThing
*
* Author: [email protected]
* Date: 2013-11-01
*
* Download the Mac App at https://github.com/alexking/StatusThing
*
*/
preferences {
section("Settings") {
input "switches", "capability.switch", title : "Switches", multiple : true, required : true
input "temperatures", "capability.temperatureMeasurement", title : "Temperature", multiple : true, required : false
input "thermostats", "capability.thermostat", title : "Thermostats", multiple : true, required : false
}
}
mappings
{
path("/updateItemsAndTemperature")
{
action :
[
GET : "updateItemsAndTemperatures"
]
}
path("/itemChangeToState/:id/:state")
{
action :
[
GET : "itemChangeToState"
]
}
}
def updateItemsAndTemperatures()
{
def items = []
for (item in switches)
{
items << [ 'id' : item.id , 'state' : item.currentValue('switch') ?: '' , 'name' : item.displayName ]
}
def temperatureItems = []
if (temperatures)
{
for (temperature in temperatures)
{
def temperatureState = temperature.currentState('temperature')
temperatureItems << [ 'id' : temperature.id, 'name' : temperature.displayName, 'value' : temperature.currentValue("temperature"), 'unit' : temperatureState.unit]
}
}
if (thermostats)
{
for (temperature in thermostats)
{
def temperatureState = temperature.currentState('temperature')
temperatureItems << [ 'id' : temperature.id, 'name' : temperature.displayName, 'value' : temperature.currentValue("temperature"), 'unit' : temperatureState.unit]
}
}
[ 'temperatures' : temperatureItems , 'items' : items ]
}
def itemChangeToState()
{
def item = switches.find { it.id == params.id }
if (params.state == "on")
{
item.on();
} else {
item.off();
}
def data = updateItemsAndTemperatures()
for(dataItem in data['items'])
{
if (dataItem.id == params.id)
{
dataItem.state = params.state;
}
}
data
}
def installed() { }
def updated() { }