Skip to content

Commit

Permalink
feat: Nodes lastActive field #319
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Mar 20, 2020
1 parent 1f62fd6 commit 6b07091
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ function nodeAdded (nodeid) {
available: false,
hassDevices: {},
failed: false,
lastActive: null,
status: NODE_STATUS[5] // dead
}
addEmptyNodes(this.nodes)
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
<td>{{ props.item.name || '' }}</td>
<td>{{ props.item.loc || '' }}</td>
<td>{{ props.item.secure ? 'Yes' : 'No'}}</td>
<td>{{ props.item.status}}</td>
<td>{{ props.item.status }}</td>
<td>{{ props.item.lastActive ? (new Date(props.item.lastActive)).toLocaleString() : 'Never' }}</td>
</tr>
</template>
</v-data-table>
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 6b07091

Please sign in to comment.