Skip to content

Commit

Permalink
Merge pull request #311 from Jopyth/develop
Browse files Browse the repository at this point in the history
Version 2.5.0
  • Loading branch information
ezeholz authored Nov 20, 2024
2 parents 32d2d93 + 39f498b commit d836d1f
Show file tree
Hide file tree
Showing 18 changed files with 4,446 additions and 55 deletions.
16 changes: 13 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Thank you for contributing.
We're trying to keep the module up to date and we're adding new features everytime.
# Contributing

Thank you for contributing!

We're trying to keep the module up to date and we're adding new features every time.
Your contribution help us so much in a lot of ways.

We ask you to keep contributing, and feel free to open as many issues and PR as you need.
We ask you to keep contributing, and feel free to open as many issues and PR as you need.

## Developer commands

- `npm run lint` - Run linting checks.
- `npm run lint:fix` - Fix linting issues.
- `npm run test` - Run linting and formatter checks + Run spelling check.
- `npm run test:spelling` - Run spelling check.
30 changes: 30 additions & 0 deletions .github/workflows/automated-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Automated Tests
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]

permissions:
contents: read

jobs:
run-lint:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- run: echo "Starting automated tests for ${{ github.repository }} on ${{ github.ref }}"
- name: Check out repository code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Check spelling
run: npm run test:spelling
- name: Check linting
run: npm run lint
- run: echo "Test job status is ${{ job.status }}."
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ node_modules
# Default settings
settings.json

# Package Lock File
package-lock.json

18 changes: 9 additions & 9 deletions API/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## Introduction

The MMM-Remote-Control Module for MagicMirror² implements a RESTful(-ish) API to control the MagicMirror² using the existing functionality built-in to MMM-Remote-Control, as well as the notifications commands built into most modules. In addition, the API creates a basic framework which allows for each module to expand or customize their own API by a simple notificiation.
The MMM-Remote-Control Module for MagicMirror² implements a RESTful(-ish) API to control the MagicMirror² using the existing functionality built-in to MMM-Remote-Control, as well as the notifications commands built into most modules. In addition, the API creates a basic framework which allows for each module to expand or customize their own API by a simple notification.

