node-red-contrib-homekit-bridged 2.0.0-dev.5 → 2.0.0-dev.8

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 (128) hide show
  1. package/build/lib/HAPHostNode.js +183 -141
  2. package/build/lib/HAPServiceNode.js +199 -172
  3. package/build/lib/HAPServiceNode2.js +207 -172
  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 -288
  8. package/build/lib/camera/CameraControl.js +119 -84
  9. package/build/lib/camera/CameraDelegate.js +481 -404
  10. package/build/lib/camera/MP4StreamingServer.js +148 -139
  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 +82 -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 -375
  45. package/build/lib/utils/ServiceUtils2.js +519 -309
  46. package/build/lib/utils/index.js +10 -11
  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 +544 -307
  55. package/build/nodes/service.js +5 -6
  56. package/build/nodes/service2.html +1721 -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 -40
  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 -84
  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/camera/CameraControl.d.ts +0 -3
  91. package/build/lib/camera/CameraDelegate.d.ts +0 -38
  92. package/build/lib/camera/MP4StreamingServer.d.ts +0 -26
  93. package/build/lib/hap/HAPCharacteristic.d.ts +0 -9
  94. package/build/lib/hap/HAPService.d.ts +0 -6
  95. package/build/lib/hap/eve-app/EveCharacteristics.d.ts +0 -20
  96. package/build/lib/hap/eve-app/EveServices.d.ts +0 -5
  97. package/build/lib/types/AccessoryInformationType.d.ts +0 -11
  98. package/build/lib/types/CameraConfigType.d.ts +0 -24
  99. package/build/lib/types/CustomCharacteristicType.d.ts +0 -6
  100. package/build/lib/types/HAPHostConfigType.d.ts +0 -22
  101. package/build/lib/types/HAPHostNodeType.d.ts +0 -14
  102. package/build/lib/types/HAPService2ConfigType.d.ts +0 -6
  103. package/build/lib/types/HAPService2NodeType.d.ts +0 -7
  104. package/build/lib/types/HAPServiceConfigType.d.ts +0 -26
  105. package/build/lib/types/HAPServiceNodeType.d.ts +0 -38
  106. package/build/lib/types/HAPStatusConfigType.d.ts +0 -5
  107. package/build/lib/types/HAPStatusNodeType.d.ts +0 -12
  108. package/build/lib/types/HostType.d.ts +0 -5
  109. package/build/lib/types/NodeType.d.ts +0 -3
  110. package/build/lib/types/PublishTimersType.d.ts +0 -4
  111. package/build/lib/types/hap-nodejs/HapAdaptiveLightingControllerMode.d.ts +0 -5
  112. package/build/lib/types/hap-nodejs/HapCategories.d.ts +0 -41
  113. package/build/lib/types/storage/SerializedHostType.d.ts +0 -5
  114. package/build/lib/types/storage/StorageType.d.ts +0 -8
  115. package/build/lib/utils/AccessoryUtils.d.ts +0 -1
  116. package/build/lib/utils/BridgeUtils.d.ts +0 -1
  117. package/build/lib/utils/CharacteristicUtils.d.ts +0 -1
  118. package/build/lib/utils/CharacteristicUtils2.d.ts +0 -1
  119. package/build/lib/utils/NodeStatusUtils.d.ts +0 -17
  120. package/build/lib/utils/ServiceUtils.d.ts +0 -1
  121. package/build/lib/utils/ServiceUtils2.d.ts +0 -1
  122. package/build/lib/utils/index.d.ts +0 -1
  123. package/build/nodes/bridge.d.ts +0 -1
  124. package/build/nodes/nrchkb.d.ts +0 -1
  125. package/build/nodes/service.d.ts +0 -1
  126. package/build/nodes/service2.d.ts +0 -1
  127. package/build/nodes/standalone.d.ts +0 -1
  128. package/build/nodes/status.d.ts +0 -1
@@ -1,178 +1,213 @@
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 __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
4
15
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const hap_nodejs_1 = require("@homebridge/hap-nodejs");
7
- const logger_1 = require("@nrchkb/logger");
8
- const NRCHKBError_1 = __importDefault(require("./NRCHKBError"));
9
- const HostType_1 = __importDefault(require("./types/HostType"));
10
- const NodeStatusUtils_1 = require("./utils/NodeStatusUtils");
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_hap_nodejs = require("@homebridge/hap-nodejs");
25
+ var import_logger = require("@nrchkb/logger");
26
+ var import_NRCHKBError = __toESM(require("./NRCHKBError"));
27
+ var import_HostType = __toESM(require("./types/HostType"));
28
+ var import_NodeStatusUtils = require("./utils/NodeStatusUtils");
11
29
  module.exports = (RED) => {
12
- const nrchkbConfigCompatibilityOverride = function () {
13
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', this.config.name, this);
14
- if (this.config.isParent === undefined) {
15
- log.trace(`nrchkbConfigCompatibilityOverride => self.config.isParent=${this.config.isParent} value changed to true`);
16
- this.config.isParent = true;
17
- }
18
- if (this.config.hostType === undefined) {
19
- log.trace(`nrchkbConfigCompatibilityOverride => self.config.hostType=${this.config.hostType} value changed to HostType.BRIDGE`);
20
- this.config.hostType = HostType_1.default.BRIDGE;
21
- }
22
- };
23
- const preInit = function (config) {
24
- this.nodeStatusUtils = new NodeStatusUtils_1.NodeStatusUtils(this);
25
- this.config = config;
26
- this.name = this.config.name;
27
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', this.config.name, this);
28
- this.RED = RED;
29
- this.publishTimers = {};
30
- nrchkbConfigCompatibilityOverride.call(this);
31
- RED.nodes.createNode(this, this.config);
32
- const ServiceUtils = require('./utils/ServiceUtils2')(this);
33
- new Promise((resolve) => {
34
- if (this.config.waitForSetupMsg) {
35
- log.debug('Waiting for Setup message. It should be of format {"payload":{"nrchkb":{"setup":{}}}}');
36
- this.setupDone = false;
37
- this.nodeStatusUtils.setStatus({
38
- fill: 'blue',
39
- shape: 'dot',
40
- text: 'Waiting for Setup'
41
- });
42
- this.handleWaitForSetup = (msg) => ServiceUtils.handleWaitForSetup(this.config, msg, resolve);
43
- this.on('input', this.handleWaitForSetup);
44
- }
45
- else {
46
- resolve(this.config);
47
- }
48
- })
49
- .then((newConfig) => {
50
- init.call(this, newConfig);
51
- })
52
- .catch((error) => {
53
- log.error(`Error while starting Service due to ${error}`);
54
- });
55
- };
56
- const init = function (config) {
57
- this.config = config;
58
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', this.config.name, this);
59
- const ServiceUtils = require('./utils/ServiceUtils2')(this);
60
- if (this.config.isParent) {
61
- log.debug('Starting Parent Service');
62
- configure.call(this);
63
- this.configured = true;
64
- this.reachable = true;
65
- }
66
- else {
67
- const serviceType = config.serviceName === 'CameraControl' ? 'Camera' : 'Linked';
68
- ServiceUtils.waitForParent()
69
- .then(() => {
70
- log.debug(`Starting ${serviceType} Service`);
71
- configure.call(this);
72
- this.configured = true;
73
- })
74
- .catch((error) => {
75
- log.error(`Error while starting ${serviceType} Service due to ${error}`);
76
- });
77
- }
78
- };
79
- const configure = function () {
80
- var _a, _b;
81
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', this.config.name, this);
82
- const Utils = require('./utils')(this);
83
- const AccessoryUtils = Utils.AccessoryUtils;
84
- const BridgeUtils = Utils.BridgeUtils;
85
- const CharacteristicUtils = require('./utils/CharacteristicUtils2')(this);
86
- const ServiceUtils = require('./utils/ServiceUtils2')(this);
87
- let parentNode;
88
- if (this.config.isParent) {
89
- const hostId = this.config.hostType == HostType_1.default.BRIDGE
90
- ? this.config.bridge
91
- : this.config.accessoryId;
92
- this.hostNode = RED.nodes.getNode(hostId);
93
- if (!this.hostNode) {
94
- const message = `Host node ${this.config.hostType == HostType_1.default.BRIDGE ? 'Bridge' : 'Standalone Accessory'} ${hostId} not found`;
95
- log.error(message, false);
96
- throw new NRCHKBError_1.default(message);
97
- }
98
- this.childNodes = [];
99
- this.childNodes.push(this);
100
- }
101
- else {
102
- parentNode = RED.nodes.getNode(this.config.parentService);
103
- if (!parentNode) {
104
- log.error('Parent Node not assigned', false);
105
- throw new NRCHKBError_1.default('Parent Node not assigned');
106
- }
107
- this.parentNode = parentNode;
108
- this.parentService = this.parentNode.service;
109
- if (!this.parentService) {
110
- log.error('Parent Service not assigned', false);
111
- throw new NRCHKBError_1.default('Parent Service not assigned');
112
- }
113
- this.hostNode = this.parentNode.hostNode;
114
- (_a = this.parentNode.childNodes) === null || _a === void 0 ? void 0 : _a.push(this);
115
- this.accessory = this.parentNode.accessory;
116
- }
117
- this.name = this.config.name;
118
- if (Object.hasOwn(this, '_flow') &&
119
- Object.hasOwn(this, '_alias') &&
120
- (this._flow ? Object(this._flow).hasOwn('TYPE') : false) &&
121
- ((_b = this._flow) === null || _b === void 0 ? void 0 : _b.TYPE) === 'subflow') {
122
- this.uniqueIdentifier = `${this._alias}/${this._flow.path}`;
123
- }
124
- else {
125
- this.uniqueIdentifier = this.id;
126
- }
127
- const subtypeUUID = hap_nodejs_1.uuid.generate(this.uniqueIdentifier);
128
- if (this.config.hostType == HostType_1.default.BRIDGE) {
129
- if (this.config.isParent) {
130
- const accessoryUUID = hap_nodejs_1.uuid.generate('A' +
131
- this.uniqueIdentifier +
132
- this.name +
133
- this.config.manufacturer +
134
- this.config.serialNo +
135
- this.config.model);
136
- this.accessory = AccessoryUtils.getOrCreate(this.hostNode.host, {
137
- name: this.name,
138
- UUID: accessoryUUID,
139
- manufacturer: this.config.manufacturer,
140
- serialNo: this.config.serialNo,
141
- model: this.config.model,
142
- firmwareRev: this.config.firmwareRev,
143
- hardwareRev: this.config.hardwareRev,
144
- softwareRev: this.config.softwareRev
145
- }, subtypeUUID);
146
- this.onIdentify = AccessoryUtils.onIdentify;
147
- this.accessory.on('identify', this.onIdentify);
148
- }
149
- }
150
- else {
151
- log.debug('Binding Service accessory as Standalone Accessory');
152
- this.accessory = this.hostNode.host;
153
- }
154
- this.service = ServiceUtils.getOrCreate(this.accessory, {
155
- name: this.name,
156
- UUID: subtypeUUID,
157
- serviceName: this.config.serviceName,
158
- config: this.config
159
- }, this.parentService);
160
- this.characteristicProperties = CharacteristicUtils.load(this.service, this.config);
161
- ServiceUtils.configureAdaptiveLightning();
162
- if (this.config.isParent) {
163
- BridgeUtils.delayedPublish(this);
164
- }
30
+ const nrchkbConfigCompatibilityOverride = function() {
31
+ const log = (0, import_logger.logger)("NRCHKB", "HAPServiceNode2", this.config.name, this);
32
+ if (this.config.isParent === void 0) {
33
+ log.trace(
34
+ `nrchkbConfigCompatibilityOverride => self.config.isParent=${this.config.isParent} value changed to true`
35
+ );
36
+ this.config.isParent = true;
37
+ }
38
+ if (this.config.hostType === void 0) {
39
+ log.trace(
40
+ `nrchkbConfigCompatibilityOverride => self.config.hostType=${this.config.hostType} value changed to HostType.BRIDGE`
41
+ );
42
+ this.config.hostType = import_HostType.default.BRIDGE;
43
+ }
44
+ };
45
+ const preInit = function(config) {
46
+ this.nodeStatusUtils = new import_NodeStatusUtils.NodeStatusUtils(this);
47
+ this.config = config;
48
+ this.name = this.config.name;
49
+ this.nrchkbClosing = false;
50
+ const log = (0, import_logger.logger)("NRCHKB", "HAPServiceNode2", this.config.name, this);
51
+ this.RED = RED;
52
+ this.publishTimers = {};
53
+ nrchkbConfigCompatibilityOverride.call(this);
54
+ RED.nodes.createNode(this, this.config);
55
+ const ServiceUtils = require("./utils/ServiceUtils2")(this);
56
+ new Promise((resolve) => {
57
+ if (this.config.waitForSetupMsg) {
58
+ log.debug(
59
+ 'Waiting for Setup message. It should be of format {"payload":{"nrchkb":{"setup":{}}}}'
60
+ );
61
+ this.setupDone = false;
165
62
  this.nodeStatusUtils.setStatus({
166
- fill: 'yellow',
167
- shape: 'ring',
168
- text: this.hostNode.config.pinCode
63
+ fill: "blue",
64
+ shape: "dot",
65
+ text: "Waiting for Setup"
169
66
  });
170
- this.supported = CharacteristicUtils.subscribeAndGetSupported(this.service);
171
- this.on('input', ServiceUtils.onInput);
172
- this.on('close', ServiceUtils.onClose);
173
- };
174
- return {
175
- preInit,
176
- init
177
- };
67
+ this.handleWaitForSetup = (msg) => ServiceUtils.handleWaitForSetup(this.config, msg, resolve);
68
+ this.on("input", this.handleWaitForSetup);
69
+ } else {
70
+ resolve(this.config);
71
+ }
72
+ }).then((newConfig) => {
73
+ init.call(this, newConfig);
74
+ }).catch((error) => {
75
+ log.error(`Error while starting Service due to ${error}`);
76
+ });
77
+ };
78
+ const init = function(config) {
79
+ this.config = config;
80
+ const log = (0, import_logger.logger)("NRCHKB", "HAPServiceNode2", this.config.name, this);
81
+ const ServiceUtils = require("./utils/ServiceUtils2")(this);
82
+ if (this.config.isParent) {
83
+ log.debug("Starting Parent Service");
84
+ configure.call(this).then(() => {
85
+ this.configured = true;
86
+ this.reachable = true;
87
+ }).catch((error) => {
88
+ log.error(
89
+ `Error while starting Parent Service due to ${error}`
90
+ );
91
+ });
92
+ } else {
93
+ const serviceType = config.serviceName === "Camera" ? "Camera" : "Linked";
94
+ ServiceUtils.waitForParent().then(async () => {
95
+ log.debug(`Starting ${serviceType} Service`);
96
+ await configure.call(this);
97
+ this.configured = true;
98
+ }).catch((error) => {
99
+ log.error(
100
+ `Error while starting ${serviceType} Service due to ${error}`
101
+ );
102
+ });
103
+ }
104
+ };
105
+ const configure = async function() {
106
+ const log = (0, import_logger.logger)("NRCHKB", "HAPServiceNode2", this.config.name, this);
107
+ const Utils = require("./utils")(this);
108
+ const AccessoryUtils = Utils.AccessoryUtils;
109
+ const BridgeUtils = Utils.BridgeUtils;
110
+ const CharacteristicUtils = require("./utils/CharacteristicUtils2")(
111
+ this
112
+ );
113
+ const ServiceUtils = require("./utils/ServiceUtils2")(this);
114
+ let parentNode;
115
+ if (this.config.isParent) {
116
+ const hostId = this.config.hostType == import_HostType.default.BRIDGE ? this.config.bridge : this.config.accessoryId;
117
+ this.hostNode = RED.nodes.getNode(hostId);
118
+ if (!this.hostNode) {
119
+ const message = `Host node ${this.config.hostType == import_HostType.default.BRIDGE ? "Bridge" : "Standalone Accessory"} ${hostId} not found`;
120
+ log.error(message, false);
121
+ throw new import_NRCHKBError.default(message);
122
+ }
123
+ this.childNodes = [];
124
+ this.childNodes.push(this);
125
+ } else {
126
+ parentNode = RED.nodes.getNode(
127
+ this.config.parentService
128
+ );
129
+ if (!parentNode) {
130
+ log.error("Parent Node not assigned", false);
131
+ throw new import_NRCHKBError.default("Parent Node not assigned");
132
+ }
133
+ this.parentNode = parentNode;
134
+ this.parentService = this.parentNode.service;
135
+ if (!this.parentService) {
136
+ log.error("Parent Service not assigned", false);
137
+ throw new import_NRCHKBError.default("Parent Service not assigned");
138
+ }
139
+ this.hostNode = this.parentNode.hostNode;
140
+ this.parentNode.childNodes?.push(this);
141
+ this.accessory = this.parentNode.accessory;
142
+ }
143
+ this.name = this.config.name;
144
+ if (Object.hasOwn(this, "_flow") && Object.hasOwn(this, "_alias") && (this._flow ? Object(this._flow).hasOwn("TYPE") : false) && this._flow?.TYPE === "subflow") {
145
+ this.uniqueIdentifier = `${this._alias}/${this._flow.path}`;
146
+ } else {
147
+ this.uniqueIdentifier = this.id;
148
+ }
149
+ const subtypeUUID = import_hap_nodejs.uuid.generate(this.uniqueIdentifier);
150
+ if (this.config.hostType == import_HostType.default.BRIDGE) {
151
+ if (this.config.isParent) {
152
+ const accessoryUUID = import_hap_nodejs.uuid.generate(
153
+ "A" + this.uniqueIdentifier + this.name + this.config.manufacturer + this.config.serialNo + this.config.model
154
+ );
155
+ this.accessory = AccessoryUtils.getOrCreate(
156
+ this.hostNode.host,
157
+ {
158
+ name: this.name,
159
+ UUID: accessoryUUID,
160
+ manufacturer: this.config.manufacturer,
161
+ serialNo: this.config.serialNo,
162
+ model: this.config.model,
163
+ firmwareRev: this.config.firmwareRev,
164
+ hardwareRev: this.config.hardwareRev,
165
+ softwareRev: this.config.softwareRev
166
+ },
167
+ subtypeUUID
168
+ // subtype of the primary service for identification
169
+ );
170
+ this.onIdentify = AccessoryUtils.onIdentify;
171
+ this.accessory.on("identify", this.onIdentify);
172
+ }
173
+ } else {
174
+ log.debug("Binding Service accessory as Standalone Accessory");
175
+ this.accessory = this.hostNode.host;
176
+ }
177
+ this.service = await ServiceUtils.getOrCreate(
178
+ this.accessory,
179
+ {
180
+ name: this.name,
181
+ UUID: subtypeUUID,
182
+ serviceName: this.config.serviceName,
183
+ config: this.config
184
+ },
185
+ this.parentService
186
+ );
187
+ if (this.nrchkbClosing) {
188
+ return;
189
+ }
190
+ this.characteristicProperties = CharacteristicUtils.load(
191
+ this.service,
192
+ this.config
193
+ );
194
+ ServiceUtils.configureAdaptiveLightning();
195
+ if (this.config.isParent) {
196
+ BridgeUtils.delayedPublish(this);
197
+ }
198
+ this.nodeStatusUtils.setStatus({
199
+ fill: "yellow",
200
+ shape: "ring",
201
+ text: this.hostNode.config.pinCode
202
+ });
203
+ this.supported = CharacteristicUtils.subscribeAndGetSupported(
204
+ this.service
205
+ );
206
+ this.on("input", ServiceUtils.onInput);
207
+ this.on("close", ServiceUtils.onClose);
208
+ };
209
+ return {
210
+ preInit,
211
+ init
212
+ };
178
213
  };
