diff --git a/MMM-NetworkScanner.js b/MMM-NetworkScanner.js index 4b26e0f..724c20a 100644 --- a/MMM-NetworkScanner.js +++ b/MMM-NetworkScanner.js @@ -88,10 +88,10 @@ Module.register("MMM-NetworkScanner", { ); if (this.config.showOffline) { - var networkDevicesByMac = getKeyedObject(this.networkDevices, 'macAddress'); - var payloadDevicesByMac = getKeyedObject(nextState, 'macAddress'); - - nextState = this.config.devices.map(device => { + var networkDevicesByMac = getKeyedObject(this.networkDevices, 'macAddress'); + var payloadDevicesByMac = getKeyedObject(nextState, 'macAddress'); + + nextState = this.config.devices.map((device,index) => { if (device.macAddress) { var oldDeviceState = networkDevicesByMac[device.macAddress]; var payloadDeviceState = payloadDevicesByMac[device.macAddress]; @@ -103,12 +103,25 @@ Module.register("MMM-NetworkScanner", { var isStale = (sinceLastSeen >= this.config.keepAlive); newDeviceState.online = (sinceLastSeen != null) && (!isStale); - + //here I remove the device if it goes offline (this could be decided by users through another config parameter + if (!newDeviceState.online && 'type' in newDeviceState && newDeviceState.type == 'Unknown') { + this.config.devices.splice(index,index); + } + return newDeviceState; } else { return device; } }); + if (this.config.showUnknown) { + // Integrate to this.config.devices every unknown device in payloadDevicesByMac, it makes sure the same device is not added twice. + for (device in payloadDevicesByMac) { + if ('type' in payloadDevicesByMac[device] && payloadDevicesByMac[device].type == 'Unknown') { + let filtered = this.config.devices.filter((v,i,a)=> v.macAddress == payloadDevicesByMac[device].macAddress); + if (filtered.length == 0) this.config.devices.push(payloadDevicesByMac[device]); + } + } + } } this.networkDevices = nextState; @@ -126,13 +139,15 @@ Module.register("MMM-NetworkScanner", { // Send notification if user status has changed if (this.config.residents.length > 0) { - var anyoneHome, command; + var anyoneHome, command, resident_found; // self = this; anyoneHome = 0; this.networkDevices.forEach(function(device) { if (self.config.residents.indexOf(device.name) >= 0) { anyoneHome = anyoneHome + device.online; + if (device.online) + resident_found = device; } }); @@ -144,6 +159,7 @@ Module.register("MMM-NetworkScanner", { if (this.config.debug) Log.info("Someone has come home"); if (this.config.occupiedCMD) { var occupiedCMD = self.config.occupiedCMD; + occupiedCMD.payload.resident_found = resident_found; this.sendNotification(occupiedCMD.notification, occupiedCMD.payload); } this.occupied = true; diff --git a/package.json b/package.json index 6f983d8..cbd8e88 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "ping": "^0.1.10" }, "devDependencies": { - "grunt": "latest", - "grunt-contrib-jshint": "latest", - "grunt-contrib-nodeunit": "latest" + "grunt": "latest", + "grunt-contrib-jshint": "latest", + "grunt-contrib-nodeunit": "latest" } }