-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSmartApp.js
41 lines (34 loc) · 1.17 KB
/
SmartApp.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
const SmartApp = require('@smartthings/smartapp')
async function setVolume(ctx) {
const volume = await ctx.configNumberValue('audioVolume')
await ctx.api.devices.sendCommands(ctx.config.monitor, [
{
capability: 'audioVolume',
command: 'setVolume',
arguments: [volume],
},
])
}
/* Defines the SmartApp */
module.exports = new SmartApp()
.enableEventLogging() // Log and pretty-print all lifecycle events and responses
.configureI18n() // Use files from locales directory for configuration page localization
.page('mainPage', (context, page, configData) => {
page.section('control', (section) => {
section.enumSetting('numSelect').options({ on: 'on', off: 'off' })
section.numberSetting('audioVolume')
})
page.section('Samsung M5 (27)', (section) => {
section
.deviceSetting('monitor')
.capabilities(['switch', 'audioVolume'])
.permissions('rx')
.required(true)
})
})
.updated(async (ctx) => {
const power = await ctx.configStringValue('numSelect')
await ctx.api.schedules.delete()
await setVolume(ctx)
ctx.api.devices.sendCommands(ctx.config.monitor, 'switch', power)
})