Skip to content

Commit deab5b1

Browse files
Merge pull request #15 from Tom-Hirschberger/development
Development
2 parents c2cb7b6 + 0c59039 commit deab5b1

11 files changed

+296
-274
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package.json
12
package-lock.json
23
*.js
34
*.mjs

.prettierrc.json

-3
This file was deleted.

.stylelintrc.json

-7
This file was deleted.

MMM-CommandToNotification.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* MagicMirror²
2-
* Module: CommandToNotification
2+
* Module: MMM-CommandToNotification
33
*
44
* By Tom Hirschberger
55
* MIT Licensed.

README.md

+74-63
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,70 @@
22

33
MagicMirror² module which periodically calls configured scripts and sends the output as value of configurable notifications. The values can be displayed in modules like [MMM-ValuesByNotification](https://github.com/Tom-Hirschberger/MMM-ValuesByNotification).
44

5-
Example scripts to read the temperature values of DHT11, DHT22, DS18B20, HTU21, SHT31d, SHTC3 or BME280 connected to the raspbarry or Miflora sensors in reach of bluetooth are included in the scripts directory. There is a documentation in the [scripts directory](./scripts/README.md), too.
5+
Example scripts to read the temperature values of DHT11, DHT22, DS18B20, HTU21, SHT31d, SHTC3 or BME280 connected to the raspbarry or Miflora sensors in reach of bluetooth are included in the scripts directory. There is a documentation in the [scripts directory](./scripts/README.md), too.
66

7-
## Basic installation
7+
## Installation
88

99
```bash
1010
cd ~/MagicMirror/modules
1111
git clone https://github.com/Tom-Hirschberger/MMM-CommandToNotification
12-
cd MMM-CommandToNotification
13-
npm install
12+
```
13+
14+
## Update
15+
16+
Just enter the module's directory, pull the update:
17+
18+
```bash
19+
cd ~/MagicMirror/modules/MMM-CommandToNotification
20+
git pull
1421
```
1522

1623
## Basic configuration
1724

1825
Add the following code to your ~/MagicMirror/config/config.js:
1926

20-
```json5
27+
```js
2128
{
22-
module: "MMM-CommandToNotification",
23-
disabled: false,
24-
config: {
25-
commands: [
26-
]
27-
},
29+
module: "MMM-CommandToNotification",
30+
config: {
31+
commands: [
32+
]
33+
},
2834
},
2935
```
3036

3137
### General
3238

39+
<!-- prettier-ignore-start -->
3340
| Option | Description | Type | Default |
34-
| ------- | --- | --- | --- |
41+
| ------- | ----------- | ---- | ------- |
3542
| updateInterval | How often should the scripts be iterated (in seconds) | Integer | 30 |
3643
| commands | A array containing the command definition objects | Array | [] |
3744
| 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 |
3845
| debug | This flag controls if debug messages should be output on the console | Boolean | false |
46+
<!-- prettier-ignore-end -->
3947

4048
### Commands
4149

50+
<!-- prettier-ignore-start -->
4251
| Option | Description | Mandatory | Type | Default |
43-
| ------- | --- | --- | --- | --- |
52+
| ------- | ----------- | --------- | ---- | ------- |
4453
| script | Either a absolute path or the realtive path of a script starting at the "scripts" directory. | true | String | null |
4554
| args | Arguments which should be passed to the script | false | String | "" |
4655
| timeout | Should the script be killed if it does not return within a specific amount of milliseconds? | false | Integer | infinity |
4756
| 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 | [] |
48-
| sync | Should the command by run synchronous (next command will be called after this one, true) or asynchronous (directly proceed with the next one and process output when the command finishes, false) | Boolean | true |
49-
| delayNext | Wait some amount of time (milliseconds) before the next command will be processed after this one has called. Make sure to set to updateInterval of the module to a value that is enough time to call and process all commands with all delays summed up! | Integer | 0 |
57+
| sync | Should the command by run synchronous (next command will be called after this one, true) or asynchronous (directly proceed with the next one and process output when the command finishes, false) | Boolean | false | true |
58+
| delayNext | Wait some amount of time (milliseconds) before the next command will be processed after this one has called. Make sure to set to updateInterval of the module to a value that is enough time to call and process all commands with all delays summed up! | false | Integer | 0 |
5059
| conditions | A map containing conditions that need to match to send the notifications | false | Map | null |
60+
<!-- prettier-ignore-end -->
5161

5262
### Notifications
5363

5464
The notifications array contains all notifications that should be send if a command is called (and the conditions matched).
5565
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.
5666
Lets see the following example:
5767

58-
```json
68+
```js
5969
notifications: [
6070
["TEST1","MY_NEW_PAYLOAD"],
6171
"TEST2",
@@ -68,57 +78,58 @@ In this example the notification "TEST1" will have "MY_NEW_PAYLOAD" as output wh
6878

6979
**All conditions specified need to match to send notifications!**
7080

71-
| Option | Description | Type | Default |
72-
| ------- | --- | --- | --- |
81+
<!-- prettier-ignore-start -->
82+
| Option | Description | Type | Default |
83+
| -------| ----------- | -----| ------- |
7384
| returnCode | Specify either a single return code or a array of return codes that need to match. If a array is specified one of the values need to match (or condition). | Integer or Array of Integer | null |
74-
| outputContains | Specify either a single string or a array of possible strings which of one need to be present in the output (or condition). | null |
85+
| outputContains | Specify either a single string or a array of possible strings which of one need to be present in the output (or condition). | Integer or Array of Integer | null |
86+
<!-- prettier-ignore-end -->
7587

7688
### Example
7789

7890
Add the following example to produce the following result:
7991

80-
* the scripts will be iterated every 10 seconds
81-
* the script "scripts/randomInteger.js" gets called every iteration
82-
* a random number between -10 and 10 is produced
83-
* the timeout of the script is 5 seconds. If the script does not produce any output within 5 seconds the call will be aborted and no notifications will be send
84-
* if the script produces output the output will be send as payload of the notifications TEST1 and TEST2
85-
* the script "scripts/randomNumberJson.js" will be called every fourth iteration because a three skips are configured
86-
* 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.
87-
* the timeout of the script is set to 10 seconds
88-
* 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"
89-
* 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
90-
91-
```json5
92+
- the scripts will be iterated every 10 seconds
93+
- the script "scripts/randomInteger.js" gets called every iteration
94+
- a random number between -10 and 10 is produced
95+
- the timeout of the script is 1000 milliseconds. If the script does not produce any output within 1000 milliseconds the call will be aborted and no notifications will be send
96+
- if the script produces output the output will be send as payload of the notifications TEST1 and TEST2
97+
- the script "scripts/randomNumberJson.js" will be called every fourth iteration because a three skips are configured
98+
- 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.
99+
- the timeout of the script is set to 2000 milliseconds
100+
- 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"
101+
- 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
102+
103+
```js
92104
{
93-
module: "MMM-CommandToNotification",
94-
disabled: false,
95-
config: {
96-
updateInterval: 10,
97-
commands: [
98-
{
99-
script: "./randomInteger.js",
100-
args: "-10 10",
101-
timeout: 5,
102-
notifications: [
103-
"TEST1",
104-
"TEST2",
105-
],
106-
},
107-
{
108-
script: "./randomNumberJson.js",
109-
args: "-50 20",
110-
skips: 3,
111-
timeout: 10,
112-
conditions: {
113-
returnCode: [0,1,2]
114-
}
115-
notifications: [
116-
"TEST3",
117-
["TEST4", true]
118-
],
119-
}
120-
]
121-
},
105+
module: "MMM-CommandToNotification",
106+
config: {
107+
updateInterval: 10,
108+
commands: [
109+
{
110+
script: "./randomInteger.js",
111+
args: "-10 10",
112+
timeout: 1000,
113+
notifications: [
114+
"TEST1",
115+
"TEST2",
116+
],
117+
},
118+
{
119+
script: "./randomNumberJson.js",
120+
args: "-50 20",
121+
skips: 3,
122+
timeout: 2000,
123+
conditions: {
124+
returnCode: [0,1,2]
125+
},
126+
notifications: [
127+
"TEST3",
128+
["TEST4", true]
129+
],
130+
}
131+
]
132+
},
122133
},
123134
```
124135

@@ -128,6 +139,6 @@ Add the following example to produce the following result:
128139

129140
## Developer commands
130141

131-
* `npm install` - Install devDependencies like ESLint.
132-
* `npm run lint` - Run linting and formatter checks.
133-
* `npm run lint:fix` - Fix linting and formatter issues.
142+
- `npm install` - Install devDependencies like ESLint.
143+
- `npm run lint` - Run linting and formatter checks.
144+
- `npm run lint:fix` - Fix linting and formatter issues.

eslint.config.mjs

+36-11
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,42 @@ import globals from "globals"
44

55
const config = [
66
{
7-
files: ["**/*.js", "**/*.mjs"],
8-
},
9-
{
10-
ignores: ["**/doc/configs/webcam-config.js"],
11-
},
12-
{
7+
files: ["**/*.js"],
138
languageOptions: {
149
globals: {
1510
...globals.browser,
1611
...globals.node,
1712
Log: "readonly",
1813
Module: "readonly",
1914
},
15+
sourceType: "commonjs"
2016
},
2117
plugins: {
2218
...eslintPluginStylistic.configs["recommended-flat"].plugins,
2319
},
2420
rules: {
2521
...eslintPluginJs.configs.all.rules,
2622
...eslintPluginStylistic.configs["recommended-flat"].rules,
27-
"@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }],
23+
"@stylistic/brace-style": ["error", "1tbs", {allowSingleLine: true}],
2824
"@stylistic/comma-dangle": ["error", "only-multiline"],
2925
"@stylistic/indent": ["error", "tab"],
30-
"@stylistic/max-statements-per-line": ["error", { max: 2 }],
26+
"@stylistic/max-statements-per-line": ["error", {max: 2}],
3127
"@stylistic/no-tabs": "off",
3228
"@stylistic/quotes": ["error", "double"],
3329
"capitalized-comments": "off",
34-
"complexity": "off",
30+
complexity: "off",
3531
"consistent-this": "off",
36-
"eqeqeq": "warn",
32+
eqeqeq: "warn",
3733
"init-declarations": "off",
3834
"max-depth": "off",
3935
"max-lines": "off",
4036
"max-lines-per-function": "off",
4137
"max-params": "off",
42-
"max-statements": ["error", { max: 80 }],
38+
"max-statements": ["error", {max: 80}],
4339
"no-else-return": "off",
4440
"no-eq-null": "warn",
41+
"no-await-in-loop": "warn",
42+
"no-compare-neg-zero": "warn",
4543
"no-inline-comments": "off",
4644
"no-magic-numbers": "off",
4745
"no-negated-condition": "off",
@@ -51,7 +49,34 @@ const config = [
5149
"one-var": "off",
5250
"prefer-destructuring": "off",
5351
"sort-keys": "off",
52+
strict: "off",
53+
}
54+
},
55+
{
56+
files: ["**/*.mjs"],
57+
languageOptions: {
58+
globals: {
59+
...globals.node
60+
},
61+
sourceType: "module"
62+
},
63+
plugins: {
64+
...eslintPluginStylistic.configs["all-flat"].plugins
5465
},
66+
rules: {
67+
...eslintPluginStylistic.configs["all-flat"].rules,
68+
"@stylistic/array-element-newline": "off",
69+
"@stylistic/comma-dangle": ["error", "only-multiline"],
70+
"@stylistic/indent": ["error", "tab"],
71+
"@stylistic/object-property-newline": "off",
72+
"@stylistic/padded-blocks": ["error", "never"],
73+
"@stylistic/quote-props": ["error", "as-needed"],
74+
"@stylistic/semi": ["error", "never"],
75+
"func-style": "off",
76+
"max-lines-per-function": ["error", 100],
77+
"no-magic-numbers": "off",
78+
"one-var": "off"
79+
}
5580
}
5681
]
5782

node_helper.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
const Log = require("logger")
88
const NodeHelper = require("node_helper")
99

10-
const spawnSync = require("child_process").spawnSync
11-
const spawn = require("child_process").spawn
12-
const fs = require("fs")
13-
const path = require("path")
10+
const spawnSync = require("node:child_process").spawnSync
11+
const spawn = require("node:child_process").spawn
12+
const fs = require("node:fs")
13+
const path = require("node:path")
1414
const scriptsDir = path.join(__dirname, "/scripts")
1515

1616
module.exports = NodeHelper.create({
@@ -24,8 +24,7 @@ module.exports = NodeHelper.create({
2424
},
2525

2626
sleep(milliseconds) {
27-
// eslint-disable-next-line no-promise-executor-return
28-
return new Promise(resolve => setTimeout(resolve, milliseconds))
27+
return new Promise((resolve) => { setTimeout(resolve, milliseconds) })
2928
},
3029

3130
// https://stackoverflow.com/questions/14332721/node-js-spawn-child-process-and-get-terminal-output-live
@@ -237,7 +236,6 @@ module.exports = NodeHelper.create({
237236
if (self.config.debug) {
238237
Log.log(`${self.name}: Delaying next: ${curCmdConfig.delayNext}`)
239238
}
240-
// eslint-disable-next-line no-await-in-loop
241239
await self.sleep(curCmdConfig.delayNext)
242240
}
243241
} else {

package.json

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
{
2-
"name": "MMM-CommandToNotification",
3-
"version": "0.0.8",
2+
"name": "mmm-commandtonotification",
3+
"version": "0.0.9",
44
"description": "A MagicMirror² module which calls system-commands or scripts periodically and sends the output as notifications.",
5-
"main": "MMM-CommandToNotification",
6-
"dependencies": {},
5+
"main": "MMM-CommandToNotification.js",
76
"repository": {
87
"type": "git",
98
"url": "git@github.com:Tom-Hirschberger/MMM-CommandToNotification.git"
109
},
1110
"keywords": [
1211
"MagicMirror",
13-
"MM",
1412
"scripts",
1513
"commands",
1614
"notifications",
@@ -27,14 +25,15 @@
2725
},
2826
"homepage": "https://github.com/Tom-Hirschberger/MMM-CommandToNotification/#readme",
2927
"devDependencies": {
30-
"@eslint/js": "^9.10.0",
31-
"@stylistic/eslint-plugin": "^2.8.0",
32-
"eslint": "^9.10.0",
33-
"globals": "^15.9.0"
28+
"@eslint/js": "^9.13.0",
29+
"@stylistic/eslint-plugin": "^2.9.0",
30+
"eslint": "^9.13.0",
31+
"globals": "^15.11.0",
32+
"prettier": "^3.3.3"
3433
},
3534
"scripts": {
36-
"lint": "eslint .",
37-
"lint:fix": "eslint . --fix",
35+
"lint": "eslint . && prettier . --check",
36+
"lint:fix": "eslint . --fix && prettier . --write",
3837
"test": "npm run lint"
3938
}
4039
}

prettier.config.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const config = {
2+
trailingComma: "none"
3+
}
4+
5+
export default config

0 commit comments

Comments
 (0)