Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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