@@ -1,5 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var NRCHKBError_exports = {};
20
+ __export(NRCHKBError_exports, {
21
+ default: () => NRCHKBError_default
22
+ });
23
+ module.exports = __toCommonJS(NRCHKBError_exports);
3
24
  class NRCHKBError extends Error {
4
25
  }
5
- exports.default = NRCHKBError;
26
+ var NRCHKBError_default = NRCHKBError;
@@ -0,0 +1,62 @@
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 PairingQRCode_exports = {};
30
+ __export(PairingQRCode_exports, {
31
+ createPairingQRCodeDataURL: () => createPairingQRCodeDataURL,
32
+ formatPinCodeForPairing: () => formatPinCodeForPairing
33
+ });
34
+ module.exports = __toCommonJS(PairingQRCode_exports);
35
+ var import_qrcode = require("homekit-code/lib/commands/qrcode/qrcode.utils");
36
+ var import_NRCHKBError = __toESM(require("./NRCHKBError"));
37
+ const pinCodeRegex = /^(?:\d{3}-\d{2}-\d{3}|\d{4}-\d{4})$/;
38
+ const formatPinCodeForPairing = (pinCode) => {
39
+ if (!pinCode) {
40
+ throw new import_NRCHKBError.default("Pin code cannot be empty");
41
+ }
42
+ if (!pinCodeRegex.test(pinCode)) {
43
+ throw new import_NRCHKBError.default(`Invalid HomeKit pin code format: ${pinCode}`);
44
+ }
45
+ const cleanPinCode = pinCode.replace(/\D/g, "");
46
+ return {
47
+ bottom: cleanPinCode.slice(4),
48
+ top: cleanPinCode.slice(0, 4)
49
+ };
50
+ };
51
+ const createPairingQRCodeDataURL = async (setupUri, pinCode) => {
52
+ const svg = await (0, import_qrcode.composeQrCode)({
53
+ pairingCode: pinCode.replace(/\D/g, ""),
54
+ setupUri
55
+ });
56
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ createPairingQRCodeDataURL,
61
+ formatPinCodeForPairing
62
+ });