diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 60bf487..484aa57 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -16,18 +16,18 @@ }, // Lines of text with details - "headerhowToConnect-details-1": { + "headerHowToConnect-details-1": { "newLine": true, "type": "staticText", "text": "lblConnectDetails-Line-1" }, - "headerhowToConnect-details-2": { + "headerHowToConnect-details-2": { "newLine": true, "type": "staticText", "text": "lblConnectDetails-Line-2" }, - "headerhowToConnect-details-3": { + "headerHowToConnect-details-3": { "newLine": true, "type": "staticText", "text": "lblConnectDetails-Line-3" @@ -47,7 +47,7 @@ }, // Text explaining ioBroker integration - "headerHowToConnect-details-3": { + "headerHowToConnect-details-4": { "newLine": true, "type": "staticText", "text": "lblConnectIobroker" @@ -72,12 +72,12 @@ }, // Explanation of usage and warning - "headerdefaultCredentials-details-1": { + "headerDefaultCredentials-details-1": { "newLine": true, "type": "staticText", "text": "lblDefaultCredentials-Line-1" }, - "headerdefaultCredentials-details-2": { + "headerDefaultCredentials-details-2": { "newLine": true, "type": "staticText", "text": "lblDefaultCredentials-Line-2" @@ -108,8 +108,8 @@ "autodiscovery": { "newLine": true, "type": "checkbox", - "sm": 6, - "md": 6, + "sm": 2, + "md": 2, "label": "lblAutoDiscovery" }, @@ -122,9 +122,10 @@ "command": "loadDevices", "jsonData": "{ \"date\": \"${data}\"}", "label": "lblLoadDevices", - "tooltip": "restoreDefaultToolTip", +// "tooltip": "restoreDefaultToolTip", "useNative": true, "variant": "outlined", + "showProcess" : true, "xs": 12, "sm": 12, "md": 12, @@ -149,37 +150,37 @@ "type": "autocompleteSendTo", "command": "getDeviceIPs", "jsonData": "{ \"service\": \"${data.deviceInputIP}\" }", - "xs": 6, - "sm": 6, - "md": 6, - "lg": 6, + "xs": 2, + "sm": 2, + "md": 2, + "lg": 2, "label": "lblInputDeviceIP-content", -// "tooltip": "Select existing device or Enter IP of new device", - "help": "lblInputDeviceIP" + "tooltip": "hlpInputDeviceIP", + "help": "hlpInputDeviceIP" }, "encryptionKey": { "type": "password", "label": "lblInputEncryptionKey", "doNotSave": true, "default": "", - "tooltip": "ttInputEncryptionKey", - "help": "hlpCloudPassword", - "xs": 3, - "sm": 3, - "md": 3, - "lg": 3 + "tooltip": "hlpInputEncryptionKey", + "help": "hlpInputEncryptionKey", + "xs": 4, + "sm": 4, + "md": 4, + "lg": 4 }, "apiPassword": { "type": "password", "label": "lblInputApiPassword", "doNotSave": true, "default": "", - "tooltip": "ttInputApiPassword", - "help": "hlpCloudPassword", - "xs": 3, - "sm": 3, - "md": 3, - "lg": 3 + "tooltip": "hlpInputApiPassword", + "help": "hlpInputApiPassword", + "xs": 2, + "sm": 2, + "md": 2, + "lg": 2 }, // Button do ADD / Modify devices, sends @@ -218,13 +219,19 @@ "xs": 12, "sm": 12, "md": 12, - "lg": 12 + "lg": 12, + "confirm" : { + "text" : "Are you sure to delete this device ? Alle states will be removed", + "title" : "Confirm device Deletion", + "ok" : "Delete Device", + "cancel" : "Cancel", + "type" : "warning" + } }, // Table (provided by backend) of all devices and their connection status "templateTable": { "type": "table", - "doNotSave" : true, "noDelete": true, "newLine": true, "xs": 12, @@ -299,7 +306,7 @@ // Header ESPHome "headerESPHomeDashboard": { "type": "header", - "text": "lblHeaderMainpage", + "text": "lblHeaderMainPage", "size": 1 }, // Introduction text @@ -388,19 +395,7 @@ "newLine": true, "type": "staticText", "text": "" - }, - - - "bindAddress" : { - "type": "ip", - "onlyIp4": true, - "noInternal": true, - "newLine": true, - "sm": 3, - "md": 3, - "lg": 3 } - } }, @@ -465,17 +460,17 @@ } }, - "sandBox": { - "type": "panel", - "label": "sandBox", - "items": { - "bindAddress" : { - "type": "ip", - "onlyIp4": true, - "noInternal": true - } - - } - } +// "sandBox": { +// "type": "panel", +// "label": "sandBox", +// "items": { +// "bindAddress" : { +// "type": "ip", +// "onlyIp4": true, +// "noInternal": true +// } +// +// } +// } } } \ No newline at end of file diff --git a/main.js b/main.js index eee425b..51bac91 100644 --- a/main.js +++ b/main.js @@ -852,7 +852,7 @@ class Esphome extends utils.Adapter { } // Avoid channel creation for empty arrays/objects if (Object.keys(jObject[i]).length !== 0) { - console.log(`park`); + // console.log(`park`); await this.setObjectAsync(id, { 'type': 'channel', 'common': { @@ -1101,6 +1101,15 @@ class Esphome extends utils.Adapter { } } + /** + * Validate a proper format of IP-Address + * @param {string} ipAddress + */ + // eslint-disable-next-line no-case-declarations,no-inner-declarations + validateIPAddress(ipAddress) { + return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipAddress); + } + /** * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ... * Using this method requires "common.message" property to be set to true in io-package.json @@ -1110,22 +1119,13 @@ class Esphome extends utils.Adapter { this.log.info('Data from configuration received : ' + JSON.stringify(obj)); try { - /** - * Validate a proper format of IP-Address - * @param {string} ipAddress - */ - // eslint-disable-next-line no-case-declarations,no-inner-declarations - function validateIPAddress(ipAddress) { - return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipAddress); - } - switch (obj.command) { //ToDo previous add function to be removed case 'addDevice': // eslint-disable-next-line no-case-declarations - const ipValid = validateIPAddress(obj.message['device-ip']); + const ipValid = this.validateIPAddress(obj.message['device-ip']); if (!ipValid) { this.log.warn(`You entered an incorrect IP-Address, cannot add device !`); @@ -1166,7 +1166,7 @@ class Esphome extends utils.Adapter { } break; - // Front End message handler to load table with all current known devices + // Front End message handler to load IP-Address dropDown with all current known devices case 'getDeviceIPs': { const dropDownEntrys = []; @@ -1179,14 +1179,14 @@ class Esphome extends utils.Adapter { // Handle front-end messages to ADD / Modify a devices case '_addUpdateDevice': - console.log(JSON.stringify(obj)); + // console.log(JSON.stringify(obj)); // IP input validation if (obj.message.ip === 'undefined'){ this.sendTo(obj.from, obj.command, {error: 'To add/modify a device, please enter the IP-Address accordingly'}, obj.callback); return; - } else if (!validateIPAddress(obj.message.ip)){ + } else if (!this.validateIPAddress(obj.message.ip)){ this.sendTo(obj.from, obj.command, {error: 'Format of IP-Address is incorrect, please provide an valid IPV4 IP-Address'}, obj.callback); @@ -1513,7 +1513,7 @@ class Esphome extends utils.Adapter { try { // Get an overview of all current devices known by adapter const knownDevices = await this.getDevicesAsync(); - console.log(`KnownDevices: ${knownDevices}`); + // console.log(`KnownDevices: ${knownDevices}`); // Loop to all devices, check if online state = TRUE otherwise delete device for (const device in knownDevices){ // Get online value