Skip to content

Commit

Permalink
state always (!!!) is string -> this fixes individual on power flow card
Browse files Browse the repository at this point in the history
fixes #483

Not sure, if this introduces other errors (again). Let's see... I did not yet see any.
  • Loading branch information
Garfonso committed Jan 2, 2024
1 parent 4b1a055 commit 36d9ec8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/converters/genericConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.');
Expand All @@ -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;
Expand Down

0 comments on commit 36d9ec8

Please sign in to comment.