Skip to content

Instantly share code, notes, and snippets.

@nayelyzarazua-bluetrail
Created July 7, 2021 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nayelyzarazua-bluetrail/a32fcf9c5a58613a4106443d4f99d5fe to your computer and use it in GitHub Desktop.
Save nayelyzarazua-bluetrail/a32fcf9c5a58613a4106443d4f99d5fe to your computer and use it in GitHub Desktop.
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