matterbridge-webhooks 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,36 @@ If you like this project and find it useful, please consider giving it a star on
8
8
  <img src="bmc-button.svg" alt="Buy me a coffee" width="120">
9
9
  </a>
10
10
 
11
+ ## [0.0.3] - 2025-05-01
12
+
13
+ ### Added
14
+
15
+ - [readme]: Added the possibility to test the hook before confirming the changes in the config editor.
16
+
17
+ ### Changed
18
+
19
+ - [package]: Require matterbridge 3.0.0.
20
+ - [package]: Updated package.
21
+ - [package]: Updated dependencies.
22
+
23
+ <a href="https://www.buymeacoffee.com/luligugithub">
24
+ <img src="bmc-button.svg" alt="Buy me a coffee" width="80">
25
+ </a>
26
+
27
+ ## [0.0.2] - 2025-03-30
28
+
29
+ ### Added
30
+
31
+ - [readme]: Added some examples for Shelly Trv gen 1.
32
+
33
+ ### Fixed
34
+
35
+ - [select]: Fixed missing clearSelect on start.
36
+
37
+ <a href="https://www.buymeacoffee.com/luligugithub">
38
+ <img src="bmc-button.svg" alt="Buy me a coffee" width="80">
39
+ </a>
40
+
11
41
  ## [0.0.1] - 2025-03-19
12
42
 
13
43
  First published release.
package/README.md CHANGED
@@ -19,6 +19,7 @@ This plugin allows you to expose any webhooks to Matter.
19
19
  Features:
20
20
 
21
21
  - The webhooks parameters can easily be entered in the frontend.
22
+ - It is possible to choose how to expose the webhooks: Switch, Outlet or Light.
22
23
  - It is possible to choose the method: GET or POST.
23
24
  - The webhook can be tested in the frontend.
24
25
 
