From c200fd6f4900d3ad1727bd1910845caaf3982acf Mon Sep 17 00:00:00 2001 From: Patrick <49351462+patrickbs96@users.noreply.github.com> Date: Wed, 8 Dec 2021 16:08:51 +0100 Subject: [PATCH] Added Details --- README.md | 4 +-- io-package.json | 12 +++++++++ lib/twinkly.js | 10 +++++++- main.js | 66 ++++++++++++++++++++++++++++++++++++------------- 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b1fb9677..26f633fd 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ The following States are available: | `ledColor` | :heavy_check_mark: | Color of LEDs, HSV/RGB(W)/HEX | | `ledConfig` | :heavy_check_mark: | Configuration of LEDs | | `ledEffect` | :heavy_check_mark: | Effects (`Effect`) | -| `ledLayout` | :heavy_check_mark: | Layout of LEDs | +| `ledLayout` | :heavy_check_mark: | Layout of LEDs (disabled for further testing) | | `ledMode` | :heavy_check_mark: | Mode: On, Color, Effect, Playlist, Off, RealTime (not yet supported), Demo | | `ledMovie` | :heavy_check_mark: | Active Movie, If multiple Movies are added in the Playlist feature then they can be selected here. (`On`) | | `ledPlaylist` | :heavy_check_mark: | Active Playlist Entry, Switch between Movies. (`Playlist`) | @@ -67,7 +67,7 @@ The following States are available: ## Changelog -### 0.2.5 (2021-12-06) +### 0.2.5 (2021-12-08) * (patrickbs96) Renamed States with led control. Now starting with "led". * (patrickbs96) Add new State `ledLayout`/`ledPlaylist` diff --git a/io-package.json b/io-package.json index efa886ab..a35ff3b4 100644 --- a/io-package.json +++ b/io-package.json @@ -3,6 +3,18 @@ "name": "twinkly", "version": "0.2.5", "news": { + "0.2.5": { + "en": "Add Playlist Feature. Renamed Datapoints", + "de": "Playlist-Funktion hinzufügen. Umbenannte Datenpunkte", + "ru": "Добавить функцию списка воспроизведения. Переименованные точки данных", + "pt": "Adicionar recurso de lista de reprodução. Pontos de dados renomeados", + "nl": "Voeg afspeellijstfunctie toe. Hernoemde datapunten", + "fr": "Ajouter une fonctionnalité de liste de lecture. Points de données renommés", + "it": "Aggiungi funzione playlist. Punti dati rinominati", + "es": "Agregar función de lista de reproducción. Puntos de datos renombrados", + "pl": "Dodaj funkcję listy odtwarzania. Zmienione nazwy punktów danych", + "zh-cn": "添加播放列表功能。重命名的数据点" + }, "0.2.4": { "en": "Handle wrong input so it does not cause exceptions", "de": "Behandeln Sie falsche Eingaben, damit keine Ausnahmen auftreten", diff --git a/lib/twinkly.js b/lib/twinkly.js index 7b741fa3..a4b56c02 100644 --- a/lib/twinkly.js +++ b/lib/twinkly.js @@ -110,11 +110,19 @@ class Twinkly { * @return {Promise} */ async interview() { + if (this.firmware === '') { + try { + await this.getFirmwareVersion(); + } catch (e) { + this.adapter.log.error(`[${this.name}.interview.fw] ${e}`); + } + } + if (Object.keys(this.details).length === 0) { try { await this.getDeviceDetails(); } catch (e) { - this.adapter.log.error(`[${this.name}.interview] ${e}`); + this.adapter.log.error(`[${this.name}.interview.details] ${e}`); } } } diff --git a/main.js b/main.js index 59ccdea5..521502fc 100644 --- a/main.js +++ b/main.js @@ -72,13 +72,24 @@ const stateNames = { measured_frame_rate : {id: 'measuredFrameRate', name: 'Measured Frame Rate', type: 'number'}, movie_capacity : {id: 'movieCapacity', name: 'Movie Capacity', type: 'number'}, number_of_led : {id: 'numberOfLed', name: 'Number of LED', type: 'number'}, + production_site : {id: 'productionSite', name: 'Production site', type: 'number', newSince: '2.8.3'}, + production_date : {id: 'productionDate', name: 'Production Date', type: 'number', role: 'value.time', newSince: '2.8.3'}, product_name : {id: 'productName', name: 'Product Name'}, product_version : {id: 'productVersion', name: 'Product Version'}, product_code : {id: 'productCode', name: 'Product Code'}, rssi : {id: 'rssi', name: 'RSSI', type: 'number'}, uptime : {id: 'uptime', name: 'Uptime'}, uuid : {id: 'uuid', name: 'UUID'}, - wire_type : {id: 'wireType', name: 'Wire Type', type: 'number'} + wire_type : {id: 'wireType', name: 'Wire Type', type: 'number'}, + + group : { + parent : {id: 'group', name: 'Group', newSince: '2.8.3'}, + subIDs : { + mode : {id: 'mode', name: 'Name'}, + compat_mode: {id: 'compatMode', name: 'Compat Mode', type: 'number'} + }, + expandJSON: false + } }, expandJSON: true }, @@ -245,7 +256,7 @@ const statesConfig = [ stateNames.ledColor.parent.id, // stateNames.ledConfig.id, stateNames.ledEffect.id, - stateNames.ledLayout.parent.id, + // stateNames.ledLayout.parent.id, Prüfen, weshalb es nicht klappt stateNames.ledMode.parent.id, stateNames.ledMovie.id, stateNames.ledSat.id, @@ -1059,8 +1070,7 @@ async function prepareObjectsByConfig() { exclude : [] }; - if (states[state].hide === undefined || !states[state].hide) { - + if (!states[state].hide) { if (states[state].parent !== undefined) { if (states[state].subIDs !== undefined && states[state].expandJSON) { // Soll der Parent angezeigt werden @@ -1082,8 +1092,12 @@ async function prepareObjectsByConfig() { } } else { let canAddState = true; - if (states[state].filter !== undefined && connections[config.device.id.device].connected) - canAddState = await connections[config.device.id.device].twinkly.checkDetailInfo(states[state].filter); + if (connections[config.device.id.device].connected) { + if (canAddState && states[state].filter !== undefined) + canAddState = await connections[config.device.id.device].twinkly.checkDetailInfo(states[state].filter); + if (canAddState && states[state].newSince !== undefined) + canAddState = tools.versionGreaterEqual(states[state].newSince, connections[config.device.id.device].twinkly.firmware); + } if (canAddState) { stateObj.id.state = states[state].id; @@ -1106,6 +1120,13 @@ async function prepareObjectsByConfig() { connections[connection].connected = false; adapter.log.error(`Could not ping ${connection} ${error}`); } + // Interview + try { + if (connections[connection].connected) + await connections[connection].twinkly.interview(); + } catch (error) { + adapter.log.error(`Could not interview ${connection} ${error}`); + } const config = { device: { @@ -1358,6 +1379,26 @@ async function saveJSONinState(connection, state, json, mapping) { mapping.logItem = mapping.logItem !== undefined && mapping.logItem === true; if (mapping.hide) return; + /** + * + * @param {String} id + * @param {{hide?: Boolean; filter?: {name: String, val: any}; role?: String}} stateInfo + * @param {any} value + * @param {Boolean} stringify + */ + async function writeState(id, stateInfo, value, stringify) { + let canSetState = !stateInfo.hide; + if (canSetState && stateInfo.filter !== undefined) + canSetState = await connections[connection].twinkly.checkDetailInfo(stateInfo.filter); + if (canSetState) { + // Unix * 1000 + if (!stringify && stateInfo.role === 'value.time') + value = value * 1000; + + await adapter.setStateAsync(state + '.' + id, stringify ? JSON.stringify(value) : value, true); + } + } + if (mapping.expandJSON) { if (!mapping.parent.hide) { state += '.' + mapping.parent.id; @@ -1367,12 +1408,7 @@ async function saveJSONinState(connection, state, json, mapping) { for (const key of Object.keys(json)) { if (Object.keys(mapping.subIDs).includes((key))) { if (typeof json[key] !== 'object' || Array.isArray(json[key])) { - let canSetState = !mapping.subIDs[key].hide; - if (canSetState && mapping.subIDs[key].filter !== undefined) - canSetState = await connections[connection].twinkly.checkDetailInfo(mapping.subIDs[key].filter); - if (canSetState) - await adapter.setStateAsync(state + '.' + mapping.subIDs[key].id, Array.isArray(json[key]) ? JSON.stringify(json[key]) : json[key], true); - + await writeState(mapping.subIDs[key].id, mapping.subIDs[key], json[key], Array.isArray(json[key])); } else { await saveJSONinState(connection, state, json[key], mapping.subIDs[key]); } @@ -1383,11 +1419,7 @@ async function saveJSONinState(connection, state, json, mapping) { } } } else { - let canSetState = true; - if (mapping.filter !== undefined) - canSetState = await connections[connection].twinkly.checkDetailInfo(mapping.filter); - if (canSetState) - await adapter.setStateAsync(state + '.' + mapping.parent.id, JSON.stringify(json), true); + await writeState(mapping.parent.id, mapping, json, true); } if (mapping.logItem) {