@haydendonald/node-red-contrib-hass-stuff 1.0.1 → 1.1.1
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 =
|
|
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 (
|
|
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 =
|
|
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 (
|
|
51
|
+
if (callback) {
|
|
52
52
|
self.hassActionCallbacks[callbackId] = callback;
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
self.getHASSEntityState = function (entityId, callback) {
|
|
56
|
-
const callbackId =
|
|
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 (
|
|
66
|
+
if (callback) {
|
|
67
67
|
self.hassCurrentStateCallbacks[callbackId] = callback;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
self.getHASSEntities = function (rules, callback) {
|
|
71
|
-
const callbackId =
|
|
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 (
|
|
81
|
+
if (callback) {
|
|
82
82
|
self.hassGetEntitiesCallbacks[callbackId] = callback;
|
|
83
83
|
}
|
|
84
84
|
};
|
|
@@ -351,13 +351,16 @@ module.exports = function ConnectionsConfigNode(RED) {
|
|
|
351
351
|
}
|
|
352
352
|
};
|
|
353
353
|
self.handleCallback = function (callbacks, callbackId, ...args) {
|
|
354
|
-
var _a;
|
|
355
354
|
//This is a specific callback id
|
|
356
|
-
if (callbackId) {
|
|
357
|
-
|
|
355
|
+
if (callbacks[callbackId]) {
|
|
356
|
+
callbacks[callbackId](...args);
|
|
358
357
|
delete callbacks[callbackId];
|
|
359
358
|
return;
|
|
360
359
|
}
|
|
360
|
+
//We failed to find the callback, so it must not exist
|
|
361
|
+
if (callbackId !== undefined) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
361
364
|
//Send to everyone
|
|
362
365
|
for (const id of Object.keys(callbacks)) {
|
|
363
366
|
if (callbacks[id]) {
|
|
@@ -171,6 +171,22 @@ module.exports = function LightControlConfigNode(RED) {
|
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
|
+
//Add our toggle scene
|
|
175
|
+
connectionsConfigNode.addHASSScene({
|
|
176
|
+
friendlyName: `${self.name} - Toggle`,
|
|
177
|
+
id: (0, utility_1.getEntityId)("scene", `${self.name}_toggle`),
|
|
178
|
+
creationCallback: (response) => { },
|
|
179
|
+
activatedCallback: (serviceData) => {
|
|
180
|
+
if (currentState.state == "off") {
|
|
181
|
+
runLights(serviceData.transition || 1, true);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
connectionsConfigNode.sendHASSAction("light.turn_off", { entity_id: [config.groupEntityId] }, {
|
|
185
|
+
transition: serviceData.transition || 1
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
174
190
|
//Add our select to keep track of what scene we are running
|
|
175
191
|
connectionsConfigNode.addHASSSelect({
|
|
176
192
|
friendlyName: `${self.name} - Current Scene`,
|
|
@@ -179,6 +195,7 @@ module.exports = function LightControlConfigNode(RED) {
|
|
|
179
195
|
...Object.values(scenes).map(scene => scene.friendlyName),
|
|
180
196
|
"Adaptive"
|
|
181
197
|
],
|
|
198
|
+
defaultState: "Adaptive",
|
|
182
199
|
creationCallback: (state) => {
|
|
183
200
|
currentSceneState = state;
|
|
184
201
|
runLights(300, false);
|
|
@@ -209,7 +226,7 @@ module.exports = function LightControlConfigNode(RED) {
|
|
|
209
226
|
this.msgReceived = function (msg, senderIds) { };
|
|
210
227
|
const activateScene = (scene, transitionSec, turnLightsOn, entitiesOn, entitiesOff) => {
|
|
211
228
|
//If the lights are off and we are not to turn the lights on don't do anything
|
|
212
|
-
if (turnLightsOn == false && currentState == "off") {
|
|
229
|
+
if (turnLightsOn == false && currentState.state == "off") {
|
|
213
230
|
return;
|
|
214
231
|
}
|
|
215
232
|
//Is not a scene preset scene if we have a entity id
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haydendonald/node-red-contrib-hass-stuff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|