node-red-contrib-homekit-bridged 2.0.0-dev.5 → 2.0.0-dev.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/build/lib/HAPHostNode.js +183 -141
- package/build/lib/HAPServiceNode.js +199 -172
- package/build/lib/HAPServiceNode2.js +207 -172
- package/build/lib/NRCHKBError.js +23 -2
- package/build/lib/PairingQRCode.js +62 -0
- package/build/lib/Storage.js +157 -92
- package/build/lib/api.js +654 -288
- package/build/lib/camera/CameraControl.js +119 -84
- package/build/lib/camera/CameraDelegate.js +481 -404
- package/build/lib/camera/MP4StreamingServer.js +148 -139
- package/build/lib/hap/HAPCharacteristic.js +25 -4
- package/build/lib/hap/HAPService.js +25 -4
- package/build/lib/hap/eve-app/EveCharacteristics.js +124 -81
- package/build/lib/hap/eve-app/EveServices.js +50 -17
- package/build/lib/hap/hap-nodejs.js +32 -0
- package/build/lib/migration/HomeKitService2Migration.js +34 -0
- package/build/lib/migration/NodeMigration.js +75 -0
- package/build/lib/types/AccessoryInformationType.js +15 -1
- package/build/lib/types/CameraConfigType.js +15 -1
- package/build/lib/types/CustomCharacteristicType.js +15 -1
- package/build/lib/types/HAPHostConfigType.js +15 -1
- package/build/lib/types/HAPHostNodeType.js +15 -1
- package/build/lib/types/HAPService2ConfigType.js +15 -1
- package/build/lib/types/HAPService2NodeType.js +15 -1
- package/build/lib/types/HAPServiceConfigType.js +15 -1
- package/build/lib/types/HAPServiceNodeType.js +15 -1
- package/build/lib/types/HAPStatusConfigType.js +15 -1
- package/build/lib/types/HAPStatusNodeType.js +15 -1
- package/build/lib/types/HostType.js +28 -7
- package/build/lib/types/NodeType.js +15 -1
- package/build/lib/types/PublishTimersType.js +15 -1
- package/build/lib/types/UniFiControllerConfigType.js +16 -0
- package/build/lib/types/hap-nodejs/HapAdaptiveLightingControllerMode.js +28 -7
- package/build/lib/types/hap-nodejs/HapCategories.js +64 -43
- package/build/lib/types/storage/SerializedHostType.js +15 -1
- package/build/lib/types/storage/StorageType.js +34 -10
- package/build/lib/unifi/ProtectDiscovery.js +80 -0
- package/build/lib/utils/AccessoryUtils.js +152 -110
- package/build/lib/utils/BridgeUtils.js +82 -39
- package/build/lib/utils/CharacteristicUtils.js +5 -49
- package/build/lib/utils/CharacteristicUtils2.js +5 -49
- package/build/lib/utils/CharacteristicUtilsBase.js +81 -0
- package/build/lib/utils/NodeStatusUtils.js +89 -40
- package/build/lib/utils/ServiceUtils.js +434 -375
- package/build/lib/utils/ServiceUtils2.js +514 -309
- package/build/lib/utils/index.js +10 -11
- package/build/nodes/bridge.html +184 -166
- package/build/nodes/bridge.js +27 -9
- package/build/nodes/locales/en-US/node-red-contrib-homekit-bridged.json +22 -0
- package/build/nodes/nrchkb.html +1601 -88
- package/build/nodes/nrchkb.js +66 -88
- package/build/nodes/plugin-instance.html +499 -0
- package/build/nodes/plugin-instance.js +46 -0
- package/build/nodes/service.html +517 -299
- package/build/nodes/service.js +5 -6
- package/build/nodes/service2.html +1683 -460
- package/build/nodes/service2.js +5 -8
- package/build/nodes/standalone.html +187 -174
- package/build/nodes/standalone.js +27 -9
- package/build/nodes/status.html +51 -18
- package/build/nodes/status.js +47 -40
- package/build/nodes/unifi-controller.html +92 -0
- package/build/nodes/unifi-controller.js +20 -0
- package/build/plugins/embedded/homebridge-camera-ffmpeg/index.js +479 -0
- package/build/plugins/embedded/homebridge-unifi-protect/index.js +521 -0
- package/build/plugins/embedded/index.js +58 -0
- package/build/plugins/nrchkb-homekit-plugins.js +17 -0
- package/build/plugins/registry/index.js +203 -0
- package/build/plugins/registry/types.js +16 -0
- package/build/scripts/migrate-homekit-service-flows.js +47 -0
- package/examples/demo/01 - ALL Demos single import.json +1885 -1885
- package/examples/demo/02 - Air Purifier.json +279 -279
- package/examples/demo/03 - Air Quality sensor with Battery.json +254 -254
- package/examples/demo/04 - Dimmable Bulb.json +172 -172
- package/examples/demo/05 - Color Bulb (HSV).json +195 -195
- package/examples/demo/06 - Fan (simple, 3 speeds).json +240 -240
- package/examples/demo/07 - Fan (with speed, oscillate, rotation direction).json +175 -175
- package/examples/demo/08 - CO2 detector.json +224 -224
- package/examples/demo/09 - CO (carbon monoxide) example.json +255 -255
- package/examples/demo/10 - Door window contact sensor.json +234 -234
- package/examples/demos (advanced)/01 - Television with inputs and speaker.json +541 -541
- package/examples/switch/01 - Plain Switch.json +178 -178
- package/package.json +95 -84
- package/build/lib/HAPHostNode.d.ts +0 -1
- package/build/lib/HAPServiceNode.d.ts +0 -1
- package/build/lib/HAPServiceNode2.d.ts +0 -1
- package/build/lib/NRCHKBError.d.ts +0 -3
- package/build/lib/Storage.d.ts +0 -30
- package/build/lib/api.d.ts +0 -1
- package/build/lib/camera/CameraControl.d.ts +0 -3
- package/build/lib/camera/CameraDelegate.d.ts +0 -38
- package/build/lib/camera/MP4StreamingServer.d.ts +0 -26
- package/build/lib/hap/HAPCharacteristic.d.ts +0 -9
- package/build/lib/hap/HAPService.d.ts +0 -6
- package/build/lib/hap/eve-app/EveCharacteristics.d.ts +0 -20
- package/build/lib/hap/eve-app/EveServices.d.ts +0 -5
- package/build/lib/types/AccessoryInformationType.d.ts +0 -11
- package/build/lib/types/CameraConfigType.d.ts +0 -24
- package/build/lib/types/CustomCharacteristicType.d.ts +0 -6
- package/build/lib/types/HAPHostConfigType.d.ts +0 -22
- package/build/lib/types/HAPHostNodeType.d.ts +0 -14
- package/build/lib/types/HAPService2ConfigType.d.ts +0 -6
- package/build/lib/types/HAPService2NodeType.d.ts +0 -7
- package/build/lib/types/HAPServiceConfigType.d.ts +0 -26
- package/build/lib/types/HAPServiceNodeType.d.ts +0 -38
- package/build/lib/types/HAPStatusConfigType.d.ts +0 -5
- package/build/lib/types/HAPStatusNodeType.d.ts +0 -12
- package/build/lib/types/HostType.d.ts +0 -5
- package/build/lib/types/NodeType.d.ts +0 -3
- package/build/lib/types/PublishTimersType.d.ts +0 -4
- package/build/lib/types/hap-nodejs/HapAdaptiveLightingControllerMode.d.ts +0 -5
- package/build/lib/types/hap-nodejs/HapCategories.d.ts +0 -41
- package/build/lib/types/storage/SerializedHostType.d.ts +0 -5
- package/build/lib/types/storage/StorageType.d.ts +0 -8
- package/build/lib/utils/AccessoryUtils.d.ts +0 -1
- package/build/lib/utils/BridgeUtils.d.ts +0 -1
- package/build/lib/utils/CharacteristicUtils.d.ts +0 -1
- package/build/lib/utils/CharacteristicUtils2.d.ts +0 -1
- package/build/lib/utils/NodeStatusUtils.d.ts +0 -17
- package/build/lib/utils/ServiceUtils.d.ts +0 -1
- package/build/lib/utils/ServiceUtils2.d.ts +0 -1
- package/build/lib/utils/index.d.ts +0 -1
- package/build/nodes/bridge.d.ts +0 -1
- package/build/nodes/nrchkb.d.ts +0 -1
- package/build/nodes/service.d.ts +0 -1
- package/build/nodes/service2.d.ts +0 -1
- package/build/nodes/standalone.d.ts +0 -1
- package/build/nodes/status.d.ts +0 -1
package/build/lib/Storage.js
CHANGED
|
@@ -1,100 +1,165 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
11
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Storage_exports = {};
|
|
30
|
+
__export(Storage_exports, {
|
|
31
|
+
Storage: () => Storage
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(Storage_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
|
35
|
+
var import_logger = require("@nrchkb/logger");
|
|
36
|
+
var import_node_persist = __toESM(require("node-persist"));
|
|
37
|
+
var import_uuid = require("uuid");
|
|
38
|
+
var import_NRCHKBError = __toESM(require("./NRCHKBError"));
|
|
39
|
+
var import_StorageType = require("./types/storage/StorageType");
|
|
13
40
|
class Storage {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return node_persist_1.default.set(itemName, value);
|
|
30
|
-
}
|
|
31
|
-
static saveCallback(eventCallback, ttl = 10000) {
|
|
32
|
-
const callbackID = (0, uuid_1.v4)();
|
|
33
|
-
Storage.memoryStorage[callbackID] = eventCallback;
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
if (callbackID in Storage.memoryStorage) {
|
|
36
|
-
Storage.log.debug(`Callback ${callbackID} timeout`);
|
|
37
|
-
eventCallback.callback();
|
|
38
|
-
delete Storage.memoryStorage[callbackID];
|
|
39
|
-
}
|
|
40
|
-
}, ttl);
|
|
41
|
-
return callbackID;
|
|
42
|
-
}
|
|
43
|
-
static saveCustomCharacteristics(value) {
|
|
44
|
-
return Storage.save(StorageType_1.StorageType.CUSTOM_CHARACTERISTICS, undefined, value);
|
|
45
|
-
}
|
|
46
|
-
static saveService(key, value) {
|
|
47
|
-
return Storage.save(StorageType_1.StorageType.SERVICE, key, value);
|
|
48
|
-
}
|
|
49
|
-
static saveAccessory(key, value) {
|
|
50
|
-
return Storage.save(StorageType_1.StorageType.ACCESSORY, key, value);
|
|
41
|
+
static {
|
|
42
|
+
this.storageInitialized = false;
|
|
43
|
+
}
|
|
44
|
+
static {
|
|
45
|
+
this.memoryStorage = /* @__PURE__ */ new Map();
|
|
46
|
+
}
|
|
47
|
+
static {
|
|
48
|
+
this.MAX_CALLBACKS = 1e3;
|
|
49
|
+
}
|
|
50
|
+
static {
|
|
51
|
+
this.log = (0, import_logger.logger)("NRCHKB", "Storage");
|
|
52
|
+
}
|
|
53
|
+
static storagePath() {
|
|
54
|
+
if (!Storage.storageInitialized) {
|
|
55
|
+
throw new import_NRCHKBError.default("Storage path was not initialized!");
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
return Storage.customStoragePath;
|
|
58
|
+
}
|
|
59
|
+
static init(...storagePathSegments) {
|
|
60
|
+
Storage.customStoragePath = import_node_path.default.resolve(...storagePathSegments);
|
|
61
|
+
Storage.storageInitialized = true;
|
|
62
|
+
Storage.log.trace("Initializing");
|
|
63
|
+
return import_node_persist.default.init({ dir: Storage.storagePath() });
|
|
64
|
+
}
|
|
65
|
+
static save(type, key, value) {
|
|
66
|
+
const itemName = key ? `${type}-${key}` : type;
|
|
67
|
+
Storage.log.trace(`Saving ${itemName}:${value}`);
|
|
68
|
+
return import_node_persist.default.set(itemName, value);
|
|
69
|
+
}
|
|
70
|
+
static saveCallback(eventCallback, ttl = 1e4) {
|
|
71
|
+
const callbackID = (0, import_uuid.v4)();
|
|
72
|
+
const currentSize = Storage.memoryStorage.size;
|
|
73
|
+
if (currentSize >= Storage.MAX_CALLBACKS) {
|
|
74
|
+
Storage.log.debug(
|
|
75
|
+
`Callback storage at maximum capacity (${currentSize}/${Storage.MAX_CALLBACKS}). Dropping oldest callbacks.`
|
|
76
|
+
);
|
|
77
|
+
const keysToDelete = Math.ceil(Storage.MAX_CALLBACKS * 0.1);
|
|
78
|
+
const iterator = Storage.memoryStorage.keys();
|
|
79
|
+
for (let index = 0; index < keysToDelete; index += 1) {
|
|
80
|
+
const oldestKey = iterator.next();
|
|
81
|
+
if (oldestKey.done) {
|
|
82
|
+
break;
|
|
66
83
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return new Promise((resolve, reject) => {
|
|
74
|
-
Storage.load(StorageType_1.StorageType.SERVICE, key).then((value) => {
|
|
75
|
-
if (value === undefined) {
|
|
76
|
-
reject('Service data not exists');
|
|
77
|
-
}
|
|
78
|
-
else if ('primaryService' in value) {
|
|
79
|
-
resolve(value);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
reject('Service data corrupted');
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
static loadAccessory(key) {
|
|
88
|
-
return Storage.load(StorageType_1.StorageType.ACCESSORY, key);
|
|
89
|
-
}
|
|
90
|
-
static loadHost(key) {
|
|
91
|
-
return Storage.load(StorageType_1.StorageType.HOST, key);
|
|
84
|
+
const entry = Storage.memoryStorage.get(oldestKey.value);
|
|
85
|
+
if (entry) {
|
|
86
|
+
clearTimeout(entry.timeoutHandle);
|
|
87
|
+
}
|
|
88
|
+
Storage.memoryStorage.delete(oldestKey.value);
|
|
89
|
+
}
|
|
92
90
|
}
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
const timeoutHandle = setTimeout(() => {
|
|
92
|
+
const entry = Storage.memoryStorage.get(callbackID);
|
|
93
|
+
if (entry) {
|
|
94
|
+
Storage.log.debug(`Callback ${callbackID} timeout`);
|
|
95
|
+
Storage.memoryStorage.delete(callbackID);
|
|
96
|
+
entry.eventCallback.callback();
|
|
97
|
+
}
|
|
98
|
+
}, ttl);
|
|
99
|
+
Storage.memoryStorage.set(callbackID, {
|
|
100
|
+
eventCallback,
|
|
101
|
+
timeoutHandle
|
|
102
|
+
});
|
|
103
|
+
return callbackID;
|
|
104
|
+
}
|
|
105
|
+
static saveCustomCharacteristics(value) {
|
|
106
|
+
return Storage.save(
|
|
107
|
+
import_StorageType.StorageType.CUSTOM_CHARACTERISTICS,
|
|
108
|
+
void 0,
|
|
109
|
+
value
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
static saveService(key, value) {
|
|
113
|
+
return Storage.save(import_StorageType.StorageType.SERVICE, key, value);
|
|
114
|
+
}
|
|
115
|
+
static saveAccessory(key, value) {
|
|
116
|
+
return Storage.save(import_StorageType.StorageType.ACCESSORY, key, value);
|
|
117
|
+
}
|
|
118
|
+
static saveHost(key, serializedHost) {
|
|
119
|
+
return Storage.save(import_StorageType.StorageType.HOST, key, serializedHost);
|
|
120
|
+
}
|
|
121
|
+
static load(type, key) {
|
|
122
|
+
const itemName = key ? `${type}-${key}` : type;
|
|
123
|
+
Storage.log.trace(`Loading ${itemName}`);
|
|
124
|
+
return import_node_persist.default.get(itemName);
|
|
125
|
+
}
|
|
126
|
+
static loadCallback(key) {
|
|
127
|
+
const entry = Storage.memoryStorage.get(key);
|
|
128
|
+
if (entry) {
|
|
129
|
+
Storage.log.trace(`Returning callback ${key}`);
|
|
130
|
+
clearTimeout(entry.timeoutHandle);
|
|
131
|
+
Storage.memoryStorage.delete(key);
|
|
132
|
+
return entry.eventCallback;
|
|
95
133
|
}
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
136
|
+
static loadCustomCharacteristics() {
|
|
137
|
+
return Storage.load(import_StorageType.StorageType.CUSTOM_CHARACTERISTICS);
|
|
138
|
+
}
|
|
139
|
+
static loadService(key) {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
Storage.load(import_StorageType.StorageType.SERVICE, key).then((value) => {
|
|
142
|
+
if (value === void 0) {
|
|
143
|
+
reject("Service data not exists");
|
|
144
|
+
} else if ("primaryService" in value) {
|
|
145
|
+
resolve(value);
|
|
146
|
+
} else {
|
|
147
|
+
reject("Service data corrupted");
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
static loadAccessory(key) {
|
|
153
|
+
return Storage.load(import_StorageType.StorageType.ACCESSORY, key);
|
|
154
|
+
}
|
|
155
|
+
static loadHost(key) {
|
|
156
|
+
return Storage.load(import_StorageType.StorageType.HOST, key);
|
|
157
|
+
}
|
|
158
|
+
static uuid4Validate(uuid) {
|
|
159
|
+
return (0, import_uuid.validate)(uuid) && (0, import_uuid.version)(uuid) === 4;
|
|
160
|
+
}
|
|
96
161
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Storage
|
|
100
|
-
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
Storage
|
|
165
|
+
});
|