Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hub_Health_SmartApp
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const SmartApp = require('@smartthings/smartapp');
require('dotenv').config();
const server = module.exports = express();
server.use(bodyParser.json());
const app = new SmartApp()
/* Handles lifecycle events from SmartThings */
server.post('/', async (req, res) => {
app.handleHttpCallback(req, res);
});
/* Defines the SmartApp */
app.enableEventLogging(2) // Log and pretty-print all lifecycle events and responses
.configureI18n() // Use files from locales directory for configuration page localization
.appId("hub-subscription")
.permissions(["r:devices:*","r:hubs:*","r:locations:*"])
.page('mainPage', (context, page, configData) => {
})
.updated(async (context, updateData) => {
await context.api.subscriptions.unsubscribeAll();
return Promise.all([
context.api.subscriptions.subscribeToHubHealth('hubEventHandler')
])
})
.subscribedHubHealthEventHandler('hubEventHandler', (context, deviceEvent) => {
console.log('hub event ',deviceEvent)
});
/* Starts the server */
let port = process.env.PORT;
server.listen(port);
console.log(`Open: http://127.0.0.1:${port}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment