Skip to content

Commit

Permalink
Merge pull request #40 from ianperrin/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
ianperrin authored Mar 2, 2019
2 parents 7a80ba5 + 06aebbb commit 1f18c2b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 28 additions & 3 deletions MMM-NetworkScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},

Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down

0 comments on commit 1f18c2b

Please sign in to comment.