node-red-contrib-homebridge-automation 0.1.12-beta.26 → 0.1.12-beta.27
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/package.json +1 -1
- package/src/hbBaseNode.js +3 -0
- package/src/hbControlNode.js +1 -1
- package/src/hbEventNode.js +0 -1
- package/src/hbResumeNode.js +29 -116
- package/test/node-red/flows.json +1 -32
package/package.json
CHANGED
package/src/hbBaseNode.js
CHANGED
|
@@ -23,6 +23,9 @@ class HbBaseNode {
|
|
|
23
23
|
if (this.handleInput) {
|
|
24
24
|
this.on('input', this.handleInput.bind(this));
|
|
25
25
|
}
|
|
26
|
+
if (this.handleHbReady) {
|
|
27
|
+
this.on('hbReady', this.handleHbReady.bind(this))
|
|
28
|
+
}
|
|
26
29
|
this.on('close', this.handleClose.bind(this));
|
|
27
30
|
this.on('hbEvent', this.handleHBEventMessage.bind(this));
|
|
28
31
|
}
|
package/src/hbControlNode.js
CHANGED
package/src/hbEventNode.js
CHANGED
package/src/hbResumeNode.js
CHANGED
|
@@ -5,12 +5,7 @@ class HbResumeNode extends HbBaseNode {
|
|
|
5
5
|
constructor(config, RED) {
|
|
6
6
|
super(config, RED);
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
this.state = null;
|
|
10
|
-
this.lastMessageTime = null;
|
|
11
|
-
this.lastMessageValue = null;
|
|
12
|
-
this.lastPayload = { On: false };
|
|
13
|
-
this.timeout = null;
|
|
8
|
+
this.storedState = null;
|
|
14
9
|
|
|
15
10
|
// Set up input and command handlers
|
|
16
11
|
// this.on('input', this.handleInput.bind(this));
|
|
@@ -18,127 +13,45 @@ class HbResumeNode extends HbBaseNode {
|
|
|
18
13
|
|
|
19
14
|
// Handle device registration
|
|
20
15
|
debug('hbResume - hbConfigNode', this.hbConfigNode);
|
|
21
|
-
// debug('hbResume - hbConfigNode', this.configNode.hbConfigNode);
|
|
22
|
-
|
|
23
16
|
}
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
debug('
|
|
18
|
+
handleInput(message, send) {
|
|
19
|
+
debug('handleInput', message.payload, this.name);
|
|
27
20
|
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
shape: '
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
this.send({ payload: service.values });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
handleInput(msg, send) {
|
|
37
|
-
this.msg = msg;
|
|
38
|
-
debug("hbResume.input: %s input", this.fullName, JSON.stringify(msg));
|
|
39
|
-
|
|
40
|
-
if (typeof msg.payload === "object") {
|
|
41
|
-
if (this.hbDevice) {
|
|
42
|
-
const message = this._createControlMessage.call(this, msg.payload, this, this.hbDevice);
|
|
43
|
-
|
|
44
|
-
if (message.characteristics.length > 0) {
|
|
45
|
-
let newMsg;
|
|
46
|
-
if (!msg.payload.On) {
|
|
47
|
-
if (this.lastPayload.On) {
|
|
48
|
-
newMsg = {
|
|
49
|
-
name: this.name,
|
|
50
|
-
_device: this.device,
|
|
51
|
-
_confId: this.confId,
|
|
52
|
-
payload: this.state,
|
|
53
|
-
Homebridge: this.hbDevice?.homebridge,
|
|
54
|
-
Manufacturer: this.hbDevice?.manufacturer,
|
|
55
|
-
Type: this.hbDevice?.deviceType,
|
|
56
|
-
};
|
|
57
|
-
} else {
|
|
58
|
-
this.state = JSON.parse(JSON.stringify(msg.payload));
|
|
59
|
-
newMsg = msg;
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
newMsg = msg;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
send(newMsg.payload.On ? newMsg : { ...newMsg, payload: { On: false } });
|
|
66
|
-
debug("hbResume.input: %s output", this.fullName, JSON.stringify(newMsg));
|
|
67
|
-
this.updateStatus(newMsg.payload);
|
|
68
|
-
this.lastMessageValue = newMsg.payload;
|
|
69
|
-
this.lastMessageTime = Date.now();
|
|
70
|
-
this.lastPayload = JSON.parse(JSON.stringify(msg.payload));
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
this.handleError("Homebridge not initialized - 1");
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
this.handleError(
|
|
77
|
-
"Payload should be a JSON object containing device characteristics and values, e.g., {\"On\":false, \"Brightness\":0 }"
|
|
78
|
-
);
|
|
21
|
+
if (!this.hbDevice) {
|
|
22
|
+
this.warn('HB not initialized');
|
|
23
|
+
this.status({ text: 'HB not initialized', shape: 'ring', fill: 'red' });
|
|
24
|
+
return;
|
|
79
25
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
handleCommand(event) {
|
|
83
|
-
const payload = { ...this.state, ...this._convertHBcharactericToNode([event], this) };
|
|
84
|
-
debug("hbResume.event: %s %s -> %s", this.fullName, JSON.stringify(this.state), JSON.stringify(payload));
|
|
85
26
|
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} else {
|
|
94
|
-
this.updateStatus({ text: `disconnected: ${event.status}`, shape: 'ring', fill: 'red' });
|
|
27
|
+
if (typeof message.payload !== 'object') {
|
|
28
|
+
const validNames = Object.keys(this.hbDevice.values)
|
|
29
|
+
.filter(key => key !== 'ConfiguredName')
|
|
30
|
+
.join(', ');
|
|
31
|
+
this.warn(`Payload should be a JSON object containing device characteristics and values, e.g. {"On":false, "Brightness":0}. Valid values: ${validNames}`);
|
|
32
|
+
this.status({ text: 'Invalid payload', shape: 'dot', fill: 'red' });
|
|
33
|
+
return;
|
|
95
34
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
handleDeviceRegistration() {
|
|
99
|
-
debug("hbResume.register:", this.fullName);
|
|
100
|
-
this.hbDevice = hbDevices.findDevice(this.device, { perms: 'pw' });
|
|
101
|
-
|
|
102
|
-
if (this.hbDevice) {
|
|
103
|
-
this._status(this.device, this, { perms: 'pw' }, (err, message) => {
|
|
104
|
-
if (!err) {
|
|
105
|
-
this.state = this._convertHBcharactericToNode(message.characteristics, this);
|
|
106
|
-
debug("hbResume received: %s = %s", this.fullName, JSON.stringify(message.characteristics).slice(0, 80) + '...');
|
|
107
|
-
} else {
|
|
108
|
-
this.error(err);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
this.deviceType = this.hbDevice.deviceType;
|
|
113
|
-
this.listener = this.command;
|
|
114
|
-
this.eventName = [];
|
|
115
35
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.eventName.push(this.hbDevice.id + event.aid + event.iid);
|
|
119
|
-
});
|
|
36
|
+
// if on, store the current values object to storedState before passing
|
|
37
|
+
// if off, if storedState, then send stored state else passthru
|
|
120
38
|
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
|
|
124
|
-
|
|
39
|
+
if (message.payload.On) {
|
|
40
|
+
this.storedState = this.hbDevice.values;
|
|
41
|
+
debug('Storing', this.storedState);
|
|
42
|
+
} else if (!message.payload.On && this.storedState) {
|
|
43
|
+
debug('Restoring', this.storedState)
|
|
44
|
+
message.payload = { ...message.payload, ...this.storedState }
|
|
45
|
+
this.storedState = null;
|
|
125
46
|
}
|
|
47
|
+
this.status({
|
|
48
|
+
text: JSON.stringify(message.payload),
|
|
49
|
+
shape: 'dot',
|
|
50
|
+
fill: 'green',
|
|
51
|
+
});
|
|
52
|
+
send(message);
|
|
126
53
|
}
|
|
127
54
|
|
|
128
|
-
updateStatus(status) {
|
|
129
|
-
this.status(status);
|
|
130
|
-
this.resetTimeout(10000);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
resetTimeout(duration) {
|
|
134
|
-
clearTimeout(this.timeout);
|
|
135
|
-
this.timeout = setTimeout(() => this.status({}), duration);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
handleError(message) {
|
|
139
|
-
this.error(message, this.msg);
|
|
140
|
-
this.updateStatus({ text: message, shape: 'ring', fill: 'red' });
|
|
141
|
-
}
|
|
142
55
|
}
|
|
143
56
|
|
|
144
57
|
module.exports = HbResumeNode;
|
package/test/node-red/flows.json
CHANGED
|
@@ -168,9 +168,7 @@
|
|
|
168
168
|
"x": 210,
|
|
169
169
|
"y": 460,
|
|
170
170
|
"wires": [
|
|
171
|
-
[
|
|
172
|
-
"452e3e6171aa7a25"
|
|
173
|
-
]
|
|
171
|
+
[]
|
|
174
172
|
]
|
|
175
173
|
},
|
|
176
174
|
{
|
|
@@ -439,34 +437,5 @@
|
|
|
439
437
|
"a866ae0bb24ce682"
|
|
440
438
|
]
|
|
441
439
|
]
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
"id": "56633636bd2e624c",
|
|
445
|
-
"type": "inject",
|
|
446
|
-
"z": "caef1e7b5b399e80",
|
|
447
|
-
"name": "",
|
|
448
|
-
"props": [
|
|
449
|
-
{
|
|
450
|
-
"p": "payload"
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
"p": "topic",
|
|
454
|
-
"vt": "str"
|
|
455
|
-
}
|
|
456
|
-
],
|
|
457
|
-
"repeat": "60",
|
|
458
|
-
"crontab": "",
|
|
459
|
-
"once": true,
|
|
460
|
-
"onceDelay": "60",
|
|
461
|
-
"topic": "",
|
|
462
|
-
"payload": "",
|
|
463
|
-
"payloadType": "date",
|
|
464
|
-
"x": 190,
|
|
465
|
-
"y": 280,
|
|
466
|
-
"wires": [
|
|
467
|
-
[
|
|
468
|
-
"452e3e6171aa7a25"
|
|
469
|
-
]
|
|
470
|
-
]
|
|
471
440
|
}
|
|
472
441
|
]
|