diff --git a/README.md b/README.md index 8e15bbe..b55ddaa 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,9 @@ with the ioBroker CLI. You can change the port via `iob set hm-rega. - ### __WORK IN PROGRESS__ --> +### 3.0.13 (2021-01-30) +* (foxriver76) ensure to not set states of non-existing RPC objects due to differences in the APIs (fixes #123) + ### 3.0.12 (2021-01-29) * (foxriver76) we now handle some more edge case errors diff --git a/hm-rega.js b/hm-rega.js index 8137842..17b5ac3 100644 --- a/hm-rega.js +++ b/hm-rega.js @@ -213,6 +213,7 @@ const checkInterval = {}; let units = {}; const states = {}; const objects = {}; +let existingStates = []; function _unescape(text) { if (typeof text !== 'string') { @@ -372,6 +373,8 @@ function main() { await getServiceMsgs(); } + // get Devices before datapoints to know which states exist + await getDevices(); await getDatapoints(); if (adapter.config.syncDutyCycle) { @@ -386,8 +389,6 @@ function main() { await getPrograms(); } - await getDevices(); - if (adapter.config.syncRooms && adapter.config.enumRooms) { await getRooms(); } @@ -1392,30 +1393,36 @@ async function getDatapoints() { states[id].val !== state.val || !states[id].ack) { states[id] = state; - await adapter.setForeignStateAsync(id, state); + // only set the state if it's a valid dp at RPC API and thus has an object + if (existingStates.includes(id)) { + await adapter.setForeignStateAsync(id, state); + } else { + adapter.log.debug(`Do not set "${JSON.stringify(state)}" to "${id}", because non-existing in corresponding adapter`); + } } // endIf } // endFor - adapter.log.info('got state values'); + adapter.log.info('Updated all datapoints'); + // delete it from RAM units = null; + existingStates = null; } /** - * Gets all devices, channels, states and rename them + * Gets all devices, channels, states and renames them * @param {string[]} devices * @param {string[]} channels * @param {string[]} _states - * @param {function} [callback] * @private */ -async function _getDevicesFromRega(devices, channels, _states, callback) { +async function _getDevicesFromRega(devices, channels, _states) { // Get all devices channels and states let data = await rega.runScriptFile('devices'); try { data = JSON.parse(data.replace(/\n/gm, '')); } catch (e) { adapter.log.error(`Cannot parse answer for devices: ${data}`); - return void (typeof callback === 'function' && callback()); + return; } const objs = []; let id; @@ -1495,8 +1502,7 @@ async function _getDevicesFromRega(devices, channels, _states, callback) { } // now rename all objects - while (objs.length > 0) { - const obj = objs.pop(); + for (const obj of objs) { try { await adapter.extendForeignObjectAsync(obj._id, obj); adapter.log.info(`renamed ${obj._id} to "${obj.common.name}"`); @@ -1504,13 +1510,14 @@ async function _getDevicesFromRega(devices, channels, _states, callback) { adapter.log.warn(`Could not rename object ${obj._id} to "${obj.common.name}": ${e}`); } } - - if (typeof callback === 'function') { - callback(); - } } -function getDevices(callback) { +/** + * Get all states/channels/devices from instance and request their name from REGA API and does renaming + * + * @return {Promise} + */ +async function getDevices() { const promises = []; const channels = {}; const devices = {}; @@ -1532,7 +1539,9 @@ function getDevices(callback) { promises.push(addStatesFromInstance(adapter.config.virtualDevicesAdapter)); } - Promise.all(promises).then(() => _getDevicesFromRega(devices, channels, _states, callback)); + await Promise.all(promises); + + await _getDevicesFromRega(devices, channels, _states); /** * adds the state information (min, max, etc.) from a given instance @@ -1587,6 +1596,8 @@ function getDevices(callback) { const parts = row.id.split('.'); const last = parts.pop(); const id = parts.join('.'); + existingStates.push(row.id); + if (row.value && row.value.native && row.value.native.UNIT) { const _id = row.id; units[_id] = _unescape(row.value.native.UNIT); diff --git a/io-package.json b/io-package.json index 27612df..3241324 100644 --- a/io-package.json +++ b/io-package.json @@ -2,8 +2,20 @@ "$schema": "https://raw.githubusercontent.com/foxriver76/ioBroker.js-controller/schemas/schemas/io-package.json", "common": { "name": "hm-rega", - "version": "3.0.12", + "version": "3.0.13", "news": { + "3.0.13": { + "en": "ensure to not set states of non-existing RPC objects due to differences in the APIs (fixes #123)", + "de": "Stellen Sie sicher, dass keine Zustände nicht vorhandener RPC-Objekte aufgrund von Unterschieden in den APIs festgelegt werden (Fixes # 123).", + "ru": "убедитесь, что не устанавливаются состояния несуществующих объектов RPC из-за различий в API (исправления # 123)", + "pt": "certifique-se de não definir estados de objetos RPC não existentes devido a diferenças nas APIs (correções # 123)", + "nl": "zorg ervoor dat u geen statussen instelt van niet-bestaande RPC-objecten vanwege verschillen in de API's (fixes # 123)", + "fr": "assurez-vous de ne pas définir les états des objets RPC non existants en raison de différences dans les API (correctifs # 123)", + "it": "assicurarsi di non impostare stati di oggetti RPC non esistenti a causa delle differenze nelle API (correzioni # 123)", + "es": "asegúrese de no establecer estados de objetos RPC no existentes debido a diferencias en las API (arreglos # 123)", + "pl": "zapewnić, aby nie ustawiać stanów nieistniejących obiektów RPC ze względu na różnice w interfejsach API (poprawki nr 123)", + "zh-cn": "确保不设置由于API的不同而导致的不存在的RPC对象的状态(修复#123)" + }, "3.0.12": { "en": "we now handle some more edge case errors", "de": "Wir behandeln jetzt einige weitere Randfallfehler", @@ -231,18 +243,6 @@ "es": "el tiempo de espera de las solicitudes aumentó a 90 segundos", "pl": "limit czasu żądań zwiększony do 90 sekund", "zh-cn": "请求超时增加到90秒" - }, - "2.6.10": { - "en": "fix crash when a user on CCU is a empty string on synchronizing favorites", - "de": "Absturz behoben, wenn ein Benutzer auf der CCU beim Synchronisieren von Favoriten eine leere Zeichenfolge ist", - "ru": "исправление сбоя, когда пользователь в CCU представляет собой пустую строку при синхронизации избранного", - "pt": "corrigir falha quando um usuário na CCU é uma string vazia na sincronização de favoritos", - "nl": "crash repareren wanneer een gebruiker op CCU een lege string is bij het synchroniseren van favorieten", - "fr": "Correction d'un crash lorsqu'un utilisateur sur CCU est une chaîne vide lors de la synchronisation des favoris", - "it": "risolve il crash quando un utente su CCU è una stringa vuota durante la sincronizzazione dei preferiti", - "es": "arregla el bloqueo cuando un usuario en CCU es una cadena vacía al sincronizar favoritos", - "pl": "napraw awarię, gdy użytkownik w CCU jest pustym ciągiem synchronizacji ulubionych", - "zh-cn": "修复当CCU上的用户为同步收藏夹中的空字符串时的崩溃" } }, "title": "HomeMatic ReGaHSS", diff --git a/package-lock.json b/package-lock.json index 4fc45e7..2248c5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "iobroker.hm-rega", - "version": "3.0.12", + "version": "3.0.13", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7dfe985..bb98bf7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iobroker.hm-rega", - "version": "3.0.12", + "version": "3.0.13", "engines": { "node": ">=10.0.0" },