This expansion was developed by [shbatm](https://github.com/shbatm) using [juzim's MMM-Api](https://github.com/juzim/MMM-Api) and of-course, [jopyth's MMM-Remote-Control](https://github.com/jopyth/MMM-Remote-Control).

Modified by [ezeholz](https://github.com/ezeholz) in the 2.2.0+, in the efford of making a more simplified version for everyone to use it.
Modified by [ezeholz](https://github.com/ezeholz) in the 2.2.0+, in the effort of making a more simplified version for everyone to use it.

## Overview

Expand Down Expand Up @@ -49,7 +49,7 @@ $ curl -X POST http://magicmirrorip:8080/api/notification/HELLO_WORLD \

Providing an API key is recommended; however, remains optional. If you wish to use an API key to authenticate, add an `apiKey:` option to the config section for this module.

If you ran the `installer.sh` script when you installed the module, a non-canoical UUID is generated for you to use; you can use this unique code, or use any string you wish.
If you ran the `installer.sh` script when you installed the module, a non-canonical UUID is generated for you to use; you can use this unique code, or use any string you wish.

### Example Config Section

Expand Down Expand Up @@ -185,14 +185,14 @@ curl -X GET http://magicmirrorip:8080/api/module/newsfeed

### 3. External APIs (Explicit) - Extending Another Module with this API

For module developers, you can extend the API to accomodate your needs by sending a "REGISTER_API" module notification. Below is an example and details.
For module developers, you can extend the API to accommodate your needs by sending a "REGISTER_API" module notification. Below is an example and details.

If correctly formated, any details sent here will override the "guessed" action by #2 above.
If correctly formatted, any details sent here will override the "guessed" action by #2 above.

```js
let payload = {
module: this.name,
path: "modulename",
path: "mymodulename",
actions: {
actionName: {
method: "GET",
Expand Down Expand Up @@ -220,12 +220,12 @@ this.sendNotification("REGISTER_API", payload);
| `prettyName` | *Optional:* You can specify a Formatted Name to use in dynamic menus, like the MMM-Remote-Control Module Control menu, otherwise one will be guessed based on the Notification text.
| `payload` | *Optional:* If you always want the module to send the same `payload`, you can provide an `Object` here. It will be merged into the `payload` sent with the notification, which will also include:<br>1. URL Parameter, if used. See notes on `payload` Object below.<br>2. Query String, if used. API key will be removed.<br>3. Request body, if `POST` method is used and a body sent.<br>4. Finally, this parameter.

#### About the `payload` Object
#### About the `payload` object

Your module will be sent a `payload` with the notification, depending on the request details, and if you provided a `payload` Object to send. It is a merged object, containing one or more of the following inputs.

1. URL Parameter. (e.g. `/api/module/mymodulename/action/:p`, where `:p` is the parameter). If nothing else below is passed or provided, this will be returned as a string. If anything else below is sent, this will be provided at `payload.param` in the notification's `payload` Object.
2. Query String. Anything passed to the query string, except the API Key (if used) will be passed through `payload`. For example, `/api/module/mymodulename/action?param1=Something&param2=Else` will be passed in `payload` as `{ param1: "Something", param2: "Else" }`
1. URL parameter. (e.g. `/api/module/mymodulename/action/:p`, where `:p` is the parameter). If nothing else below is passed or provided, this will be returned as a string. If anything else below is sent, this will be provided at `payload.param` in the notification's `payload` Object.
2. Query String. Anything passed to the query string, except the API key (if used) will be passed through `payload`. For example, `/api/module/mymodulename/action?param1=Something&param2=Else` will be passed in `payload` as `{ param1: "Something", param2: "Else" }`
3. `POST` Body. Same as query string above.
4. Custom Payload. Any `Object` provided with the `payload:` key when you send the initial "REGISTER_API" notification.

Expand Down
17 changes: 8 additions & 9 deletions API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* By shbatm
* MIT Licensed.
*/
/* jshint node: true, esversion: 6 */

const path = require("path");
const url = require("url");
Expand Down Expand Up @@ -51,7 +50,7 @@ module.exports = {
let getActions = function(content) {
let re = /notification \=\=\=? (?:"|')([A-Z_-]+?)(?:"|')|case (?:"|')([A-Z_-]+)(?:"|')/g;

Check warning on line 51 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unnecessary escape character: \=

Check warning on line 51 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unnecessary escape character: \=

Check warning on line 51 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

Unnecessary escape character: \=
let m;

Check warning on line 52 in API/api.js

View workflow job for this annotation

GitHub Actions / run-lint

'm' is defined but never used
let availabeActions = [];
let availableActions = [];
if (re.test(content)) {
content.match(re).forEach((match) => {
let n = match.replace(re, '$1');
Expand All @@ -62,11 +61,11 @@ module.exports = {
'KEYPRESS_MODE_CHANGED',
'USER_PRESENCE'
].indexOf(n) === -1) {
availabeActions.push(n);
availableActions.push(n);
}
});
}
return availabeActions;
return availableActions;
};

let skippedModules = ['clock', 'compliments', 'MMM-Remote-Control'];
Expand Down Expand Up @@ -118,7 +117,7 @@ module.exports = {
// Route for testing the api at http://mirror:8080/api/test
this.expressRouter.route(['/test','/']) // Test without apiKey
.get((req, res) => {
if (!this.checkInititialized(res)) { return; }
if (!this.checkInitialized(res)) { return; }
res.json({ success: true });
});

Expand Down Expand Up @@ -291,7 +290,7 @@ module.exports = {
actionName = req.body.monitor.toUpperCase();
}
} else {
var actionName = req.params.action ? req.params.action.toUpperCase() : "STATUS";
actionName = req.params.action ? req.params.action.toUpperCase() : "STATUS";
}
this.executeQuery(this.checkDelay({ action: `MONITOR${actionName}` }, req), res);
});
Expand Down Expand Up @@ -342,7 +341,7 @@ module.exports = {
},

answerModuleApi(req, res) {
if (!this.checkInititialized(res)) { return; }
if (!this.checkInitialized(res)) { return; }
var dataMerged = this.mergeData().data

if (!req.params.moduleName) {
Expand Down Expand Up @@ -427,7 +426,7 @@ module.exports = {
}
// If only a URL Parameter is passed, it will be sent as a string
// If we have either a query string or a payload already provided w the action,
// then the paramteter will be inside the payload.param property.
// then the parameter will be inside the payload.param property.
delete req.query.apiKey;
let query = { notification: n };
if (req.params.p && req.params.p === "delay") {
Expand Down Expand Up @@ -478,7 +477,7 @@ module.exports = {
return;
},

checkInititialized(res) {
checkInitialized(res) {
if (!this.initialized) {
this.sendResponse(res, "Not initialized, have you opened or refreshed your browser since the last time you started MagicMirror²?");
return false;
Expand Down
25 changes: 17 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](https://keepachangelog.com/)
and this project adheres to [Semantic Versioning](https://semver.org/).

## [2.5.0] - 2024-11-20

### Added

- Added a spell checker and fixed problems that were found (#308).
- Added JavaScript linting (for the start with soft rules) (#310).
- Added GitHub workflow for linting and spell checking on every push and pull request (#310).
- Added Turkish language (#305)

## [2.4.0] - 2024-10-08

Expand Down Expand Up @@ -120,7 +129,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Updates now show if there's an update available every day (#52)
- Templates for issues and PRs, and also stale for automanagement of issues.
- Templates for issues and PRs, and also stale for auto management of issues.
- Close Dev Tools (#119)
- Undo Config Implementation [Beta]
- Classes to show, hide or toggle multiple modules at once (#34)
Expand Down Expand Up @@ -150,7 +159,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.1.0] - 2020-11-01

Hello! Ezequiel here. Just wanted to say thanks for trust in me, in the past days I made a lot of changes into the code, adding some functions that'll surely be in a future release, and also putting everything together in my fork. I answered almost every issue raised, and tried to help every person that use this module. Today, I'm glad to be able to share everything I learned to all of you. I apologize for some fast and uncommented commits, I just thinked that some things needed to be fixed ASAP.
Hello! Ezequiel here. Just wanted to say thanks for trust in me, in the past days I made a lot of changes into the code, adding some functions that'll surely be in a future release, and also putting everything together in my fork. I answered almost every issue raised, and tried to help every person that use this module. Today, I'm glad to be able to share everything I learned to all of you. I apologize for some fast and uncommented commits, I just thought that some things needed to be fixed ASAP.
See you in future commits, issues and PRs :D

### Fixed
Expand All @@ -162,7 +171,7 @@ See you in future commits, issues and PRs :D
- IP now showing (#194)
- MM restart button don't just stop anymore (#126)
- Saving config should work as expected now (#153)
- installer.sh now detects where's the node instalation (#222)
- installer.sh now detects where's the node installation (#222)

### Added

Expand All @@ -178,7 +187,7 @@ See you in future commits, issues and PRs :D

## [2.0.1] - 2020-10-28

**Huge thanks to [@ezeholz](https://github.com/ezeholz)** who has offered to maintain the module fron now on!
**Huge thanks to [@ezeholz](https://github.com/ezeholz)** who has offered to maintain the module from now on!
Credit for this (and future) versions and releases goes to @ezeholz (unless noted otherwise).

Now requires MagicMirror² version 2.7.
Expand All @@ -191,7 +200,7 @@ Now requires MagicMirror² version 2.7.

## [2.0.0] - 2019-02-21

Huge shoutout to [shbatm](https://github.com/shbatm) for his work on this new major version, which brings a new API, custom menus and commands and lots of other stuff:
Huge shout out to [shbatm](https://github.com/shbatm) for his work on this new major version, which brings a new API, custom menus and commands and lots of other stuff:

### Added

Expand Down Expand Up @@ -307,7 +316,7 @@ Huge shoutout to [shbatm](https://github.com/shbatm) for his work on this new ma
- Menu to change the `config.js`
- Modules can be installed, added, removed, configured
- There will be backups of the five last versions of the `config.js` in the `config` folder
- Some of these parts are hidden behind an "exprimental" warning, do **not** ignore that warning
- Some of these parts are hidden behind an "experimental" warning, do **not** ignore that warning
- NOTIFICATION action, see [README.md](README.md#notification-request) for details

### Changed
Expand Down
2 changes: 0 additions & 2 deletions MMM-Remote-Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* MIT Licensed.
*/

/* jshint esversion:6 */

Module.register("MMM-Remote-Control", {

requiresVersion: "2.12.0",
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This module for the [MagicMirror²](https://github.com/MagicMirrorOrg/MagicMirror) allows you to quickly shutdown your mirror through a web browser.
The website should work fine on any device (desktop, smart phone, tablet, ...).
Since we all want our [SD cards to live a long and prosper life](http://raspberrypi.stackexchange.com/a/383) we properly shut down before pulling the power plug everytime, am I right?
Since we all want our [SD cards to live a long and prosper life](http://raspberrypi.stackexchange.com/a/383) we properly shut down before pulling the power plug every time, am I right?
Additionally you can hide and show modules on your mirror and do other cool stuff.

![The Main Menu](.github/main.png)
Expand Down Expand Up @@ -55,7 +55,7 @@ npm install

- (3) For security reasons, the MagicMirror² (and therefore the Remote Control) is *not* reachable externally.
To change this, configure `address`, and `ipWhitelist` in your `config.js` (see [these lines in the sample config](https://github.com/MagicMirrorOrg/MagicMirror/blob/master/config/config.js.sample#L12-L22)).
For example change `address` to `0.0.0.0` and add two allowed devices with IP-Adresses `192.168.0.42` and `192.168.0.50`:
For example change `address` to `0.0.0.0` and add two allowed devices with IP addresses `192.168.0.42` and `192.168.0.50`:

```js
address : '0.0.0.0',
Expand Down Expand Up @@ -122,7 +122,7 @@ If this happens, simply reconfigure and save it again.
## Call methods from other modules
You can call any of the methods provided in the UI directly through a GET request, or a module notification.
For example you can use [MMM-ModuleScheduler](https://forum.magicmirror.builders/topic/691/mmm-modulescheduler) to automatically shutdown your RasberryPi at a certain time, or integrate it with home automation systems. Or use [MMM-Navigate](https://github.com/Ax-LED/MMM-Navigate) to allow direct actions from your Mirror by using a rotating button.
For example you can use [MMM-ModuleScheduler](https://forum.magicmirror.builders/topic/691/mmm-modulescheduler) to automatically shutdown your RaspberryPi at a certain time, or integrate it with home automation systems. Or use [MMM-Navigate](https://github.com/Ax-LED/MMM-Navigate) to allow direct actions from your Mirror by using a rotating button.
### Examples
Expand Down Expand Up @@ -177,7 +177,7 @@ See some specific examples for controlling your mirror from other modules and ad
| :-: | ------------- |
| HIDE | Hide a module, with the name (or identifier--see `MODULE_DATA` action) specified by `module` in the payload. You can also send `module: "all"` to hide all modules. |
| SHOW | Show a module (see above for how to specify which one). |
| TOGGLE | Toggle a module's visiblity (see above for how to specify which one). |
| TOGGLE | Toggle a module's visibility (see above for how to specify which one). |
| FORCE | Force a module to show (see above for how to specify which one). |
| MODULE_DATA | Returns a JSON format of the data displayed in the UI, including all valid identifiers for the `HIDE` and `SHOW` action. |
Expand Down Expand Up @@ -243,7 +243,7 @@ Depending on your installation, some `shell` commands used by this module are no
### Custom Classes
You probably wanna hide or show some modules at the same time, right? It's everything that we want this module for, of course.
Well, now you can add as many classes as you like, and define whether they show themself, hide or toggle between the two stages!
Well, now you can add as many classes as you like, and define whether they show themselves, hide or toggle between the two stages!
```js
classes: {
Expand Down
77 changes: 77 additions & 0 deletions cspell.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"version": "0.2",
"language": "en",
"words": [
"apikey",
"articlelessdetails",
"articlemoredetails",
"articlenext",
"articleprevious",
"articlescrollup",
"articletogglefull",
"Ausschalten",
"Bethge",
"bokmål",
"cambio",
"chlog",
"defaultmodules",
"Energieoptionen",
"extdocs",
"ezeholz",
"Ezequiel",
"Flickr",
"FULLSCREEN",
"HIDEALERT",
"HIDEALL",
"jopyth",
"juzim",
"kapsolas",
"Keyport",
"khassel",
"Kristjan",
"kvpairs",
"listname",
"LOCKSTRING",
"lockstrings",
"longname",
"MODULEAPI",
"MONITOROFF",
"MONITORON",
"MONITORSTATUS",
"MONITORTIMED",
"MONITORTOGGLE",
"mymodulename",
"mypayload",
"Mysh",
"navicon",
"newsfeed",
"newsitems",
"Norsk",
"plusplus",
"REFRESHMM",
"remotecontrol",
"RESTARTMM",
"revparse",
"SENDALERT",
"shbatm",
"showalert",
"SHOWALL",
"somthingelse",
"TOGGLEFULLSCREEN",
"UPDATEMM",
"userpresence",
"vcgencmd",
"Wooo",
"xsmall",
"YOURAPIKEY"
],
"ignorePaths": [
"modules.json",
"node_modules/**",
"translations/**",
"*.min.js"
],
"dictionaries": [
"node"
]
}
Loading

0 comments on commit d836d1f

Please sign in to comment.