diff --git a/lib/hass.js b/lib/hass.js index ca5bc5c..c9e75ed 100644 --- a/lib/hass.js +++ b/lib/hass.js @@ -156,7 +156,7 @@ function HASS(options, log) { log.error(`Invalid answer: ${msg}`); } else { if (response.type === 'result' && requests[response.id]) { - log.debug(`got answer for ${requests[response.id].type} success = ${response.success}, result = ${response.result}`); + log.debug(`got answer for ${requests[response.id].type} success = ${response.success}, result = ${JSON.stringify(response.result)}`); if (typeof requests[response.id].cb === 'function') { requests[response.id].cb(!response.success, response.result); delete requests[response.id]; diff --git a/main.js b/main.js index 23f3aab..a78e3ce 100644 --- a/main.js +++ b/main.js @@ -244,7 +244,13 @@ function parseStates(entities, services, callback) { } adapter.log.debug(`Found Entity state ${obj._id}: ${JSON.stringify(obj.common)} / ${JSON.stringify(obj.native)}`) objs.push(obj); - states.push({id: obj._id, lc: lc, ts: ts, val: entity.state, ack: true}) + + let val = entity.state; + if ((typeof val === 'object' && val !== null) || Array.isArray(val)) { + val = JSON.stringify(val); + } + + states.push({id: obj._id, lc, ts, val, ack: true}) } if (entity.attributes) { @@ -288,7 +294,13 @@ function parseStates(entities, services, callback) { adapter.log.debug(`Found Entity attribute ${obj._id}: ${JSON.stringify(obj.common)} / ${JSON.stringify(obj.native)}`) objs.push(obj); - states.push({id: obj._id, lc: lc, ts: ts, val: entity.attributes[attr], ack: true}); + + let val = entity.attributes[attr]; + if ((typeof val === 'object' && val !== null) || Array.isArray(val)) { + val = JSON.stringify(val); + } + + states.push({id: obj._id, lc, ts, val, ack: true}); } } } @@ -355,7 +367,7 @@ function main() { } let val = entity.attributes[attr]; if ((typeof val === 'object' && val !== null) || Array.isArray(val)) { - val = JSON.stringify(entity.attributes[attr]); + val = JSON.stringify(val); } adapter.setForeignState(id + attr, {val, ack: true, lc, ts}); }