Created
March 2, 2021 21:28
-
-
Save nayelyzarazua-bluetrail/995befb1f36d3bf332feda027a598d3c to your computer and use it in GitHub Desktop.
SmartApp_DynamicInputsDelete
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() | |
const numofElements = ["input1","input2","input3"] | |
/* Handles lifecycle events from SmartThings */ | |
server.post('/', async (req, res) => { | |
app.handleHttpCallback(req, res); | |
}); | |
/* Defines the SmartApp .enableEventLogging() */ | |
app.enableEventLogging(2) | |
.appId("deleteInputs") | |
.configureI18n() // Language file in ./locales folder | |
.permissions([ | |
"r:locations:*", | |
"r:devices:*", | |
"x:devices:*" | |
]) | |
.page('mainPage', (context, page, configData) => { | |
page.section('device', section => { | |
for(let i=0; i<numofElements.length; i++){ | |
section.textSetting(numofElements[i]).name('Type your '+numofElements[i]).required(true).defaultValue('Input for '+numofElements[i]) | |
} | |
}); | |
}) | |
.updated(async (context, updateData) => { | |
console.log("update") | |
}) | |
.installed(async (context, InstallData) => { | |
console.log("installed") | |
deleteOneElement() | |
}); | |
function deleteOneElement(){ | |
numofElements.splice(1, 1); | |
console.log("numofElements ",numofElements) | |
} | |
/* 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