node-red-contrib-homekit-bridged 2.0.0-dev.0 → 2.0.0-dev.10

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 (125) hide show
  1. package/build/lib/HAPHostNode.js +185 -148
  2. package/build/lib/HAPServiceNode.js +200 -177
  3. package/build/lib/HAPServiceNode2.js +208 -177
  4. package/build/lib/NRCHKBError.js +23 -2
  5. package/build/lib/PairingQRCode.js +62 -0
  6. package/build/lib/Storage.js +152 -90
  7. package/build/lib/api.js +654 -291
  8. package/build/lib/camera/CameraControl.js +125 -0
  9. package/build/lib/camera/CameraDelegate.js +507 -0
  10. package/build/lib/camera/MP4StreamingServer.js +159 -0
  11. package/build/lib/hap/HAPCharacteristic.js +25 -4
  12. package/build/lib/hap/HAPService.js +25 -4
  13. package/build/lib/hap/eve-app/EveCharacteristics.js +124 -81
  14. package/build/lib/hap/eve-app/EveServices.js +50 -17
  15. package/build/lib/hap/hap-nodejs.js +32 -0
  16. package/build/lib/migration/HomeKitService2Migration.js +34 -0
  17. package/build/lib/migration/NodeMigration.js +75 -0
  18. package/build/lib/types/AccessoryInformationType.js +15 -1
  19. package/build/lib/types/CameraConfigType.js +15 -1
  20. package/build/lib/types/CustomCharacteristicType.js +15 -1
  21. package/build/lib/types/HAPHostConfigType.js +15 -1
  22. package/build/lib/types/HAPHostNodeType.js +15 -1
  23. package/build/lib/types/HAPService2ConfigType.js +15 -1
  24. package/build/lib/types/HAPService2NodeType.js +15 -1
  25. package/build/lib/types/HAPServiceConfigType.js +15 -1
  26. package/build/lib/types/HAPServiceNodeType.js +15 -1
  27. package/build/lib/types/HAPStatusConfigType.js +15 -1
  28. package/build/lib/types/HAPStatusNodeType.js +15 -1
  29. package/build/lib/types/HostType.js +28 -7
  30. package/build/lib/types/NodeType.js +15 -1
  31. package/build/lib/types/PublishTimersType.js +15 -1
  32. package/build/lib/types/UniFiControllerConfigType.js +16 -0
  33. package/build/lib/types/hap-nodejs/HapAdaptiveLightingControllerMode.js +28 -7
  34. package/build/lib/types/hap-nodejs/HapCategories.js +64 -43
  35. package/build/lib/types/storage/SerializedHostType.js +15 -1
  36. package/build/lib/types/storage/StorageType.js +34 -10
  37. package/build/lib/unifi/ProtectDiscovery.js +80 -0
  38. package/build/lib/utils/AccessoryUtils.js +152 -110
  39. package/build/lib/utils/BridgeUtils.js +95 -39
  40. package/build/lib/utils/CharacteristicUtils.js +5 -49
  41. package/build/lib/utils/CharacteristicUtils2.js +5 -49
  42. package/build/lib/utils/CharacteristicUtilsBase.js +81 -0
  43. package/build/lib/utils/NodeStatusUtils.js +89 -40
  44. package/build/lib/utils/ServiceUtils.js +433 -371
  45. package/build/lib/utils/ServiceUtils2.js +519 -305
  46. package/build/lib/utils/index.js +11 -12
  47. package/build/nodes/bridge.html +206 -168
  48. package/build/nodes/bridge.js +27 -9
  49. package/build/nodes/locales/en-US/node-red-contrib-homekit-bridged.json +22 -0
  50. package/build/nodes/nrchkb.html +1753 -117
  51. package/build/nodes/nrchkb.js +66 -88
  52. package/build/nodes/plugin-instance.html +509 -0
  53. package/build/nodes/plugin-instance.js +46 -0
  54. package/build/nodes/service.html +557 -306
  55. package/build/nodes/service.js +5 -6
  56. package/build/nodes/service2.html +1735 -455
  57. package/build/nodes/service2.js +5 -8
  58. package/build/nodes/standalone.html +208 -176
  59. package/build/nodes/standalone.js +27 -9
  60. package/build/nodes/status.html +51 -18
  61. package/build/nodes/status.js +47 -41
  62. package/build/nodes/unifi-controller.html +92 -0
  63. package/build/nodes/unifi-controller.js +20 -0
  64. package/build/plugins/embedded/homebridge-camera-ffmpeg/index.js +479 -0
  65. package/build/plugins/embedded/homebridge-unifi-protect/index.js +521 -0
  66. package/build/plugins/embedded/index.js +58 -0
  67. package/build/plugins/nrchkb-homekit-plugins.js +17 -0
  68. package/build/plugins/registry/index.js +203 -0
  69. package/build/plugins/registry/types.js +16 -0
  70. package/build/scripts/migrate-homekit-service-flows.js +47 -0
  71. package/examples/demo/01 - ALL Demos single import.json +1885 -2139
  72. package/examples/demo/02 - Air Purifier.json +12 -61
  73. package/examples/demo/03 - Air Quality sensor with Battery.json +8 -36
  74. package/examples/demo/04 - Dimmable Bulb.json +4 -21
  75. package/examples/demo/05 - Color Bulb (HSV).json +5 -26
  76. package/examples/demo/06 - Fan (simple, 3 speeds).json +6 -31
  77. package/examples/demo/07 - Fan (with speed, oscillate, rotation direction).json +4 -21
  78. package/examples/demo/08 - CO2 detector.json +8 -39
  79. package/examples/demo/09 - CO (carbon monoxide) example.json +9 -44
  80. package/examples/demo/10 - Door window contact sensor.json +8 -39
  81. package/examples/demos (advanced)/01 - Television with inputs and speaker.json +19 -85
  82. package/examples/switch/01 - Plain Switch.json +179 -199
  83. package/package.json +48 -34
  84. package/build/lib/HAPHostNode.d.ts +0 -1
  85. package/build/lib/HAPServiceNode.d.ts +0 -1
  86. package/build/lib/HAPServiceNode2.d.ts +0 -1
  87. package/build/lib/NRCHKBError.d.ts +0 -3
  88. package/build/lib/Storage.d.ts +0 -30
  89. package/build/lib/api.d.ts +0 -1
  90. package/build/lib/hap/HAPCharacteristic.d.ts +0 -9
  91. package/build/lib/hap/HAPService.d.ts +0 -6
  92. package/build/lib/hap/eve-app/EveCharacteristics.d.ts +0 -20
  93. package/build/lib/hap/eve-app/EveServices.d.ts +0 -5
  94. package/build/lib/types/AccessoryInformationType.d.ts +0 -11
  95. package/build/lib/types/CameraConfigType.d.ts +0 -24
  96. package/build/lib/types/CustomCharacteristicType.d.ts +0 -6
  97. package/build/lib/types/HAPHostConfigType.d.ts +0 -22
  98. package/build/lib/types/HAPHostNodeType.d.ts +0 -14
  99. package/build/lib/types/HAPService2ConfigType.d.ts +0 -6
  100. package/build/lib/types/HAPService2NodeType.d.ts +0 -7
  101. package/build/lib/types/HAPServiceConfigType.d.ts +0 -26
  102. package/build/lib/types/HAPServiceNodeType.d.ts +0 -38
  103. package/build/lib/types/HAPStatusConfigType.d.ts +0 -5
  104. package/build/lib/types/HAPStatusNodeType.d.ts +0 -12
  105. package/build/lib/types/HostType.d.ts +0 -5
  106. package/build/lib/types/NodeType.d.ts +0 -3
  107. package/build/lib/types/PublishTimersType.d.ts +0 -4
  108. package/build/lib/types/hap-nodejs/HapAdaptiveLightingControllerMode.d.ts +0 -5
  109. package/build/lib/types/hap-nodejs/HapCategories.d.ts +0 -41
  110. package/build/lib/types/storage/SerializedHostType.d.ts +0 -5
  111. package/build/lib/types/storage/StorageType.d.ts +0 -8
  112. package/build/lib/utils/AccessoryUtils.d.ts +0 -1
  113. package/build/lib/utils/BridgeUtils.d.ts +0 -1
  114. package/build/lib/utils/CharacteristicUtils.d.ts +0 -1
  115. package/build/lib/utils/CharacteristicUtils2.d.ts +0 -1
  116. package/build/lib/utils/NodeStatusUtils.d.ts +0 -17
  117. package/build/lib/utils/ServiceUtils.d.ts +0 -1
  118. package/build/lib/utils/ServiceUtils2.d.ts +0 -1
  119. package/build/lib/utils/index.d.ts +0 -1
  120. package/build/nodes/bridge.d.ts +0 -1
  121. package/build/nodes/nrchkb.d.ts +0 -1
  122. package/build/nodes/service.d.ts +0 -1
  123. package/build/nodes/service2.d.ts +0 -1
  124. package/build/nodes/standalone.d.ts +0 -1
  125. package/build/nodes/status.d.ts +0 -1
