diff --git a/MMM-NetworkScanner.js b/MMM-NetworkScanner.js index f340bd0..d54d966 100644 --- a/MMM-NetworkScanner.js +++ b/MMM-NetworkScanner.js @@ -25,6 +25,10 @@ Module.register("MMM-NetworkScanner", { occupiedCMD: null, // {notification: 'TEST', payload: {action: 'occupiedCMD'}}, vacantCMD: null, // {notification: 'TEST', payload: {action: 'vacantCMD'}}, + colored: false, // show devices colorcoded with color defined in devices [] // + coloredSymbolOnly: false, // show symbol only in color // + showLastSeenWhenOffline: false, // show last seen only when offline // + debug: false, }, @@ -176,27 +180,42 @@ Module.register("MMM-NetworkScanner", { var deviceTable = document.createElement("table"); deviceTable.classList.add("small"); this.networkDevices.forEach(function(device) { - if (device) { + if (device && (device.online || device.showOffline)) { // device row + var deviceRow = document.createElement("tr"); var deviceOnline = (device.online ? "bright" : "dimmed"); deviceRow.classList.add(deviceOnline); // Icon + var deviceCell = document.createElement("td"); deviceCell.classList.add("device"); var icon = document.createElement("i"); icon.classList.add("fa", "fa-fw", "fa-" + device.icon); + + if (self.config.colored) { + icon.style.cssText = "color: " + device.color; + } + + if (self.config.colored && !self.config.coloredSymbolOnly && device.lastSeen) { + deviceCell.style.cssText = "color: " + device.color; + } + deviceCell.appendChild(icon); deviceCell.innerHTML += device.name; + deviceRow.appendChild(deviceCell); // When last seen - if (self.config.showLastSeen && device.lastSeen) { + 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"); - dateCell.innerHTML = device.lastSeen.fromNow(); + if (typeof device.lastSeen !== 'undefined') { + dateCell.innerHTML = device.lastSeen.fromNow(); + } deviceRow.appendChild(dateCell); } @@ -222,6 +241,12 @@ Module.register("MMM-NetworkScanner", { if (!device.hasOwnProperty("icon")) { device.icon = "question"; } + if (!device.hasOwnProperty("color")) { + device.color = "#ffffff"; + } + if (!device.hasOwnProperty("showOffline")) { + device.showOffline = true; + } if (!device.hasOwnProperty("name")) { if (device.hasOwnProperty("macAddress")) { device.name = device.macAddress; diff --git a/README.md b/README.md index f0cff36..25c1e53 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,11 @@ Add the module to the modules array in the `config/config.js` file: | `occupiedCMD` | `{}` | `optional` the notification to be sent if one of the devices in the `residents` array is found online. See [Notification Example](#notification-example). | | `vacantCMD` | `{}` | `optional` the notification to be sent if **NONE** of the devices in the `residents` array is found online. See [Notification Example](#notification-example). | | `debug` | `false` | `optional` adds extended messages to the log. | +| `color` | `false` | `optional` shows devices in dedicated color defined in the devices section. | +| `coloredSymbolOnly` | `false` | `optional` shows only the devices symbol. | +| `showLastSeenWhenOffline:` | `false` | `optional` show last seen only when offline. | + + #### Device Object The device object contains information about the devices to be found on the network. @@ -68,6 +73,7 @@ The device object contains information about the devices to be found on the netw | `ipAddress` | `optional` the IP address **or** host name of the device. | `192.168.0.1` or `github.com` | | `name` | `optional` the friendly name for the device. If omitted, the `macAddress` or `ipAddress` will be used. | `Phone` or `Router` | | `icon` | `optional` the symbol to show next to the device. See [Font Awesome](http://fontawesome.io/cheatsheet/) cheatsheet. If omitted, `question` will be used. | There are a huge number of icons to choose from. Here are some examples: `globe`, `server`, `desktop`, `laptop`, `mobile`, `wifi`. | +| `color` | `optional` the color the device should be display with. | `#ff0000` for red | **Note** A device object should only contain either a `macAddress` *or* an `ipAddress` **NOT** both.