Skip to content

Commit

Permalink
Merge pull request #7 from Tom-Hirschberger/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Tom-Hirschberger authored Nov 24, 2023
2 parents 5a71285 + 4f56b74 commit 7d08034
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 12 deletions.
5 changes: 3 additions & 2 deletions MMM-CommandToNotification.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global Module
/* Magic Mirror²
/* MagicMirror²
* Module: CommandToNotification
*
* By Tom Hirschberger
Expand All @@ -11,7 +11,8 @@ Module.register('MMM-CommandToNotification', {
defaults: {
updateInterval: 30,
commands: [],
sync: true
sync: true,
debug: false
},

start: function () {
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ Add the following code to your ~/MagicMirror/config/config.js:
| updateInterval | How often should the scripts be iterated (in seconds) | Integer | 30 |
| commands | A array containing the command definition objects | Array | [] |
| sync | Should the commands called one by one (true) or should all be started as fast as possible (false). Can be overriden for each command in the command configuration | Boolean | true |
| debug | This flag controls if debug messages should be output on the console | Boolean | false |

### Commands

| Option | Description | Mandatory | Type | Default |
| ------- | --- | --- | --- | --- |
| script | Either a absolute path or the realtive path of a script starting at the "scripts" directory | true | String | null |
| script | Either a absolute path or the realtive path of a script starting at the "scripts" directory. Make sure to add a "./" as prefix if you call a script in the "scripts" directory. | true | String | null |
| args | Arguments which should be passed to the script | false | String | "" |
| timeout | Should the script be killed if it does not return within a specific amount of milliseconds? | false | Integer | infinity |
| notifications | A array containing names of the notifications to send if script returns output. If not present the script gets called but no notification will be send. If you want to override the payload instead of using the output please look at the notification section. | false | Array | [] |
Expand All @@ -51,8 +52,8 @@ Add the following code to your ~/MagicMirror/config/config.js:
### Notifications

The notifications array contains all notifications that should be send if a command is called (and the conditions matched).
There may be situations where you want send a notification with a specific payload instead of the output of the script. You can do so if you specify a array instead of the string identifiying the notification.
Lets see the following example:
There may be situations where you want send a notification with a specific payload instead of the output of the script. You can do so if you specify a array instead of the string identifiying the notification.
Lets see the following example:

```json
notifications: [
Expand Down Expand Up @@ -85,6 +86,7 @@ Add the following example to produce the following result:
* the script calculates a random number between -50 and 20 and produces a json object containing two values ("integer" and "float"). The float value is the random number the integer value the random number rounded as integer.
* the timeout of the script is set to 10 seconds
* the result of the script (JSON object as string) will be send as payload of notification TEST3 while TEST4 will be send with payload "true"
* As the condition `returnCode` is set to `[0,1,2]` the notifications `TEST3` and `TEST4` only will be send if the script `./randomNumberJson.js` only will be send if the script exits with code 0, 1 or 2

```json5
{
Expand All @@ -107,6 +109,9 @@ Add the following example to produce the following result:
args: "-50 20",
skips: 3,
timeout: 10,
conditions: {
returnCode: [0,1,2]
}
notifications: [
"TEST3",
["TEST4", true]
Expand All @@ -116,3 +121,7 @@ Add the following example to produce the following result:
},
},
```

#### My Prusa MK4 3D-Printer setup

<img src="examples/exampleSetup.png" alt="Curl->MMM-CommandToNotification->MMM-ValuesByNotification" width="600px"/>
Binary file added examples/bash-curl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/exampleSetup.odg
Binary file not shown.
Binary file added examples/exampleSetup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/module-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/vbn-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Magic Mirror²
/* MagicMirror²
* Module: CommandToNotification
*
* By Tom Hirschberger
Expand Down Expand Up @@ -187,10 +187,13 @@ module.exports = NodeHelper.create({

postProcessCommand: function(cmdIdx, curCmdConfig, curNotifications, output, returnCode){
const self = this
// console.log("Postprocessing cmdIdx: "+cmdIdx)
console.log("curCmdConfig: "+JSON.stringify(curCmdConfig))
// console.log(output)
// console.log(returnCode)
if (self.config.debug){
console.log("Postprocessing cmdIdx: "+cmdIdx)
console.log("curCmdConfig: "+JSON.stringify(curCmdConfig))
console.log(output)
console.log(returnCode)
}

if(output !== null){
if (typeof curNotifications !== "undefined"){
if (self.validateConditions(curCmdConfig, output, returnCode)){
Expand Down
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{
"name": "MMM-CommandToNotification",
"version": "0.0.5",
"description": "",
"version": "0.0.6",
"description": "A MagicMirror² module which calls system-commands or scripts periodically and sends the output as notifications.",
"main": "MMM-CommandToNotification",
"dependencies": {},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git@github.com:Tom-Hirschberger/MMM-CommandToNotification.git"
},
"keywords": [
"MagicMirror",
"MM",
"scripts",
"commands",
"notifications",
"conditional",
"temperature",
"humidity",
"environment",
"sensors"
],
"author": "Thomas Hirschberger",
"license": "MIT",
"bugs": {
Expand Down
11 changes: 11 additions & 0 deletions scripts/dummy.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
fp=$(readlink -f $0)
d=$(dirname $fp)
cf="$d/dummy.content"
if [ "$1" != "" ]
then
cf="$1"
fi

cat "$cf"
exit 0
7 changes: 7 additions & 0 deletions scripts/dummy.content
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"test_data": {
"temp": -10.0123,
"humidity": 50.4567,
"test_string:": "this is a test"
}
}

0 comments on commit 7d08034

Please sign in to comment.