-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBathroomLightController.txt[IoTBench@IoTBench-test-suite].js
79 lines (45 loc) · 2.07 KB
/
BathroomLightController.txt[IoTBench@IoTBench-test-suite].js
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
const { SmartApp } = require('@smartthings/smartapp')
module.exports = new SmartApp()
.enableEventLogging(2)
.configureI18n()
.page('mainPage', (context, page, configData) => {
page.section('When these doors are both closed, or at least one is open...', section => {
section.deviceSetting('contact1').capability(['contactSensor']).name('');
section.deviceSetting('contact2').capability(['contactSensor']).name('');
});
page.section('Turn on/off a light...', section => {
section.deviceSetting('switch1').capability(['switch']).name('');
});
})
.updated(async (context, updateData) => {
await context.api.subscriptions.subscribeToDevices(context.config.contact2, 'contactSensor', 'contact', 'contactHandler2')
await context.api.subscriptions.subscribeToDevices(context.config.switch1, 'switch', 'switch', 'timeoutHandler')
await context.api.subscriptions.subscribeToDevices(context.config.contact1, 'contactSensor', 'contact', 'contactHandler1')
})
.subscribedEventHandler('timeoutHandler', (context, event) => {
this.runIn(60 * 10, switchHandler)
})
.subscribedEventHandler('contactHandler2', (context, event) => {
console.log("${event.value}")
if (event.value == 'open') {
context.api.devices.sendCommands(context.config.switch1, 'switch', off)
} else {
if (event.value == 'closed') {
if
context.api.devices.sendCommands(context.config.switch1, 'switch', on)
}
}
}
})
.subscribedEventHandler('contactHandler1', (context, event) => {
console.log("${event.value}")
if (event.value == 'open') {
context.api.devices.sendCommands(context.config.switch1, 'switch', off)
} else {
if (event.value == 'closed') {
if
context.api.devices.sendCommands(context.config.switch1, 'switch', on)
}
}
}
})