Skip to content

Commit

Permalink
Merge pull request #14 from fewieden/develop
Browse files Browse the repository at this point in the history
2.1.0
  • Loading branch information
fewieden authored Feb 13, 2022
2 parents 78eea33 + ecca4be commit c00d147
Show file tree
Hide file tree
Showing 14 changed files with 819 additions and 1,760 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ engines:
enabled: true
config:
languages:
- javascript
- javascript
eslint:
enabled: true
channel: "eslint-6"
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sourceType": "module"
},
"settings": {
"import/core-modules": [ "node_helper" ]
"import/core-modules": ["logger", "node_helper"]
},
"env": {
"browser": true,
Expand Down
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Thanks for contributing to this module!

Please create pull requests to the branch `develop`.
Please create pull requests towards the branch `develop`.

To hold one code style and standard there are several linters and tools in this project set. Make sure you fulfill the requirements.
Also, there will be automatically analysis performed once you created the pull request.
To hold one code style and standard there are several linters and tools in this project configured. Make sure you fulfill the requirements.
Also, there will be an automatic analysis performed once you create the pull request.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github: fewieden
custom: ['https://paypal.me/fewieden']
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Please create pull requests to the branch `develop`.
Please create pull requests towards the branch `develop`.

* Does the pull request solve an issue (add a reference)?
* What are the features of this pr?
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 16.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
15 changes: 15 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: changelog

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dangoslen/[email protected]
with:
changeLogPath: CHANGELOG.md
skipLabels: Skip Changelog
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# MMM-ip Changelog

## [2.1.0]

MagicMirror² version >= 2.15.0 required.

### Added

* Added config option `updateInterval`
* Github actions

### Changed

* Node helper logs are now done through MagicMirror logger
* Github config files

### Removed

* Travis-CI integration

## [2.0.0]

### Added
Expand Down
34 changes: 9 additions & 25 deletions MMM-ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @see https://github.com/fewieden/MMM-ip
*/

/* global Module Log */

/**
* @external Module
* @see https://github.com/MichMich/MagicMirror/blob/master/js/module.js
Expand Down Expand Up @@ -54,7 +56,8 @@ Module.register('MMM-ip', {
fontSize: 9,
dimmed: true,
types: ['eth0', 'wlan0'],
families: ['IPv4', 'IPv6']
families: ['IPv4', 'IPv6'],
updateInterval: 5 * 60 * 1000 // every 5 minutes
},

/**
Expand Down Expand Up @@ -106,7 +109,7 @@ Module.register('MMM-ip', {
start() {
Log.info(`Starting module: ${this.name}`);
this.addGlobals();
this.sendSocketNotification('GET_NETWORK_INTERFACES');
this.sendSocketNotification('CONFIG', this.config);
},

/**
Expand Down Expand Up @@ -164,7 +167,6 @@ Module.register('MMM-ip', {
if (/(HIDE)/g.test(data) && !/(SHOW)/g.test(data)) {
this.sendNotification('CLOSE_MODAL');
} else if (/(SHOW)/g.test(data) && !/(HIDE)/g.test(data)) {
console.log(this.interfaces);
this.sendNotification('OPEN_MODAL', {
template: 'templates/InterfaceModal.njk',
data: {
Expand Down Expand Up @@ -207,7 +209,6 @@ Module.register('MMM-ip', {
socketNotificationReceived(notification, payload) {
if (notification === 'NETWORK_INTERFACES') {
this.interfaces = payload;
Log.info('interfaces', payload);
this.updateDom(300);
}
},
Expand All @@ -220,27 +221,10 @@ Module.register('MMM-ip', {
*
* @returns {string} Mac address or empty string.
*/
getMacAddress(array= []) {
for (const item of array) {
if (item.mac) {
return `(MAC: ${item.mac})`;
}
}

return '';
},
getMacAddress(array = []) {
const itemWithMacAddress = array.find(item => item.mac);

/**
* @function includes
* @description Helper function to check if item is included in the array.
*
* @param {string[]} array - Array of texts.
* @param {string} item - Text that should be checked for.
*
* @returns {boolean} Is the item included in the array?
*/
includes(array= [], item) {
return array.includes(item);
return itemWithMacAddress ? `(MAC: ${itemWithMacAddress.mac})` : '';
},

/**
Expand All @@ -250,6 +234,6 @@ Module.register('MMM-ip', {
* @returns {void}
*/
addGlobals() {
this.nunjucksEnvironment().addGlobal('includes', this.includes);
this.nunjucksEnvironment().addGlobal('includes', (array = [], item) => array.includes(item));
}
});
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MMM-ip [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-ip/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-ip.svg?branch=master)](https://travis-ci.org/fewieden/MMM-ip) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-ip/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-ip) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-ip/badge.svg)](https://snyk.io/test/github/fewieden/mmm-ip)
# MMM-ip [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-ip/master/LICENSE) ![Build status](https://github.com/fewieden/MMM-ip/workflows/build/badge.svg) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-ip/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-ip) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-ip/badge.svg)](https://snyk.io/test/github/fewieden/mmm-ip)

IPv4/IPv6 Network Address Module for MagicMirror<sup>2</sup>

Expand Down Expand Up @@ -34,6 +34,7 @@ IPv4/IPv6 Network Address Module for MagicMirror<sup>2</sup>
| `dimmed` | `true` | Boolean for discrete visibility |
| `families` | `['IPv4', 'IPv6']` | Array of network address families to display. Possible values in the array are: `'IPv4'` and `'IPv6'`. |
| `types` | `['eth0', 'wlan0']` | Array of network interface types to display. Check the types of your network cards in the logs. They get logged on MagicMirror start. |
| `updateInterval` | `300000` (5 mins) | How often should the network interface list be updated in milliseconds? |

## OPTIONAL: Voice Control and Modal

Expand All @@ -50,3 +51,8 @@ The voice control mode for this module is `NETWORK`
* CLOSE HELP -> Hides the help information.
* SHOW INTERFACES -> Shows network interfaces based on config options with mac addresses.
* HIDE INTERFACES -> Hide network interfaces.

## Developer

* `npm run lint` - Lints JS and CSS files.
* `npm run docs` - Generates documentation.
38 changes: 26 additions & 12 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,44 @@
* @see https://github.com/fewieden/MMM-ip
*/

/**
* @external os
* @see https://nodejs.org/api/os.html
*/
const os = require('os');

/**
* @external node_helper
* @see https://github.com/MichMich/MagicMirror/blob/master/modules/node_modules/node_helper/index.js
*/
const NodeHelper = require('node_helper');

/**
* @external os
* @see https://nodejs.org/api/os.html
* @external logger
* @see https://github.com/MichMich/MagicMirror/blob/master/js/logger.js
*/
const interfaces = require('os').networkInterfaces();
const Log = require('logger');

/**
* @module node_helper
* @description Backend for the module to get information about the network interfaces of the computer.
*
* @requires external:os
* @requires external:node_helper
* @requires external:logger
*/
module.exports = NodeHelper.create({
/** @member {string} requiresVersion - Defines the minimum version of MagicMirror to run this node_helper. */
requiresVersion: '2.15.0',

/**
* @function start
* @description Logs a start message to the console.
* @override
* @function getNetworkInterfaces
* @description Returns network interfaces from the computer.
*
* @returns {void}
* @returns {object[]} List of network interfaces.
*/
start() {
console.log(`Starting module helper: ${this.name}`);
console.log(`Available network interface types: ${Object.keys(interfaces).join(', ')}`);
getNetworkInterfaces() {
return os.networkInterfaces();
},

/**
Expand All @@ -48,9 +56,15 @@ module.exports = NodeHelper.create({
*
* @returns {void}
*/
socketNotificationReceived(notification) {
if (notification === 'GET_NETWORK_INTERFACES') {
socketNotificationReceived(notification, payload) {
if (notification === 'CONFIG') {
const interfaces = this.getNetworkInterfaces();
Log.info(`Available network interface types: ${Object.keys(interfaces).join(', ')}`);
this.sendSocketNotification('NETWORK_INTERFACES', interfaces);

setInterval(() => {
this.sendSocketNotification('NETWORK_INTERFACES', this.getNetworkInterfaces());
}, payload.updateInterval);
}
}
});
Loading

0 comments on commit c00d147

Please sign in to comment.