Skip to content

Commit

Permalink
chore: release v3.0.13
Browse files Browse the repository at this point in the history
ensure to not set states of non-existing RPC objects due to differences in the APIs (fixes #123)
  • Loading branch information
foxriver76 committed Jan 30, 2021
1 parent f4d216e commit e5c1a0b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ with the ioBroker CLI. You can change the port via `iob set hm-rega.<instance> -
### __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

Expand Down
43 changes: 27 additions & 16 deletions hm-rega.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ const checkInterval = {};
let units = {};
const states = {};
const objects = {};
let existingStates = [];

function _unescape(text) {
if (typeof text !== 'string') {
Expand Down Expand Up @@ -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) {
Expand All @@ -386,8 +389,6 @@ function main() {
await getPrograms();
}

await getDevices();

if (adapter.config.syncRooms && adapter.config.enumRooms) {
await getRooms();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1495,22 +1502,22 @@ 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}"`);
} catch (e) {
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<void>}
*/
async function getDevices() {
const promises = [];
const channels = {};
const devices = {};
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.hm-rega",
"version": "3.0.12",
"version": "3.0.13",
"engines": {
"node": ">=10.0.0"
},
Expand Down

0 comments on commit e5c1a0b

Please sign in to comment.