@haydendonald/node-red-contrib-hass-stuff 1.0.1 → 1.1.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.
@@ -16,7 +16,7 @@ module.exports = function ConnectionsConfigNode(RED) {
16
16
  self.hassEventCallServiceCallbacks = {};
17
17
  self.hassEventStateChangeCallbacks = {};
18
18
  self.sendHASSAPI = function (protocol, method, path, callback, params, data, results) {
19
- const callbackId = callback ? (0, utility_1.generateRandomId)(Object.keys(self.hassAPICallbacks)) : undefined;
19
+ const callbackId = (0, utility_1.generateRandomId)(Object.keys(self.hassAPICallbacks));
20
20
  const msg = {
21
21
  topic: connectionsTypes_1.Topics.API,
22
22
  callbackId,
@@ -31,12 +31,12 @@ module.exports = function ConnectionsConfigNode(RED) {
31
31
  };
32
32
  self.sendMsg(msg);
33
33
  //Add our callback for when a response comes back in
34
- if (callbackId && callback) {
34
+ if (callback) {
35
35
  self.hassAPICallbacks[callbackId] = callback;
36
36
  }
37
37
  };
38
38
  self.sendHASSAction = function (action, target, data, callback) {
39
- const callbackId = callback ? (0, utility_1.generateRandomId)(Object.keys(self.hassActionCallbacks)) : undefined;
39
+ const callbackId = (0, utility_1.generateRandomId)(Object.keys(self.hassActionCallbacks));
40
40
  const msg = {
41
41
  topic: connectionsTypes_1.Topics.ACTION,
42
42
  callbackId,
@@ -48,12 +48,12 @@ module.exports = function ConnectionsConfigNode(RED) {
48
48
  };
49
49
  self.sendMsg(msg);
50
50
  //Add our callback for when a response comes back in
51
- if (callbackId && callback) {
51
+ if (callback) {
52
52
  self.hassActionCallbacks[callbackId] = callback;
53
53
  }
54
54
  };
55
55
  self.getHASSEntityState = function (entityId, callback) {
56
- const callbackId = callback ? (0, utility_1.generateRandomId)(Object.keys(self.hassCurrentStateCallbacks)) : undefined;
56
+ const callbackId = (0, utility_1.generateRandomId)(Object.keys(self.hassCurrentStateCallbacks));
57
57
  const msg = {
58
58
  topic: connectionsTypes_1.Topics.STATE,
59
59
  callbackId,
@@ -63,12 +63,12 @@ module.exports = function ConnectionsConfigNode(RED) {
63
63
  };
64
64
  self.sendMsg(msg);
65
65
  //Add our callback for when a response comes back in
66
- if (callbackId && callback) {
66
+ if (callback) {
67
67
  self.hassCurrentStateCallbacks[callbackId] = callback;
68
68
  }
69
69
  };
70
70
  self.getHASSEntities = function (rules, callback) {
71
- const callbackId = callback ? (0, utility_1.generateRandomId)(Object.keys(self.hassGetEntitiesCallbacks)) : undefined;
71
+ const callbackId = (0, utility_1.generateRandomId)(Object.keys(self.hassGetEntitiesCallbacks));
72
72
  const msg = {
73
73
  topic: connectionsTypes_1.Topics.GET_ENTITIES,
74
74
  callbackId,
@@ -78,7 +78,7 @@ module.exports = function ConnectionsConfigNode(RED) {
78
78
  };
79
79
  self.sendMsg(msg);
80
80
  //Add our callback for when a response comes back in
81
- if (callbackId && callback) {
81
+ if (callback) {
82
82
  self.hassGetEntitiesCallbacks[callbackId] = callback;
83
83
  }
84
84
  };
@@ -251,6 +251,7 @@ module.exports = function ConnectionsConfigNode(RED) {
251
251
  }
252
252
  const previousState = entities.length == 1 ? entities[0].state : undefined;
253
253
  self.addHASSEntity(entityId, data(options.state || previousState), options.creationCallback ? (response) => {
254
+ console.log(response);
254
255
  options.creationCallback(response.payload.state, response);
255
256
  } : undefined);
256
257
  });
@@ -351,13 +352,16 @@ module.exports = function ConnectionsConfigNode(RED) {
351
352
  }
352
353
  };
353
354
  self.handleCallback = function (callbacks, callbackId, ...args) {
354
- var _a;
355
355
  //This is a specific callback id
356
- if (callbackId) {
357
- (_a = callbacks[callbackId]) === null || _a === void 0 ? void 0 : _a.call(callbacks, ...args);
356
+ if (callbacks[callbackId]) {
357
+ callbacks[callbackId](...args);
358
358
  delete callbacks[callbackId];
359
359
  return;
360
360
  }
361
+ //We failed to find the callback, so it must not exist
362
+ if (callbackId !== undefined) {
363
+ return;
364
+ }
361
365
  //Send to everyone
362
366
  for (const id of Object.keys(callbacks)) {
363
367
  if (callbacks[id]) {
@@ -5,6 +5,7 @@
5
5
  inputs: 1,
6
6
  outputs: 1,
7
7
  icon: "bulb.svg",
8
+ paletteLabel: "Connections",
8
9
  defaults: {
9
10
  name: { value: "" },
10
11
  connectionsConfigNode: { value: '', type: "connections-config-node", required: true }
@@ -179,6 +179,7 @@ module.exports = function LightControlConfigNode(RED) {
179
179
  ...Object.values(scenes).map(scene => scene.friendlyName),
180
180
  "Adaptive"
181
181
  ],
182
+ defaultState: "Adaptive",
182
183
  creationCallback: (state) => {
183
184
  currentSceneState = state;
184
185
  runLights(300, false);
@@ -5,6 +5,7 @@
5
5
  inputs: 1,
6
6
  outputs: 1,
7
7
  icon: "bulb.svg",
8
+ paletteLabel: "Light Control",
8
9
  defaults: {
9
10
  name: { value: "" },
10
11
  lightControlConfigNode: { value: '', type: "light-control-config-node", required: true }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haydendonald/node-red-contrib-hass-stuff",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "A collection of stuff I use on my Node Red + Home Assistant server. This could be of use for others, i don't know..",
5
5
  "devDependencies": {
6
6
  "@types/node": "^18.14.0",