The SmartApp class handles all SmartApp lifecycle events and callbacks. It is instantiated and configured with handlers where appropriate and is invoked in response to either web server HTTP requests, or in response to AWS Lambda function calls.
const smartapp = new SmartApp()
.enableEventLogging(2)
.configureI18n()
....
.page('mainPage', (context, page, configData) => {
page.section('sensors', section => {
section.deviceSetting('contactSensor')
.capabilities(['contactSensor'])
.required(false);
})
})
.updated(async (context, updateData) => {
await context.api.subscriptions.unsubscribeAll()
await context.api.subscriptions.subscribeToDevices(
context.config.contactSensor, 'contactSensor', 'contact', 'deviceEventHandler');
})
.subscribedEventHandler('myDeviceEventHandler', (context, event) => {
const value = event.value === 'open' ? 'on' : 'off';
context.api.devices.sendCommands(context.config.lights, 'switch', value);
})
- defaultDeviceCommandHandler
- defaultScheduledEventHandler
- deviceCommand
- deviceCommandHandler
- oauthHandler
- scheduledEventHandler
- subscribedDeviceEventHandler
- subscribedDeviceHealthEventHandler
- subscribedDeviceLifecycleEventHandler
- subscribedEventHandler
- subscribedHubHealthEventHandler
- subscribedModeEventHandler
- subscribedSceneLifecycleEventHandler
- subscribedSecurityArmStateEventHandler
server.post('/', (req, res) => {
smartapp.handleHttpCallback(req, res);
});