The SmartApp class handles all SmartApp lifecycle events and callbacks. It is instantiated and configured with handlers for appropriate and invoked in response to either web-server HTTP requests or 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
- deviceCommand
- deviceCommandHandler
- oauthHandler
- scheduledEventHandler
- subscribedDeviceEventHandler
- subscribedDeviceHealthEventHandler
- subscribedDeviceLifecycleEventHandler
- subscribedEventHandler
- subscribedHubHealthEventHandler
- subscribedModeEventHandler
- subscribedSceneLifecycleEventHandler
- subscribedSecurityArmStateEventHandler
server.post('/', (req, res) => {
smartapp.handleHttpCallback(req, res);
});