From ec5064bc4d54efabbf7df9c15871ee17a1222de5 Mon Sep 17 00:00:00 2001 From: Tommy Goode Date: Thu, 24 Oct 2019 00:46:19 -0500 Subject: [PATCH] Store last_seen in state.json, so that it is sent out correctly on restart. (#2197) --- lib/controller.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index 87601c5e..b4ce7875 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -246,6 +246,10 @@ class Controller { 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}; const currentState = this.state.exists(entity.settings.ID) ? this.state.get(entity.settings.ID) : {}; const newState = objectAssignDeep.noMutate(currentState, payload); @@ -274,10 +278,6 @@ class Controller { 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 (settings.get().experimental.output === 'json') { await this.mqtt.publish(entity.name, JSON.stringify(messagePayload), options);