node-red-contrib-homekit-bridged 2.0.0-dev.1 → 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 -146
  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 -290
  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 -112
  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 -368
  45. package/build/lib/utils/ServiceUtils2.js +519 -304
  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 -1885
  72. package/examples/demo/02 - Air Purifier.json +279 -279
  73. package/examples/demo/03 - Air Quality sensor with Battery.json +254 -254
  74. package/examples/demo/04 - Dimmable Bulb.json +172 -172
  75. package/examples/demo/05 - Color Bulb (HSV).json +195 -195
  76. package/examples/demo/06 - Fan (simple, 3 speeds).json +240 -240
  77. package/examples/demo/07 - Fan (with speed, oscillate, rotation direction).json +175 -175
  78. package/examples/demo/08 - CO2 detector.json +224 -224
  79. package/examples/demo/09 - CO (carbon monoxide) example.json +255 -255
  80. package/examples/demo/10 - Door window contact sensor.json +234 -234
  81. package/examples/demos (advanced)/01 - Television with inputs and speaker.json +541 -541
  82. package/examples/switch/01 - Plain Switch.json +178 -178
  83. package/package.json +95 -82
  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
@@ -0,0 +1,203 @@
1
+ "use strict";
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 });
11
+ };
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 registry_exports = {};
30
+ __export(registry_exports, {
31
+ NRCHKB_NODE_RED_PLUGIN_TYPE: () => NRCHKB_NODE_RED_PLUGIN_TYPE,
32
+ clearPluginsForTest: () => clearPluginsForTest,
33
+ getPlugin: () => getPlugin,
34
+ listPlugins: () => listPlugins,
35
+ normalizePluginId: () => normalizePluginId,
36
+ registerNodeRedPlugins: () => registerNodeRedPlugins,
37
+ registerPlugin: () => registerPlugin,
38
+ registerPluginFromModule: () => registerPluginFromModule,
39
+ registerPluginFromPackage: () => registerPluginFromPackage,
40
+ validatePluginMetadata: () => validatePluginMetadata
41
+ });
42
+ module.exports = __toCommonJS(registry_exports);
43
+ var import_node_fs = __toESM(require("node:fs"));
44
+ var import_node_path = __toESM(require("node:path"));
45
+ var import_node_url = require("node:url");
46
+ const NRCHKB_NODE_RED_PLUGIN_TYPE = "nrchkb-homekit-plugin";
47
+ const registry = /* @__PURE__ */ new Map();
48
+ const normalizePluginId = (packageName, pluginName) => `${packageName}:${pluginName}`;
49
+ const assertNonEmpty = (field, value) => {
50
+ if (typeof value !== "string" || value.trim().length === 0) {
51
+ throw new Error(`Plugin metadata field "${field}" is required.`);
52
+ }
53
+ };
54
+ const validatePluginMetadata = (metadata) => {
55
+ assertNonEmpty("packageName", metadata.packageName);
56
+ assertNonEmpty("pluginName", metadata.pluginName);
57
+ assertNonEmpty("displayName", metadata.displayName);
58
+ assertNonEmpty("author", metadata.author);
59
+ assertNonEmpty("version", metadata.version);
60
+ assertNonEmpty("description", metadata.description);
61
+ if (!metadata.capabilities || typeof metadata.capabilities !== "object") {
62
+ throw new Error('Plugin metadata field "capabilities" is required.');
63
+ }
64
+ if (metadata.prerequisites?.serviceNames && (!Array.isArray(metadata.prerequisites.serviceNames) || metadata.prerequisites.serviceNames.some(
65
+ (serviceName) => typeof serviceName !== "string" || serviceName.trim().length === 0
66
+ ))) {
67
+ throw new Error(
68
+ "Plugin metadata prerequisites.serviceNames must be an array of service names."
69
+ );
70
+ }
71
+ if (metadata.serviceNames) {
72
+ if (!Array.isArray(metadata.serviceNames) || metadata.serviceNames.some(
73
+ (serviceName) => typeof serviceName !== "string" || serviceName.trim().length === 0
74
+ )) {
75
+ throw new Error(
76
+ "Plugin metadata serviceNames must be an array of service names."
77
+ );
78
+ }
79
+ }
80
+ if (metadata.attachment && !["inline", "config-node"].includes(metadata.attachment)) {
81
+ throw new Error(
82
+ 'Plugin metadata attachment must be "inline" or "config-node".'
83
+ );
84
+ }
85
+ if (metadata.editor && (!Array.isArray(metadata.editor.sections) || metadata.editor.sections.some(
86
+ (section) => section.title !== void 0 && typeof section.title !== "string" || section.description !== void 0 && typeof section.description !== "string" || section.icon !== void 0 && typeof section.icon !== "string" || section.collapsed !== void 0 && typeof section.collapsed !== "boolean" || !Array.isArray(section.fields) || section.fields.some(
87
+ (field) => typeof field.path !== "string" || field.path.trim().length === 0 || typeof field.label !== "string" || field.label.trim().length === 0 || ![
88
+ "text",
89
+ "number",
90
+ "checkbox",
91
+ "select",
92
+ "password",
93
+ "textarea",
94
+ "config-node",
95
+ "dynamic-select"
96
+ ].includes(field.type)
97
+ )
98
+ ))) {
99
+ throw new Error(
100
+ "Plugin metadata editor.sections must contain valid editor field definitions."
101
+ );
102
+ }
103
+ const expectedId = normalizePluginId(
104
+ metadata.packageName,
105
+ metadata.pluginName
106
+ );
107
+ if (metadata.id !== expectedId) {
108
+ throw new Error(
109
+ `Plugin id "${metadata.id}" must match normalized id "${expectedId}".`
110
+ );
111
+ }
112
+ return {
113
+ ...metadata,
114
+ attachment: metadata.attachment ?? "inline"
115
+ };
116
+ };
117
+ const registerPlugin = (metadata, factory) => {
118
+ const validMetadata = validatePluginMetadata(metadata);
119
+ if (registry.has(validMetadata.id)) {
120
+ throw new Error(`Plugin "${validMetadata.id}" is already registered.`);
121
+ }
122
+ const plugin = {
123
+ metadata: validMetadata,
124
+ factory
125
+ };
126
+ registry.set(validMetadata.id, plugin);
127
+ return plugin;
128
+ };
129
+ const registerPluginFromPackage = (packageJson, metadata, factory) => {
130
+ const packageName = metadata.packageName ?? packageJson.name;
131
+ const version = metadata.version ?? packageJson.version;
132
+ if (!packageName) {
133
+ throw new Error("Plugin packageName could not be resolved.");
134
+ }
135
+ if (!version) {
136
+ throw new Error("Plugin version could not be resolved.");
137
+ }
138
+ return registerPlugin(
139
+ {
140
+ ...metadata,
141
+ packageName,
142
+ version,
143
+ id: metadata.id ?? normalizePluginId(packageName, metadata.pluginName)
144
+ },
145
+ factory
146
+ );
147
+ };
148
+ const findNearestPackageJson = (startFile) => {
149
+ let current = import_node_path.default.dirname(startFile);
150
+ while (current !== import_node_path.default.dirname(current)) {
151
+ const candidate = import_node_path.default.join(current, "package.json");
152
+ if (import_node_fs.default.existsSync(candidate)) {
153
+ return JSON.parse(import_node_fs.default.readFileSync(candidate, "utf8"));
154
+ }
155
+ current = import_node_path.default.dirname(current);
156
+ }
157
+ throw new Error(`Could not find package.json for ${startFile}.`);
158
+ };
159
+ const registerPluginFromModule = (importMetaUrl, metadata, factory) => {
160
+ const modulePath = (0, import_node_url.fileURLToPath)(importMetaUrl);
161
+ const packageJson = findNearestPackageJson(modulePath);
162
+ if (metadata.packageName && metadata.packageName !== packageJson.name) {
163
+ throw new Error(
164
+ `Plugin packageName "${metadata.packageName}" does not match nearest package "${packageJson.name}".`
165
+ );
166
+ }
167
+ return registerPluginFromPackage(packageJson, metadata, factory);
168
+ };
169
+ const getPlugin = (id) => registry.get(id);
170
+ const listPlugins = () => Array.from(registry.values());
171
+ const registerNodeRedPlugins = (RED) => {
172
+ const nodeRedPlugins = RED?.plugins?.getPluginsByType?.(
173
+ NRCHKB_NODE_RED_PLUGIN_TYPE
174
+ );
175
+ nodeRedPlugins?.forEach((definition) => {
176
+ if (definition.type !== NRCHKB_NODE_RED_PLUGIN_TYPE || !definition.metadata || !definition.factory || registry.has(definition.metadata.id)) {
177
+ return;
178
+ }
179
+ try {
180
+ registerPlugin(definition.metadata, definition.factory);
181
+ } catch (error) {
182
+ RED?.log?.warn?.(
183
+ `Skipping NRCHKB plugin "${definition.metadata.id}" because registration failed: ${error}`
184
+ );
185
+ }
186
+ });
187
+ };
188
+ const clearPluginsForTest = () => {
189
+ registry.clear();
190
+ };
191
+ // Annotate the CommonJS export names for ESM import in node:
192
+ 0 && (module.exports = {
193
+ NRCHKB_NODE_RED_PLUGIN_TYPE,
194
+ clearPluginsForTest,
195
+ getPlugin,
196
+ listPlugins,
197
+ normalizePluginId,
198
+ registerNodeRedPlugins,
199
+ registerPlugin,
200
+ registerPluginFromModule,
201
+ registerPluginFromPackage,
202
+ validatePluginMetadata
203
+ });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var import_node_fs = require("node:fs");
4
+ var import_node_path = require("node:path");
5
+ var import_HomeKitService2Migration = require("../lib/migration/HomeKitService2Migration");
6
+ const usage = () => {
7
+ console.error(
8
+ "Usage: node build/scripts/migrate-homekit-service-flows.js <flow-file.json> [output-file.json]"
9
+ );
10
+ };
11
+ const parseFlowFile = (filePath) => {
12
+ const content = (0, import_node_fs.readFileSync)(filePath, "utf8");
13
+ return JSON.parse(content);
14
+ };
15
+ const migrate = (flowPath) => {
16
+ const parsed = parseFlowFile(flowPath);
17
+ if (!Array.isArray(parsed)) {
18
+ throw new Error(
19
+ "Flow file must contain a JSON array of Node-RED nodes."
20
+ );
21
+ }
22
+ return (0, import_HomeKitService2Migration.migrateHomeKitServiceFlow)(parsed);
23
+ };
24
+ const [, , inputPath, outputPath] = process.argv;
25
+ if (!inputPath) {
26
+ usage();
27
+ process.exitCode = 1;
28
+ } else {
29
+ try {
30
+ const inputFile = (0, import_node_path.resolve)(inputPath);
31
+ const result = migrate(inputFile);
32
+ const destination = outputPath ? (0, import_node_path.resolve)(outputPath) : inputFile;
33
+ (0, import_node_fs.writeFileSync)(
34
+ destination,
35
+ `${JSON.stringify(result.nodes, null, 4)}
36
+ `,
37
+ "utf8"
38
+ );
39
+ console.log(
40
+ `Migrated ${result.migrated} homekit-service node(s), including ${result.cameraMigrated} camera node(s); skipped ${result.skipped}.`
41
+ );
42
+ console.log(`Wrote ${destination}`);
43
+ } catch (error) {
44
+ console.error(error instanceof Error ? error.message : error);
45
+ process.exitCode = 1;
46
+ }
47
+ }