Created
July 7, 2021 16:41
-
-
Save nayelyzarazua-bluetrail/a32fcf9c5a58613a4106443d4f99d5fe to your computer and use it in GitHub Desktop.
Hub_Health_SmartApp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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