* (Apollon77) make sure a "null" value in state changes is not crashing

This commit is contained in:
Ingo Fischer
2022-06-17 23:20:26 +02:00
parent 271bd03d14
commit 52d8bddb11
5 changed files with 49 additions and 6 deletions
+3 -3
View File
@@ -42,7 +42,7 @@ function startAdapter(options) {
let requestFields = {};
if (typeof state.val === 'string') {
try {
requestFields = JSON.parse(state.val);
requestFields = JSON.parse(state.val) || {};
} catch (err) {
adapter.log.info(`Ignore data for service call ${id} is no valid JSON: ${err.message}`);
requestFields = {};
@@ -284,7 +284,7 @@ function parseStates(entities, services, callback) {
}
obj = {
_id: `${adapter.namespace}.entities.${entity.entity_id}.${attr}`,
_id: `${adapter.namespace}.entities.${entity.entity_id}.${attr.replace(adapter.FORBIDDEN_CHARS, '_')}`,
type: 'state',
common: common,
native: {
@@ -390,7 +390,7 @@ function main() {
if ((typeof val === 'object' && val !== null) || Array.isArray(val)) {
val = JSON.stringify(val);
}
adapter.setForeignState(id + attr, {val, ack: true, lc, ts});
adapter.setForeignState(id + attr.replace(adapter.FORBIDDEN_CHARS, '_'), {val, ack: true, lc, ts});
}
}
});