Skip to content

Commit

Permalink
add conditional stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Oct 24, 2024
1 parent 08311a0 commit a32ace6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit a32ace6

Please sign in to comment.