diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 3ca3b15..db7f93b 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -16,7 +16,10 @@ "defaultTopic": { "type": "text", "label": "defaultTopic", - "newLine": true + "newLine": true, + "sm": 12, + "md": 6, + "lg": 3 }, "defaultTopicAuth": { "type": "select", @@ -42,19 +45,92 @@ "defaultUsername": { "type": "text", "label": "defaultUsername", - "newLine": true + "newLine": true, + "sm": 12, + "md": 6, + "lg": 3 }, "defaultPassword": { "type": "password", "label": "defaultPassword", "visible": true, - "newLine": false + "newLine": false, + "sm": 12, + "md": 6, + "lg": 3 }, "defaultAccessToken": { "type": "text", "label": "defaultAccessToken", "help": "helpDefaultAccessToken", - "newLine": true + "newLine": false, + "sm": 12, + "md": 6, + "lg": 3 + }, + "presetTopicsDivider": { + "type": "divider" + }, + "presetTopics": { + "type": "table", + "sm": 12, + "items": [ + { + "type": "text", + "width": "20%", + "attr": "presetTopicName", + "title": "TopicName" + }, + { + "type": "select", + "width": "20%", + "attr": "presetTopicAuth", + "title": "TopicAuth", + "options": [ + { + "label": "defaultTopicAuthNone", + "value": 0 + }, + { + "label": "defaultTopicAuthUser", + "value": 1 + }, + { + "label": "defaultTopicAuthToken", + "value": 2 + } + ] + }, + { + "type": "text", + "width": "20%", + "attr": "presetTopicUsername", + "title": "TopicUsername" + }, + { + "type": "password", + "width": "20%", + "attr": "presetTopicPassword", + "title": "TopicPassword", + "visible": true + }, + { + "type": "password", + "width": "20%", + "attr": "presetTopicAccessToken", + "title": "TopicAccessToken", + "visible": true + } + ] + }, + "actionsDivider": { + "type": "divider" + }, + "testBtn": { + "type": "sendTo", + "command": "testBtn", + "variant": "contained", + "label": "Test" } } } \ No newline at end of file diff --git a/main.js b/main.js index c03c491..6ab5f93 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ const utils = require('@iobroker/adapter-core'); const axios = require('axios'); +const {type} = require('os'); class ntfy extends utils.Adapter { @@ -75,6 +76,19 @@ class ntfy extends utils.Adapter { } } } + if (typeof obj === 'object' && obj.command) { + if (obj.command === 'testBtn') { + this.log.error(`test: ${JSON.stringify(this.config.presetTopics)} and type ${typeof this.config.presetTopics}`); + let testMsg; + if (typeof this.config.presetTopics !== 'object' || this.config.presetTopics.length <= 0) { + testMsg = 'Presets: None'; + } else { + testMsg = `Presets: ${JSON.stringify(this.config.presetTopics)}`; + } + + this.sendTo(obj.from, obj.command, [{label: testMsg, value: ''}], obj.callback); + } + } } sendMessage(obj) {