Skip to content

Commit acf289d

Browse files
committed
feat(device): Indicate failure of proactive discovery as node status
1 parent b3ba524 commit acf289d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

connection.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ module.exports = function (RED) {
383383
}
384384
}
385385

386-
this.handlePing = function (semverExpr) {
386+
this.handlePing = function ({ semverExpr }) {
387387
if (!semver.satisfies(VSH_VERSION, semverExpr)) {
388388
return
389389
}
@@ -402,7 +402,7 @@ module.exports = function (RED) {
402402
})
403403
}
404404

405-
this.handleKill = function (reason, semverExpr) {
405+
this.handleKill = function ({ reason, semverExpr }) {
406406
if (semverExpr && !semver.satisfies(VSH_VERSION, semverExpr)) {
407407
return
408408
}
@@ -413,10 +413,20 @@ module.exports = function (RED) {
413413
this.disconnect()
414414
}
415415

416+
this.handleSetDeviceStatus = function ({ status, color, devices }) {
417+
devices.forEach((deviceId) => {
418+
this.execCallbackForOne(deviceId, 'setStatus', {
419+
shape: 'dot',
420+
fill: color,
421+
text: status,
422+
})
423+
})
424+
}
425+
416426
this.handleService = function (message) {
417427
switch (message.operation) {
418428
case 'ping':
419-
this.handlePing(message.semverExpr)
429+
this.handlePing(message)
420430
break
421431
case 'overrideConfig':
422432
if (message.rateLimiter) {
@@ -425,8 +435,16 @@ module.exports = function (RED) {
425435
}
426436
break
427437
case 'kill':
428-
this.handleKill(message.reason, message.semverExpr)
438+
this.handleKill(message)
429439
break
440+
case 'setDeviceStatus':
441+
this.handleSetDeviceStatus(message)
442+
break
443+
default:
444+
this.logger(
445+
`received service request (${message.operation}) that is not supported by this VSH version. Updating to the latest version might fix this!`,
446+
'warn'
447+
)
430448
}
431449
}
432450

0 commit comments

Comments
 (0)