@@ -1,100 +1,162 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Storage = void 0;
7
- const logger_1 = require("@nrchkb/logger");
8
- const node_persist_1 = __importDefault(require("node-persist"));
9
- const path_1 = __importDefault(require("path"));
10
- const uuid_1 = require("uuid");
11
- const NRCHKBError_1 = __importDefault(require("./NRCHKBError"));
12
- const StorageType_1 = require("./types/storage/StorageType");
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
- static storagePath() {
15
- if (!Storage.storageInitialized) {
16
- throw new NRCHKBError_1.default('Storage path was not initialized!');
17
- }
18
- return Storage.customStoragePath;
19
- }
20
- static init(...storagePathSegments) {
21
- Storage.customStoragePath = path_1.default.resolve(...storagePathSegments);
22
- Storage.storageInitialized = true;
23
- Storage.log.trace('Initializing');
24
- return node_persist_1.default.init({ dir: Storage.storagePath() });
25
- }
26
- static save(type, key, value) {
27
- const itemName = key ? `${type}-${key}` : type;
28
- Storage.log.trace(`Saving ${itemName}:${value}`);
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);
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!");
48
56
  }
49
- static saveAccessory(key, value) {
50
- return Storage.save(StorageType_1.StorageType.ACCESSORY, key, value);
51
- }
52
- static saveHost(key, serializedHost) {
53
- return Storage.save(StorageType_1.StorageType.HOST, key, serializedHost);
54
- }
55
- static load(type, key) {
56
- const itemName = key ? `${type}-${key}` : type;
57
- Storage.log.trace(`Loading ${itemName}`);
58
- return node_persist_1.default.get(itemName);
59
- }
60
- static loadCallback(key) {
61
- if (key in Storage.memoryStorage) {
62
- Storage.log.trace(`Returning callback ${key}`);
63
- const value = Storage.memoryStorage[key];
64
- delete Storage.memoryStorage[key];
65
- return value;
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
- return undefined;
68
- }
69
- static loadCustomCharacteristics() {
70
- return Storage.load(StorageType_1.StorageType.CUSTOM_CHARACTERISTICS);
71
- }
72
- static loadService(key) {
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
- });
84
+ const entry = Storage.memoryStorage.get(oldestKey.value);
85
+ if (entry) {
86
+ clearTimeout(entry.timeoutHandle);
87
+ }
88
+ Storage.memoryStorage.delete(oldestKey.value);
89
+ }
86
90
  }
