From a32ace628494af045f4c0c71ab7d3000e64eb61f Mon Sep 17 00:00:00 2001 From: TA2k Date: Thu, 24 Oct 2024 20:12:26 +0200 Subject: [PATCH] add conditional stringify --- main.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index d057189..ef73338 100644 --- a/main.js +++ b/main.js @@ -673,15 +673,18 @@ class Homeconnect extends utils.Adapter { .then(() => { if (subElement.value !== undefined) { this.log.debug('Set api value'); - this.setState( - haId + folder + '.' + subElement.key.replace(/\./g, '_'), - JSON.stringify(subElement.value), - true, - ).catch((error) => { - this.log.error('failed set state ' + haId + folder + '.' + subElement.key.replace(/\./g, '_')); - this.log.error("Value: '" + JSON.stringify(subElement.value) + "'"); - this.log.error(error); - }); + let value = subElement.value; + //check if value is an object + if (typeof value === 'object' && value !== null) { + value = JSON.stringify(value); + } + this.setState(haId + folder + '.' + subElement.key.replace(/\./g, '_'), value, true).catch( + (error) => { + this.log.error('failed set state ' + haId + folder + '.' + subElement.key.replace(/\./g, '_')); + this.log.error("Value: '" + value + "'"); + this.log.error(error); + }, + ); } }) .catch(() => {