Store last_seen in state.json, so that it is sent out correctly on restart. (#2197)

This commit is contained in:
Tommy Goode 2019-10-24 00:46:19 -05:00 committed by Koen Kanters
parent ebd2f264a9
commit ec5064bc4d

View File

@ -246,6 +246,10 @@ class Controller {
return; return;
} }
if (entity.type === 'device' && settings.get().advanced.last_seen !== 'disable' && entity.device.lastSeen) {
payload.last_seen = utils.formatDate(entity.device.lastSeen, settings.get().advanced.last_seen);
}
let messagePayload = {...payload}; let messagePayload = {...payload};
const currentState = this.state.exists(entity.settings.ID) ? this.state.get(entity.settings.ID) : {}; const currentState = this.state.exists(entity.settings.ID) ? this.state.get(entity.settings.ID) : {};
const newState = objectAssignDeep.noMutate(currentState, payload); const newState = objectAssignDeep.noMutate(currentState, payload);
@ -274,10 +278,6 @@ class Controller {
attributes.forEach((a) => messagePayload.device[a] = device[a]); attributes.forEach((a) => messagePayload.device[a] = device[a]);
} }
if (entity.type === 'device' && settings.get().advanced.last_seen !== 'disable') {
messagePayload.last_seen = utils.formatDate(entity.device.lastSeen, settings.get().advanced.last_seen);
}
if (Object.entries(messagePayload).length) { if (Object.entries(messagePayload).length) {
if (settings.get().experimental.output === 'json') { if (settings.get().experimental.output === 'json') {
await this.mqtt.publish(entity.name, JSON.stringify(messagePayload), options); await this.mqtt.publish(entity.name, JSON.stringify(messagePayload), options);