@@ -54,12 +55,32 @@ See the complete guidelines on [Matterbridge](https://github.com/Luligu/matterbr
54
55
 
55
56
  ## How to add a webhook
56
57
 
57
- In the frontend open the plugin config: add a new webhook, enter the webhook name in the first field (replace newKey with the name you want to give to the webhook), select GET or POST and enter the webhook url. The webhook name will be the device name on the controller. The webhook will be exposed like a switch or like a plug, when you turn it on the webhook is called and in a few seconds the switch or the plug will revert to off.
58
+ In the frontend open the plugin config: add a new webhook, enter the webhook name in the first field (replace newKey with the name you want to give to the webhook), select GET or POST and enter the webhook url. The webhook name will be the device name on the controller. The webhook will be exposed like a switch, like an outlet or like a light. When you turn it on, the webhook is called and in a few seconds the switch or the outlet or the light will revert to off.
58
59
 
59
60
  It is possible to test directly the webhook from the config editor.
60
61
 
61
62
  ## Examples
62
63
 
63
- ## Shelly webhooks
64
+ ## Shelly webhooks examples
64
65
 
65
- For example to turn on a shelly gen 1 device with ip 192.168.1.155 the url is http://192.168.1.155/light/0?turn=on.
66
+ Change 192.168.1.XXX with your device IP address.
67
+
68
+ ### Shelly 1 Gen 1
69
+
70
+ To turn on a shelly gen 1 device with ip 192.168.1.155 the url is http://192.168.1.XXX/light/0?turn=on.
71
+
72
+ To turn off a shelly gen 1 device with ip 192.168.1.155 the url is http://192.168.1.XXX/light/0?turn=off.
73
+
74
+ ### Shelly Trv Gen 1
75
+
76
+ The following examples allows to fully control a Shelly Trv Gen 1, adding Boost, Schedule and Profile (provided by https://github.com/vandan380).
77
+
78
+ "Boost 30min": method: POST, Url: "http://192.168.1.XXX/thermostats/0?boost_minutes=30"
79
+
80
+ "Schedule Enable": method: POST, Url: "http://192.168.1.XXX/settings/thermostats/0?schedule=1"
81
+
82
+ "Schedule Disable": method: POST, Url: "http://192.168.1.XXX/settings/thermostats/0?schedule=0"
83
+
84
+ "Profile Working Day": method: POST, Url: "http://192.168.1.XXX/settings/thermostats/0?schedule_profile=1"
85
+
86
+ "Profile Holiday": method: POST, Url: "http://192.168.1.XXX/settings/thermostats/0?schedule_profile=2"
package/dist/fetch.js CHANGED
@@ -44,7 +44,7 @@ export async function fetch(url, method = 'GET', data = {}, timeout = 5000) {
44
44
  clearTimeout(timeoutId);
45
45
  res.resume();
46
46
  req.destroy();
47
- return reject(new Error(`Request failed with status code: ${res.statusCode}`));
47
+ reject(new Error(`Request failed with status code: ${res.statusCode}`));
48
48
  }
49
49
  res.on('data', (chunk) => {
50
50
  responseData += chunk;
package/dist/platform.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { bridgedNode, MatterbridgeDynamicPlatform, MatterbridgeEndpoint, onOffLight, onOffOutlet, onOffSwitch } from 'matterbridge';
2
+ import { isValidObject } from 'matterbridge/utils';
2
3
  import { fetch } from './fetch.js';
3
4
  export class Platform extends MatterbridgeDynamicPlatform {
4
5
  webhooks;
5
6
  bridgedDevices = new Map();
6
7
  constructor(matterbridge, log, config) {
7
8
  super(matterbridge, log, config);
8
- if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('2.2.5')) {
9
- throw new Error(`This plugin requires Matterbridge version >= "2.2.5". Please update Matterbridge to the latest version in the frontend.`);
9
+ if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.0.0')) {
10
+ throw new Error(`This plugin requires Matterbridge version >= "3.0.0". Please update Matterbridge to the latest version in the frontend.`);
10
11
  }
11
12
  this.log.info('Initializing platform:', this.config.name);
12
13
  this.webhooks = this.config.webhooks;
@@ -14,6 +15,8 @@ export class Platform extends MatterbridgeDynamicPlatform {
14
15
  }
15
16
  async onStart(reason) {
16
17
  this.log.info('onStart called with reason:', reason ?? 'none');
18
+ await this.ready;
19
+ await this.clearSelect();
17
20
  let i = 1;
18
21
  for (const webhookName in this.webhooks) {
19
22
  if (Object.prototype.hasOwnProperty.call(this.webhooks, webhookName)) {
@@ -48,9 +51,33 @@ export class Platform extends MatterbridgeDynamicPlatform {
48
51
  await device.setAttribute('onOff', 'onOff', false, device.log);
49
52
  });
50
53
  }
51
- async onAction(action, value, id) {
54
+ async onAction(action, value, id, formData) {
52
55
  this.log.info('onAction called with action:', action, 'and value:', value ?? 'none', 'and id:', id ?? 'none');
56
+ this.log.debug('onAction called with formData:', formData ?? 'none');
57
+ if (id?.startsWith('root_webhooks_'))
58
+ id = id.replace('root_webhooks_', '');
59
+ if (id?.endsWith('_test'))
60
+ id = id.replace('_test', '');
53
61
  if (action === 'test') {
62
+ if (isValidObject(formData, 1) && isValidObject(formData.webhooks, 1)) {
63
+ const webhooks = formData.webhooks;
64
+ for (const webhookName in webhooks) {
65
+ if (Object.prototype.hasOwnProperty.call(webhooks, webhookName)) {
66
+ const webhook = webhooks[webhookName];
67
+ if (id?.includes(webhookName)) {
68
+ this.log.info(`Testing new webhook ${webhookName} method ${webhook.method} url ${webhook.httpUrl}`);
69
+ fetch(webhook.httpUrl, webhook.method)
70
+ .then(() => {
71
+ this.log.notice(`Webhook test ${webhookName} successful!`);
72
+ })
73
+ .catch((err) => {
74
+ this.log.error(`Webhook test ${webhookName} failed: ${err instanceof Error ? err.message : err}`);
75
+ });
76
+ }
77
+ }
78
+ }
79
+ return;
80
+ }
54
81
  for (const webhookName in this.webhooks) {
55
82
  if (Object.prototype.hasOwnProperty.call(this.webhooks, webhookName)) {
56
83
  const webhook = this.webhooks[webhookName];
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge-webhooks",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge-webhooks",
9
- "version": "0.0.1",
9
+ "version": "0.0.3",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "node-ansi-logger": "^3.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-webhooks",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Matterbridge webhooks plugin",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ // enable isolatedModules just for ts-jest
5
+ "isolatedModules": true
6
+ },
7
+ "include": ["**/*.spec.ts", "**/*.test.ts", "**/__test__/*"]
8
+ }