@hurenkam/hue-services 0.6.5 → 0.6.7

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/README.md CHANGED
@@ -15,6 +15,8 @@ Unit tests are in place for the server side nodes.
15
15
  Editor/UI functionality is currently not being tested apart from my own use in the editor, so your mileage may vary.
16
16
 
17
17
  # Changelog
18
+ v0.6.6: Support bridge v3 acquire key; better error handling on put requests.
19
+
18
20
  v0.6.5: Added nodes for camera and contact sensor. Improved generic service usability.
19
21
 
20
22
  v0.6.4: Fix checkbox to work with Safari
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hurenkam/hue-services",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "Custom node-red nodes for interfacing with philips hue devices",
5
5
  "author": "Mark Hurenkamp",
6
6
  "license": "Apache 2.0",
@@ -22,6 +22,12 @@
22
22
  "hue",
23
23
  "clip"
24
24
  ],
25
+ "files": [
26
+ "README.md",
27
+ "LICENSE",
28
+ "package.json",
29
+ "src"
30
+ ],
25
31
  "node-red": {
26
32
  "version": ">=2.0.0",
27
33
  "nodes": {
package/src/RestApi.js CHANGED
@@ -81,6 +81,7 @@ class RestApi {
81
81
  var local = this;
82
82
 
83
83
  var request = this.#requestQ.shift();
84
+ this.#info("_handleRequest() url: " + request.url + " method: " + request.method + " data: " + request.data);
84
85
  this.#request(request.url, request.method, request.data)
85
86
  .then(async (result) => {
86
87
  await local.#limiter.removeTokens(1,()=>{});
@@ -90,7 +91,10 @@ class RestApi {
90
91
  .catch((error) => {
91
92
  this.#error("_handleRequest(" + request.url + ") error: ");
92
93
  this.#error(error);
93
- request.reject();
94
+ var info = {};
95
+ info.error = error;
96
+ info.request = request;
97
+ request.reject(info);
94
98
 
95
99
  // back off for a few seconds, just in case we ran into a 429 error.
96
100
  local.#timeout = setTimeout(local.#handleRequest.bind(local), 5000);
@@ -105,33 +109,45 @@ class RestApi {
105
109
  get(url) {
106
110
  this.#trace("get(" + url + ")");
107
111
  var local = this;
108
- return new Promise(function (resolve, reject) {
112
+
113
+ let promise = new Promise((resolve, reject) => {
109
114
  local.#requestQ.push({ url: url, method: "GET", data: null, resolve: resolve, reject: reject });
110
115
  });
116
+
117
+ return promise;
111
118
  }
112
119
 
113
120
  put(url, data) {
114
121
  this.#trace("put(" + url + ")");
115
122
  var local = this;
116
- return new Promise(function (resolve, reject) {
123
+
124
+ let promise = new Promise((resolve, reject) => {
117
125
  local.#requestQ.push({ url: url, method: "PUT", data: data, resolve: resolve, reject: reject });
118
126
  });
127
+
128
+ return promise;
119
129
  }
120
130
 
121
131
  post(url, data) {
122
132
  this.#trace(".post(" + url + ")");
123
133
  var local = this;
124
- return new Promise(function (resolve, reject) {
134
+
135
+ let promise = new Promise((resolve, reject) => {
125
136
  local.#requestQ.push({ url: url, method: "POST", data: data, resolve: resolve, reject: reject });
126
137
  });
138
+
139
+ return promise;
127
140
  }
128
141
 
129
142
  delete(url, data) {
130
143
  this.#trace(".delete(" + url + ")");
131
144
  var local = this;
132
- return new Promise(function (resolve, reject) {
145
+
146
+ let promise = new Promise((resolve, reject) => {
133
147
  local.#requestQ.push({ url: url, method: "DELETE", data: data, resolve: resolve, reject: reject });
134
148
  });
149
+
150
+ return promise;
135
151
  }
136
152
  }
137
153
 
@@ -107,7 +107,7 @@ class Resource extends events.EventEmitter {
107
107
 
108
108
  put(data) {
109
109
  this.#trace("put(",data,")");
110
- this.clip().put(this.rtype(),this.rid(), data);
110
+ return this.clip().put(this.rtype(),this.rid(), data);
111
111
  }
112
112
 
113
113
  onEvent(event) {
@@ -119,7 +119,7 @@ class BridgeConfigNode extends BaseNode {
119
119
  var id = "BridgeConfig (" + Math.floor((Math.random() * 100) + 1) + ")";
120
120
  var request = {
121
121
  "method": "POST",
122
- "url": "http://" + ip + "/api",
122
+ "url": "https://" + ip + "/api",
123
123
  "headers": { "Content-Type": "application/json; charset=utf-8" },
124
124
  "data": { "devicetype": id },
125
125
  "httpsAgent": new https.Agent({ rejectUnauthorized: false })
@@ -82,26 +82,35 @@ class ResourceNode extends BaseNode {
82
82
  }
83
83
 
84
84
  onInput(msg) {
85
+ super.onInput(msg);
86
+
85
87
  var resource = this.resource();
86
88
  if (!resource) {
87
89
  this.#trace("onInput(): Resource not found",this.rid());
90
+ return;
88
91
  }
89
92
 
90
- if (msg.rtypes) {
91
- if ((resource) && (msg.rtypes.includes(resource.rtype()))) {
92
- this.#trace("onInput(",msg.payload,")");
93
- resource.put(msg.payload);
94
- }
93
+ if (msg.rtypes && msg.rtypes.includes(resource.rtype())) {
94
+ resource.put(msg.payload).then(result => {
95
+ return;
96
+ }, info => {
97
+ var error = info.error;
98
+ var request = info.request;
99
+ this.error("ResourceNode::onInput() request: "+JSON.stringify(request)+" error: " + error);
100
+ return;
101
+ });
95
102
  }
96
103
 
97
- if (msg.rids) {
98
- if ((resource) && (msg.rids.includes(resource.rid()))) {
99
- this.#trace("onInput(",msg.payload,")");
100
- resource.put(msg.payload);
101
- }
104
+ if (msg.rids && msg.rids.includes(resource.rid())) {
105
+ resource.put(msg.payload).then(result => {
106
+ return;
107
+ }, info => {
108
+ var error = info.error;
109
+ var request = info.request;
110
+ this.error("ResourceNode::onInput() request: "+JSON.stringify(request)+" error: " + error);
111
+ return;
112
+ });
102
113
  }
103
-
104
- super.onInput(msg);
105
114
  }
106
115
  }
107
116
 
@@ -1,31 +0,0 @@
1
- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
- # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
-
4
- name: Node.js CI
5
-
6
- on:
7
- push:
8
- branches: [ "maturing-v0.5" ]
9
- pull_request:
10
- branches: [ "maturing-v0.5" ]
11
-
12
- jobs:
13
- build:
14
-
15
- runs-on: ubuntu-latest
16
-
17
- strategy:
18
- matrix:
19
- node-version: [14.x, 16.x, 18.x]
20
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
-
22
- steps:
23
- - uses: actions/checkout@v3
24
- - name: Use Node.js ${{ matrix.node-version }}
25
- uses: actions/setup-node@v3
26
- with:
27
- node-version: ${{ matrix.node-version }}
28
- cache: 'npm'
29
- - run: npm ci
30
- - run: npm run build --if-present
31
- - run: npm test
@@ -1,2 +0,0 @@
1
- 2ml0TLJEUc-j-byMhxIhymRSOUPUlnzRrZUiseoq
2
-