From 6b070915c98ed31f47340a3a6ebe55cc454360f7 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 20 Mar 2020 16:38:37 +0100 Subject: [PATCH] feat: Nodes lastActive field #319 --- lib/ZwaveClient.js | 12 +++++++++++- src/components/ControlPanel.vue | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/ZwaveClient.js b/lib/ZwaveClient.js index 31d58903a06..5b27bbea1e6 100644 --- a/lib/ZwaveClient.js +++ b/lib/ZwaveClient.js @@ -277,6 +277,7 @@ function nodeAdded (nodeid) { available: false, hassDevices: {}, failed: false, + lastActive: null, status: NODE_STATUS[5] // dead } addEmptyNodes(this.nodes) @@ -415,6 +416,7 @@ function nodeReady (nodeid, nodeinfo) { ozwnode.ready = true ozwnode.status = NODE_STATUS[6] + ozwnode.lastActive = Date.now() // add it to know devices types (if not already present) if (!this.devices[ozwnode.device_id]) { @@ -515,12 +517,20 @@ function notification (nodeid, notif, help) { case 6: // alive msg = 'node' + nodeid + ': node ' + NODE_STATUS[notif] + let ready = notif !== 5 + let wasReady = ozwnode.ready + + if (ready || (!ready && wasReady)) { + ozwnode.lastActive = Date.now() + } + if (ozwnode.available) { ozwnode.status = NODE_STATUS[notif] - ozwnode.ready = notif !== 5 + ozwnode.ready = ready this.emit('nodeStatus', ozwnode) } + break default: msg = 'Unknown notification code ' + notif diff --git a/src/components/ControlPanel.vue b/src/components/ControlPanel.vue index a44034db7e4..f492d5daee2 100644 --- a/src/components/ControlPanel.vue +++ b/src/components/ControlPanel.vue @@ -72,7 +72,8 @@ {{ props.item.name || '' }} {{ props.item.loc || '' }} {{ props.item.secure ? 'Yes' : 'No'}} - {{ props.item.status}} + {{ props.item.status }} + {{ props.item.lastActive ? (new Date(props.item.lastActive)).toLocaleString() : 'Never' }} @@ -710,7 +711,8 @@ export default { { text: 'Name', value: 'name' }, { text: 'Location', value: 'loc' }, { text: 'Secure', value: 'secure' }, - { text: 'Status', value: 'status' } + { text: 'Status', value: 'status' }, + { text: 'Last Active', value: 'lastActive' } ], rules: { required: value => {