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
|
@@ -1,44 +1,87 @@
|
|
|
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 __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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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_logger = require("@nrchkb/logger");
|
|
25
|
+
var import_HostType = __toESM(require("../types/HostType"));
|
|
26
|
+
const PUBLISH_CHECK_INTERVAL_MS = 250;
|
|
27
|
+
const buildBridgeUtils = () => {
|
|
28
|
+
const canPublishHost = (node) => {
|
|
29
|
+
let hasPendingService = false;
|
|
30
|
+
node.RED.nodes.eachNode((currentNode) => {
|
|
31
|
+
if (hasPendingService) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (currentNode.type !== "homekit-service" && currentNode.type !== "homekit-service2") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const serviceNode = node.RED.nodes.getNode(currentNode.id);
|
|
38
|
+
if (serviceNode?.hostNode?.id === node.hostNode.id && !serviceNode.configured) {
|
|
39
|
+
hasPendingService = true;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return !hasPendingService;
|
|
43
|
+
};
|
|
44
|
+
const delayedPublish = (node) => {
|
|
45
|
+
const log = (0, import_logger.logger)("NRCHKB", "BridgeUtils", node.config.name, node);
|
|
46
|
+
if (!node.hostNode.published) {
|
|
47
|
+
if (node.publishTimers[node.hostNode.id] !== void 0) {
|
|
48
|
+
clearTimeout(node.publishTimers[node.hostNode.id]);
|
|
49
|
+
}
|
|
50
|
+
const hostTypeName = node.hostNode.hostType == import_HostType.default.BRIDGE ? "Bridge" : "Standalone Accessory";
|
|
51
|
+
const tryPublish = () => {
|
|
52
|
+
try {
|
|
53
|
+
if (!node.hostNode.published) {
|
|
54
|
+
if (!canPublishHost(node)) {
|
|
55
|
+
node.publishTimers[node.hostNode.id] = setTimeout(
|
|
56
|
+
tryPublish,
|
|
57
|
+
PUBLISH_CHECK_INTERVAL_MS
|
|
58
|
+
);
|
|
59
|
+
return;
|
|
14
60
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
log.error(`${hostTypeName} publish failed due to ${error}`);
|
|
32
|
-
node.nodeStatusUtils.setStatus({
|
|
33
|
-
fill: 'red',
|
|
34
|
-
shape: 'ring',
|
|
35
|
-
text: `Error while publishing ${hostTypeName}`
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}, 5000);
|
|
61
|
+
const published = node.hostNode.publish();
|
|
62
|
+
if (published) {
|
|
63
|
+
log.debug(`${hostTypeName} published`);
|
|
64
|
+
} else {
|
|
65
|
+
log.error(`${hostTypeName} not published`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
log.error(`${hostTypeName} publish failed due to ${error}`);
|
|
70
|
+
node.nodeStatusUtils.setStatus({
|
|
71
|
+
fill: "red",
|
|
72
|
+
shape: "ring",
|
|
73
|
+
text: `Error while publishing ${hostTypeName}`
|
|
74
|
+
});
|
|
39
75
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
76
|
+
};
|
|
77
|
+
node.publishTimers[node.hostNode.id] = setTimeout(
|
|
78
|
+
tryPublish,
|
|
79
|
+
PUBLISH_CHECK_INTERVAL_MS
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
delayedPublish
|
|
85
|
+
};
|
|
44
86
|
};
|
|
87
|
+
module.exports = buildBridgeUtils;
|
|
@@ -1,51 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const log = (0, logger_1.logger)('NRCHKB', 'CharacteristicUtils', node.config.name, node);
|
|
7
|
-
const ServiceUtils = require('./ServiceUtils')(node);
|
|
8
|
-
const load = (service, config) => {
|
|
9
|
-
let characteristicProperties = {};
|
|
10
|
-
if (config.characteristicProperties &&
|
|
11
|
-
config.characteristicProperties.length > 0) {
|
|
12
|
-
characteristicProperties = JSON.parse(config.characteristicProperties.replace(/\${(.*?)}/g, (_, envName) => node.RED.util.evaluateNodeProperty(envName, 'env', node, {})));
|
|
13
|
-
log.trace('Evaluating value:');
|
|
14
|
-
log.trace(config.characteristicProperties);
|
|
15
|
-
log.trace('Evaluated as:');
|
|
16
|
-
log.trace(JSON.stringify(characteristicProperties));
|
|
17
|
-
for (const key in characteristicProperties) {
|
|
18
|
-
if (!Object.hasOwn(characteristicProperties, key))
|
|
19
|
-
continue;
|
|
20
|
-
const characteristic = service.getCharacteristic(hap_nodejs_1.Characteristic[key]);
|
|
21
|
-
if (characteristic && characteristicProperties[key]) {
|
|
22
|
-
log.debug(`Found Characteristic Properties for ${key}`);
|
|
23
|
-
characteristic.setProps(characteristicProperties[key]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return characteristicProperties;
|
|
28
|
-
};
|
|
29
|
-
const subscribeAndGetSupported = (service) => {
|
|
30
|
-
const supported = [];
|
|
31
|
-
const allCharacteristics = service.characteristics.concat(service.optionalCharacteristics);
|
|
32
|
-
node.onCharacteristicGet = ServiceUtils.onCharacteristicGet;
|
|
33
|
-
node.onCharacteristicSet = ServiceUtils.onCharacteristicSet(service.characteristics);
|
|
34
|
-
node.onCharacteristicChange = ServiceUtils.onCharacteristicChange(service.characteristics);
|
|
35
|
-
allCharacteristics.forEach((characteristic) => {
|
|
36
|
-
const cKey = characteristic.constructor.name;
|
|
37
|
-
supported.push(cKey);
|
|
38
|
-
characteristic.on('get', node.onCharacteristicGet);
|
|
39
|
-
characteristic.on('set', node.onCharacteristicSet);
|
|
40
|
-
characteristic.on('change', node.onCharacteristicChange);
|
|
41
|
-
if (characteristic.displayName === 'Current Temperature') {
|
|
42
|
-
characteristic.props.minValue = -100;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return [...new Set(supported)];
|
|
46
|
-
};
|
|
47
|
-
return {
|
|
48
|
-
load: load,
|
|
49
|
-
subscribeAndGetSupported: subscribeAndGetSupported
|
|
50
|
-
};
|
|
2
|
+
const buildCharacteristicUtilsBase = require("./CharacteristicUtilsBase");
|
|
3
|
+
const buildServiceUtils = require("./ServiceUtils");
|
|
4
|
+
const buildCharacteristicUtils = (node) => {
|
|
5
|
+
return buildCharacteristicUtilsBase(node, buildServiceUtils, { getHandlerUsesCharacteristics: false });
|
|
51
6
|
};
|
|
7
|
+
module.exports = buildCharacteristicUtils;
|
|
@@ -1,51 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const log = (0, logger_1.logger)('NRCHKB', 'CharacteristicUtils', node.config.name, node);
|
|
7
|
-
const ServiceUtils = require('./ServiceUtils2')(node);
|
|
8
|
-
const load = (service, config) => {
|
|
9
|
-
let characteristicProperties = {};
|
|
10
|
-
if (config.characteristicProperties &&
|
|
11
|
-
config.characteristicProperties.length > 0) {
|
|
12
|
-
characteristicProperties = JSON.parse(config.characteristicProperties.replace(/\${(.*?)}/g, (_, envName) => node.RED.util.evaluateNodeProperty(envName, 'env', node, {})));
|
|
13
|
-
log.trace('Evaluating value:');
|
|
14
|
-
log.trace(config.characteristicProperties);
|
|
15
|
-
log.trace('Evaluated as:');
|
|
16
|
-
log.trace(JSON.stringify(characteristicProperties));
|
|
17
|
-
for (const key in characteristicProperties) {
|
|
18
|
-
if (!Object.hasOwn(characteristicProperties, key))
|
|
19
|
-
continue;
|
|
20
|
-
const characteristic = service.getCharacteristic(hap_nodejs_1.Characteristic[key]);
|
|
21
|
-
if (characteristic && characteristicProperties[key]) {
|
|
22
|
-
log.debug(`Found Characteristic Properties for ${key}`);
|
|
23
|
-
characteristic.setProps(characteristicProperties[key]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return characteristicProperties;
|
|
28
|
-
};
|
|
29
|
-
const subscribeAndGetSupported = (service) => {
|
|
30
|
-
const supported = [];
|
|
31
|
-
const allCharacteristics = service.characteristics.concat(service.optionalCharacteristics);
|
|
32
|
-
node.onCharacteristicGet = ServiceUtils.onCharacteristicGet(service.characteristics);
|
|
33
|
-
node.onCharacteristicSet = ServiceUtils.onCharacteristicSet(service.characteristics);
|
|
34
|
-
node.onCharacteristicChange = ServiceUtils.onCharacteristicChange(service.characteristics);
|
|
35
|
-
allCharacteristics.forEach((characteristic) => {
|
|
36
|
-
const cKey = characteristic.constructor.name;
|
|
37
|
-
supported.push(cKey);
|
|
38
|
-
characteristic.on('get', node.onCharacteristicGet);
|
|
39
|
-
characteristic.on('set', node.onCharacteristicSet);
|
|
40
|
-
characteristic.on('change', node.onCharacteristicChange);
|
|
41
|
-
if (characteristic.displayName === 'Current Temperature') {
|
|
42
|
-
characteristic.props.minValue = -100;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return [...new Set(supported)];
|
|
46
|
-
};
|
|
47
|
-
return {
|
|
48
|
-
load: load,
|
|
49
|
-
subscribeAndGetSupported: subscribeAndGetSupported
|
|
50
|
-
};
|
|
2
|
+
const buildCharacteristicUtilsBase = require("./CharacteristicUtilsBase");
|
|
3
|
+
const buildServiceUtils2 = require("./ServiceUtils2");
|
|
4
|
+
const buildCharacteristicUtils2 = (node) => {
|
|
5
|
+
return buildCharacteristicUtilsBase(node, buildServiceUtils2, { getHandlerUsesCharacteristics: true });
|
|
51
6
|
};
|
|
7
|
+
module.exports = buildCharacteristicUtils2;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_hap_nodejs = require("@homebridge/hap-nodejs");
|
|
3
|
+
var import_logger = require("@nrchkb/logger");
|
|
4
|
+
const ENV_VAR_REGEX = /\${(.*?)}/g;
|
|
5
|
+
const buildCharacteristicUtilsBase = (node, serviceUtilsFactory, options) => {
|
|
6
|
+
const log = (0, import_logger.logger)("NRCHKB", "CharacteristicUtils", node.config.name, node);
|
|
7
|
+
const ServiceUtils = serviceUtilsFactory(node);
|
|
8
|
+
const load = (service, config) => {
|
|
9
|
+
let characteristicProperties = {};
|
|
10
|
+
if (config.characteristicProperties && config.characteristicProperties.length > 0) {
|
|
11
|
+
try {
|
|
12
|
+
characteristicProperties = JSON.parse(
|
|
13
|
+
config.characteristicProperties.replace(
|
|
14
|
+
ENV_VAR_REGEX,
|
|
15
|
+
(_, envName) => node.RED.util.evaluateNodeProperty(
|
|
16
|
+
envName,
|
|
17
|
+
"env",
|
|
18
|
+
node,
|
|
19
|
+
{}
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
log.error(
|
|
25
|
+
`Invalid characteristicProperties JSON, ignoring custom properties: ${error}`
|
|
26
|
+
);
|
|
27
|
+
node.nodeStatusUtils.setStatus({
|
|
28
|
+
fill: "red",
|
|
29
|
+
shape: "ring",
|
|
30
|
+
text: "Invalid characteristic properties"
|
|
31
|
+
});
|
|
32
|
+
return characteristicProperties;
|
|
33
|
+
}
|
|
34
|
+
log.trace("Evaluating value:");
|
|
35
|
+
log.trace(config.characteristicProperties);
|
|
36
|
+
log.trace("Evaluated as:");
|
|
37
|
+
log.trace(JSON.stringify(characteristicProperties));
|
|
38
|
+
for (const key in characteristicProperties) {
|
|
39
|
+
if (!Object.hasOwn(characteristicProperties, key)) continue;
|
|
40
|
+
const characteristic = service.getCharacteristic(
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
import_hap_nodejs.Characteristic[key]
|
|
43
|
+
);
|
|
44
|
+
if (characteristic && characteristicProperties[key]) {
|
|
45
|
+
log.debug(`Found Characteristic Properties for ${key}`);
|
|
46
|
+
characteristic.setProps(characteristicProperties[key]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return characteristicProperties;
|
|
51
|
+
};
|
|
52
|
+
const subscribeAndGetSupported = (service) => {
|
|
53
|
+
const supported = /* @__PURE__ */ new Set();
|
|
54
|
+
const allCharacteristics = service.characteristics.concat(
|
|
55
|
+
service.optionalCharacteristics
|
|
56
|
+
);
|
|
57
|
+
node.onCharacteristicGet = options.getHandlerUsesCharacteristics ? ServiceUtils.onCharacteristicGet(service.characteristics) : ServiceUtils.onCharacteristicGet;
|
|
58
|
+
node.onCharacteristicSet = ServiceUtils.onCharacteristicSet(
|
|
59
|
+
service.characteristics
|
|
60
|
+
);
|
|
61
|
+
node.onCharacteristicChange = ServiceUtils.onCharacteristicChange(
|
|
62
|
+
service.characteristics
|
|
63
|
+
);
|
|
64
|
+
allCharacteristics.forEach((characteristic) => {
|
|
65
|
+
const cKey = characteristic.constructor.name;
|
|
66
|
+
supported.add(cKey);
|
|
67
|
+
characteristic.on("get", node.onCharacteristicGet);
|
|
68
|
+
characteristic.on("set", node.onCharacteristicSet);
|
|
69
|
+
characteristic.on("change", node.onCharacteristicChange);
|
|
70
|
+
if (characteristic.displayName === "Current Temperature") {
|
|
71
|
+
characteristic.props.minValue = -100;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return supported;
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
load,
|
|
78
|
+
subscribeAndGetSupported
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
module.exports = buildCharacteristicUtilsBase;
|
|
@@ -1,48 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
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 NodeStatusUtils_exports = {};
|
|
20
|
+
__export(NodeStatusUtils_exports, {
|
|
21
|
+
NodeStatusUtils: () => NodeStatusUtils
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(NodeStatusUtils_exports);
|
|
24
|
+
const DEFAULT_STATUS_TYPE = "MSG";
|
|
25
|
+
let nextStatusId = 0;
|
|
5
26
|
class NodeStatusUtils {
|
|
6
|
-
|
|
7
|
-
|
|
27
|
+
constructor(node) {
|
|
28
|
+
this.node = node;
|
|
29
|
+
this.pendingTimeouts = /* @__PURE__ */ new Set();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set the status
|
|
33
|
+
* @param status - status to be displayed
|
|
34
|
+
* @param timeout - if provided will clear the status after the timeout
|
|
35
|
+
*/
|
|
36
|
+
setStatus(status, timeout) {
|
|
37
|
+
this.node.status(status);
|
|
38
|
+
nextStatusId += 1;
|
|
39
|
+
const newStatusId = nextStatusId;
|
|
40
|
+
this.lastStatusId = newStatusId;
|
|
41
|
+
if (typeof status !== "string") {
|
|
42
|
+
this.lastStatusType = status.type ?? DEFAULT_STATUS_TYPE;
|
|
43
|
+
} else {
|
|
44
|
+
this.lastStatusType = DEFAULT_STATUS_TYPE;
|
|
8
45
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.node.status(status);
|
|
12
|
-
const newStatusId = Date.now();
|
|
13
|
-
this.lastStatusId = newStatusId;
|
|
14
|
-
if (typeof status !== 'string') {
|
|
15
|
-
this.lastStatusType = (_a = status.type) !== null && _a !== void 0 ? _a : DEFAULT_STATUS_TYPE;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.lastStatusType = DEFAULT_STATUS_TYPE;
|
|
19
|
-
}
|
|
20
|
-
if (timeout) {
|
|
21
|
-
this.clearStatus(newStatusId, timeout);
|
|
22
|
-
}
|
|
23
|
-
return newStatusId;
|
|
46
|
+
if (timeout) {
|
|
47
|
+
this.clearStatus(newStatusId, timeout);
|
|
24
48
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
return newStatusId;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clear the status by type, only if last status type is the same as the type provided
|
|
53
|
+
* @param type - type of status to be cleared
|
|
54
|
+
*/
|
|
55
|
+
clearStatusByType(type) {
|
|
56
|
+
if (this.lastStatusType === type) {
|
|
57
|
+
this.clearStatus();
|
|
29
58
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Clear the status
|
|
62
|
+
* @param statusId - if provided will clear the status only if the statusId is the same as the last statusId
|
|
63
|
+
* @param timeout - if provided will clear the status after the timeout
|
|
64
|
+
*/
|
|
65
|
+
clearStatus(statusId, timeout) {
|
|
66
|
+
if (statusId !== void 0) {
|
|
67
|
+
if (statusId === this.lastStatusId) {
|
|
68
|
+
if (timeout) {
|
|
69
|
+
const timeoutHandle = setTimeout(
|
|
70
|
+
(nodeStatusUtil) => {
|
|
71
|
+
nodeStatusUtil.pendingTimeouts.delete(timeoutHandle);
|
|
72
|
+
nodeStatusUtil.clearStatus(statusId);
|
|
73
|
+
},
|
|
74
|
+
timeout,
|
|
75
|
+
this
|
|
76
|
+
);
|
|
77
|
+
this.pendingTimeouts.add(timeoutHandle);
|
|
78
|
+
} else {
|
|
79
|
+
this.setStatus("");
|
|
45
80
|
}
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
this.setStatus("");
|
|
46
84
|
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Clean up all pending timeouts (call on node close)
|
|
88
|
+
*/
|
|
89
|
+
cleanup() {
|
|
90
|
+
this.pendingTimeouts.forEach((timeout) => clearTimeout(timeout));
|
|
91
|
+
this.pendingTimeouts.clear();
|
|
92
|
+
}
|
|
47
93
|
}
|
|
48
|
-
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
NodeStatusUtils
|
|
97
|
+
});
|