Skip to content

Commit

Permalink
fix possible invalid date
Browse files Browse the repository at this point in the history
  • Loading branch information
Garfonso committed Dec 9, 2023
1 parent 3497413 commit aacfa4a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/converters/genericConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ exports.iobState2EntityState = function (entity, val, attribute) {
} else if (typeof val === 'number' && entity.attributes && ['timestamp'].includes(entity.attributes.device_class)) {
return val; //do not convert timestamps.
} else if (typeof val === 'number' && entity.attributes && ['date'].includes(entity.attributes.device_class)) {
return new Date(val).toDateString(); //convert to date string
const dateStr = new Date(val).toDateString(); //convert to date string
return dateStr === 'Invalid Date' ? 'unknown' : dateStr;
} else if (type === 'lock') {
return val ? 'unlocked' : 'locked';
} else if (typeof val === 'boolean' && type !== 'media_player') {
Expand Down

0 comments on commit aacfa4a

Please sign in to comment.