87
- static loadAccessory(key) {
88
- return Storage.load(StorageType_1.StorageType.ACCESSORY, key);
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;
89
133
  }
90
- static loadHost(key) {
91
- return Storage.load(StorageType_1.StorageType.HOST, key);
134
+ return void 0;
135
+ }
136
+ static loadCustomCharacteristics() {
137
+ return Storage.load(import_StorageType.StorageType.CUSTOM_CHARACTERISTICS);
138
+ }
139
+ static async loadService(key) {
140
+ const value = await Storage.load(import_StorageType.StorageType.SERVICE, key);
141
+ if (value === void 0) {
142
+ throw "Service data not exists";
92
143
  }
93
- static uuid4Validate(uuid) {
94
- return (0, uuid_1.validate)(uuid) && (0, uuid_1.version)(uuid) === 4;
144
+ if (typeof value === "object" && value !== null && "primaryService" in value) {
145
+ return value;
95
146
  }
147
+ throw "Service data corrupted";
148
+ }
149
+ static loadAccessory(key) {
150
+ return Storage.load(import_StorageType.StorageType.ACCESSORY, key);
151
+ }
152
+ static loadHost(key) {
153
+ return Storage.load(import_StorageType.StorageType.HOST, key);
154
+ }
155
+ static uuid4Validate(uuid) {
156
+ return (0, import_uuid.validate)(uuid) && (0, import_uuid.version)(uuid) === 4;
157
+ }
96
158
  }
97
- exports.Storage = Storage;
98
- Storage.storageInitialized = false;
99
- Storage.memoryStorage = {};
100
- Storage.log = (0, logger_1.logger)('NRCHKB', 'Storage');
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ Storage
162
+ });