Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showOffline=false and residents don't work reliably #50

Open
thburghout opened this issue Nov 9, 2019 · 0 comments
Open

showOffline=false and residents don't work reliably #50

thburghout opened this issue Nov 9, 2019 · 0 comments

Comments

@thburghout
Copy link

This is due to the keepAlive only being respected when showOffline is active.

I will leave a patch here, as this repository does not seem to be maintained. Alternatively, you may provide some instructions on what a pull request should contain.

--- MMM-NetworkScanner.js
+++ MMM-NetworkScanner.js
@@ -14,7 +14,7 @@
 	defaults: {
 		devices: [], // an array of device objects e.g. { macAddress: "aa:bb:cc:11:22:33", name: "DEVICE-NAME", icon: "FONT-AWESOME-ICON"}
 		network: "-l", // a Local Network IP mask to limit the mac address scan, i.e. `192.168.0.0/24`. Use `-l` for the entire localnet
-		showUnknown: true, // shows devices found on the network even if not specified in the 'devices' option 
+		showUnknown: true, // shows devices found on the network even if not specified in the 'devices' option
 		showOffline: true, // shows devices specified in the 'devices' option even when offline
 		showLastSeen: false, // shows when the device was last seen e.g. "Device Name - last seen 5 minutes ago"
 		keepAlive: 180, // how long (in seconds) a device should be considered 'alive' since it was last found on the network
@@ -87,31 +87,30 @@
 				})
 			);
 
-			if (this.config.showOffline) {
-				var networkDevicesByMac = getKeyedObject(this.networkDevices, 'macAddress');
-				var payloadDevicesByMac = getKeyedObject(nextState, 'macAddress');
+			var networkDevicesByMac = getKeyedObject(this.networkDevices, 'macAddress');
+			var payloadDevicesByMac = getKeyedObject(nextState, 'macAddress');
 
-				nextState = this.config.devices.map(device => {
-					if (device.macAddress) {
-						var oldDeviceState = networkDevicesByMac[device.macAddress];
-						var payloadDeviceState = payloadDevicesByMac[device.macAddress];
-						var newDeviceState = payloadDeviceState || oldDeviceState || device;
+			nextState = this.config.devices.map(device => {
+				if (device.macAddress) {
+					var oldDeviceState = networkDevicesByMac[device.macAddress];
+					var payloadDeviceState = payloadDevicesByMac[device.macAddress];
+					var newDeviceState = payloadDeviceState || oldDeviceState || device;
 
-						var sinceLastSeen = newDeviceState.lastSeen ?
-							moment().diff(newDeviceState.lastSeen, 'seconds') :
-							null;
-						var isStale = (sinceLastSeen >= this.config.keepAlive);
+					var sinceLastSeen = newDeviceState.lastSeen ?
+						moment().diff(newDeviceState.lastSeen, 'seconds') :
+						null;
+					var isStale = (sinceLastSeen >= this.config.keepAlive);
 
-						newDeviceState.online = (sinceLastSeen != null) && (!isStale);
+					newDeviceState.online = (sinceLastSeen != null) && (!isStale);
 
-						return newDeviceState;
-					} else {
-						return device;
-					}
-				});
-			}
+					return newDeviceState;
+				} else {
+					return device;
+				}
+			});
 
-			this.networkDevices = nextState;
+			this.networkDevices = this.config.showOffline ?
+				nextState : nextState.filter(d => { return d.online; });
 
 			// Sort list by known device names, then unknown device mac addresses
 			if (this.config.sort) {
@@ -213,7 +212,7 @@
 				deviceRow.appendChild(deviceCell);
 
 				// When last seen
-				if ((self.config.showLastSeen && device.lastSeen  && !self.config.showLastSeenWhenOffline) || 
+				if ((self.config.showLastSeen && device.lastSeen  && !self.config.showLastSeenWhenOffline) ||
 					(self.config.showLastSeen && !device.lastSeen &&  self.config.showLastSeenWhenOffline)) {
 					var dateCell = document.createElement("td");
 					dateCell.classList.add("date", "dimmed", "light");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant