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,182 +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 self = this;
14
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', self.config.name, self);
15
- if (self.config.isParent === undefined) {
16
- log.trace(`nrchkbConfigCompatibilityOverride => self.config.isParent=${self.config.isParent} value changed to true`);
17
- self.config.isParent = true;
18
- }
19
- if (self.config.hostType === undefined) {
20
- log.trace(`nrchkbConfigCompatibilityOverride => self.config.hostType=${self.config.hostType} value changed to HostType.BRIDGE`);
21
- self.config.hostType = HostType_1.default.BRIDGE;
22
- }
23
- };
24
- const preInit = function (config) {
25
- const self = this;
26
- self.nodeStatusUtils = new NodeStatusUtils_1.NodeStatusUtils(self);
27
- self.config = config;
28
- self.name = self.config.name;
29
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', self.config.name, self);
30
- self.RED = RED;
31
- self.publishTimers = {};
32
- nrchkbConfigCompatibilityOverride.call(self);
33
- RED.nodes.createNode(self, self.config);
34
- const ServiceUtils = require('./utils/ServiceUtils2')(self);
35
- new Promise((resolve) => {
36
- if (self.config.waitForSetupMsg) {
37
- log.debug('Waiting for Setup message. It should be of format {"payload":{"nrchkb":{"setup":{}}}}');
38
- self.setupDone = false;
39
- self.nodeStatusUtils.setStatus({
40
- fill: 'blue',
41
- shape: 'dot',
42
- text: 'Waiting for Setup',
43
- });
44
- self.handleWaitForSetup = (msg) => ServiceUtils.handleWaitForSetup(self.config, msg, resolve);
45
- self.on('input', self.handleWaitForSetup);
46
- }
47
- else {
48
- resolve(self.config);
49
- }
50
- })
51
- .then((newConfig) => {
52
- init.call(self, newConfig);
53
- })
54
- .catch((error) => {
55
- log.error(`Error while starting Service due to ${error}`);
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;
62
+ this.nodeStatusUtils.setStatus({
63
+ fill: "blue",
64
+ shape: "dot",
65
+ text: "Waiting for Setup"
56
66
  });
57
- };
58
- const init = function (config) {
59
- const self = this;
60
- self.config = config;
61
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', self.config.name, self);
62
- const ServiceUtils = require('./utils/ServiceUtils2')(self);
63
- if (self.config.isParent) {
64
- log.debug('Starting Parent Service');
65
- configure.call(self);
66
- self.configured = true;
67
- self.reachable = true;
68
- }
69
- else {
70
- const serviceType = config.serviceName === 'CameraControl' ? 'Camera' : 'Linked';
71
- ServiceUtils.waitForParent()
72
- .then(() => {
73
- log.debug(`Starting ${serviceType} Service`);
74
- configure.call(self);
75
- self.configured = true;
76
- })
77
- .catch((error) => {
78
- log.error(`Error while starting ${serviceType} Service due to ${error}`);
79
- });
80
- }
81
- };
82
- const configure = function () {
83
- var _a, _b;
84
- const self = this;
85
- const log = (0, logger_1.logger)('NRCHKB', 'HAPServiceNode2', self.config.name, self);
86
- const Utils = require('./utils')(self);
87
- const AccessoryUtils = Utils.AccessoryUtils;
88
- const BridgeUtils = Utils.BridgeUtils;
89
- const CharacteristicUtils = require('./utils/CharacteristicUtils2')(self);
90
- const ServiceUtils = require('./utils/ServiceUtils2')(self);
91
- let parentNode;
92
- if (self.config.isParent) {
93
- const hostId = self.config.hostType == HostType_1.default.BRIDGE
94
- ? self.config.bridge
95
- : self.config.accessoryId;
96
- self.hostNode = RED.nodes.getNode(hostId);
97
- if (!self.hostNode) {
98
- const message = `Host node ${self.config.hostType == HostType_1.default.BRIDGE ? 'Bridge' : 'Standalone Accessory'} ${hostId} not found`;
99
- log.error(message, false);
100
- throw new NRCHKBError_1.default(message);
101
- }
102
- self.childNodes = [];
103
- self.childNodes.push(self);
104
- }
105
- else {
106
- parentNode = RED.nodes.getNode(self.config.parentService);
107
- if (!parentNode) {
108
- log.error('Parent Node not assigned', false);
109
- throw new NRCHKBError_1.default('Parent Node not assigned');
110
- }
111
- self.parentNode = parentNode;
112
- self.parentService = self.parentNode.service;
113
- if (!self.parentService) {
114
- log.error('Parent Service not assigned', false);
115
- throw new NRCHKBError_1.default('Parent Service not assigned');
116
- }
117
- self.hostNode = self.parentNode.hostNode;
118
- (_a = self.parentNode.childNodes) === null || _a === void 0 ? void 0 : _a.push(self);
119
- self.accessory = self.parentNode.accessory;
120
- }
121
- self.name = self.config.name;
122
- if (self.hasOwnProperty('_flow') &&
123
- self.hasOwnProperty('_alias') &&
124
- ((_b = self._flow) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('TYPE')) &&
125
- self._flow.TYPE === 'subflow') {
126
- self.uniqueIdentifier = self._alias + '/' + self._flow.path;
127
- }
128
- else {
129
- self.uniqueIdentifier = self.id;
130
- }
131
- const subtypeUUID = hap_nodejs_1.uuid.generate(self.uniqueIdentifier);
132
- if (self.config.hostType == HostType_1.default.BRIDGE) {
133
- if (self.config.isParent) {
134
- const accessoryUUID = hap_nodejs_1.uuid.generate('A' +
135
- self.uniqueIdentifier +
136
- self.name +
137
- self.config.manufacturer +
138
- self.config.serialNo +
139
- self.config.model);
140
- self.accessory = AccessoryUtils.getOrCreate(self.hostNode.host, {
141
- name: self.name,
142
- UUID: accessoryUUID,
143
- manufacturer: self.config.manufacturer,
144
- serialNo: self.config.serialNo,
145
- model: self.config.model,
146
- firmwareRev: self.config.firmwareRev,
147
- hardwareRev: self.config.hardwareRev,
148
- softwareRev: self.config.softwareRev,
149
- }, subtypeUUID);
150
- self.onIdentify = AccessoryUtils.onIdentify;
151
- self.accessory.on('identify', self.onIdentify);
152
- }
153
- }
154
- else {
155
- log.debug('Binding Service accessory as Standalone Accessory');
156
- self.accessory = self.hostNode.host;
157
- }
158
- self.service = ServiceUtils.getOrCreate(self.accessory, {
159
- name: self.name,
160
- UUID: subtypeUUID,
161
- serviceName: self.config.serviceName,
162
- config: self.config,
163
- }, self.parentService);
164
- self.characteristicProperties = CharacteristicUtils.load(self.service, self.config);
165
- ServiceUtils.configureAdaptiveLightning();
166
- if (self.config.isParent) {
167
- BridgeUtils.delayedPublish(self);
168
- }
169
- self.nodeStatusUtils.setStatus({
170
- fill: 'yellow',
171
- shape: 'ring',
172
- text: self.hostNode.config.pinCode,
173
- });
174
- self.supported = CharacteristicUtils.subscribeAndGetSupported(self.service);
175
- self.on('input', ServiceUtils.onInput);
176
- self.on('close', ServiceUtils.onClose);
177
- };
178
- return {
179
- preInit,
180
- init,
181
- };
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
+ };
182
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
+ });