Skip to content

Instantly share code, notes, and snippets.

@nayelyzarazua-bluetrail
Created March 2, 2021 21:28
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/995befb1f36d3bf332feda027a598d3c to your computer and use it in GitHub Desktop.
Save nayelyzarazua-bluetrail/995befb1f36d3bf332feda027a598d3c to your computer and use it in GitHub Desktop.
SmartApp_DynamicInputsDelete
'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