From 36d9ec8953954c427ceb4fd1a1fe9f4715b5459a Mon Sep 17 00:00:00 2001 From: Garfonso Date: Tue, 2 Jan 2024 13:46:35 +0100 Subject: [PATCH] state always (!!!) is string -> this fixes individual on power flow card fixes #483 Not sure, if this introduces other errors (again). Let's see... I did not yet see any. --- lib/converters/genericConverter.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/converters/genericConverter.js b/lib/converters/genericConverter.js index 2cf47214a..73f731182 100644 --- a/lib/converters/genericConverter.js +++ b/lib/converters/genericConverter.js @@ -48,8 +48,6 @@ exports.numericDeviceClasses = [ 'distance' ]; -const numericDeviceClassesIob = exports.numericDeviceClasses.concat(['timestamp']); - exports.iobState2EntityState = function (entity, val, attribute) { let type = entity.context.type; const pos = type.lastIndexOf('.'); @@ -61,14 +59,17 @@ exports.iobState2EntityState = function (entity, val, attribute) { return val ? 'on' : 'off'; } else if (type === 'binary_sensor') { return val ? 'on' : 'off'; - } else if (typeof val === 'number' && entity.attributes && (numericDeviceClassesIob.includes(entity.attributes.device_class) || entity.attributes.unit_of_measurement)) { - return val; //do not convert timestamps or values that have a unit of measurement.. - } else if (typeof val === 'number' && entity.attributes && ['date'].includes(entity.attributes.device_class)) { - const dateStr = new Date(val).toDateString(); //convert to date string + }else if (typeof val === 'number' && entity.attributes && ['date', 'timestamp'].includes(entity.attributes.device_class)) { + //convert to date string + const date = new Date(val); + let dateStr = date.toDateString(); + if (attribute === 'timestamp') { + dateStr = date.toISOString(); + } return dateStr === 'Invalid Date' ? 'unknown' : dateStr; } else if (type === 'lock') { return val ? 'unlocked' : 'locked'; - } else if (typeof val === 'boolean' && type !== 'media_player') { + } else if (typeof val === 'boolean' && type !== 'media_player' && !attribute) { //attributes can have true/false. return val ? 'on' : 'off'; } else if (typeof val === 'number' && entity.context.STATE.map2lovelace) { return entity.context.STATE.map2lovelace[val] || val;