node-red-contrib-googlehome 0.0.15 → 1.0.0

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.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/googlehome.js +16 -12
  3. package/package.json +5 -3
package/README.md CHANGED
@@ -17,4 +17,6 @@ You will need an account [here](https://googlehome.hardill.me.uk). Once you have
17
17
  account you can define a number of devices. You can then configure a node to represent
18
18
  that device in a Node-RED flow.
19
19
 
20
- The full documentation can be found [here](https://googlehome.hardill.me.uk/docs)
20
+ The full documentation can be found [here](https://googlehome.hardill.me.uk/docs)
21
+
22
+ Minimum NodeJS version is now 20 (uses `fetch` to replace `request`)
package/googlehome.js CHANGED
@@ -23,7 +23,6 @@ module.exports = function(RED) {
23
23
  const fs = require('fs');
24
24
  const mqtt = require('mqtt');
25
25
  const path = require('path');
26
- const request = require('request');
27
26
 
28
27
  var devices = {};
29
28
  var status = {};
@@ -214,6 +213,7 @@ module.exports = function(RED) {
214
213
  //console.log("replying to a command")
215
214
  var resp = {
216
215
  requestId: msg._requestId,
216
+ status: msg.status,
217
217
  id: msg.deviceId,
218
218
  execution: msg.payload
219
219
  }
@@ -254,21 +254,25 @@ module.exports = function(RED) {
254
254
 
255
255
  function getDevices(username, password, id) {
256
256
  if (username && password) {
257
- request.get({
258
- url: devicesURL,
259
- auth: {
260
- username: username,
261
- password: password
257
+ fetch(devicesURL, {
258
+ method: 'GET',
259
+ headers: {
260
+ 'Authorization': `Basic ${Buffer.from(username + ':' + password, "utf-8").toString('base64')}`
262
261
  }
263
- }, function(err,res,body) {
264
- if (!err && res.statusCode == 200) {
265
- var devs = JSON.parse(body);
266
- devices[id] = devs
262
+ })
263
+ .then(res => {
264
+ if (res.status === 200) {
265
+ return res.json()
267
266
  } else {
268
- //console.("err: " + err);
269
267
  RED.log.log("Problem looking up " + username + "'s devices");
270
268
  }
271
- });
269
+ })
270
+ .then(json => {
271
+ devices[id] = json
272
+ })
273
+ .catch( err => {
274
+ console.log(err)
275
+ })
272
276
  }
273
277
  }
274
278
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-googlehome",
3
- "version": "0.0.15",
3
+ "version": "1.0.0",
4
4
  "description": "A Smart Home Action for Google Home",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,7 +26,9 @@
26
26
  "author": "hardillb@gmail.com",
27
27
  "license": "Apache-2.0",
28
28
  "dependencies": {
29
- "mqtt": "^4.2.6",
30
- "request": "^2.83.0"
29
+ "mqtt": "^5.15.1"
30
+ },
31
+ "engines": {
32
+ "node": ">=18.x"
31
33
  }
32
34
  }