hap-nodejs 0.12.3-beta.2 → 0.12.3-beta.21
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/README.md +1 -0
- package/dist/accessories/AirConditioner_accessory.js +24 -24
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +23 -23
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +292 -373
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +15 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +31 -21
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +45 -48
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +11 -11
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +8 -8
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +10 -10
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +11 -11
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +19 -19
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +17 -17
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +6 -6
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +36 -47
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.js +2 -2
- package/dist/accessories/types.js.map +1 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -28
- package/dist/index.js.map +1 -1
- package/dist/lib/Accessory.d.ts +1 -58
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +747 -1149
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +1 -2
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +392 -524
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.js +6 -10
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +2 -133
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +1467 -669
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +0 -10
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +216 -280
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +1 -51
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +474 -322
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.js +112 -104
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +0 -65
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +255 -278
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +318 -381
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +0 -1
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +1 -2
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +19 -3
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +217 -218
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +0 -4
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +189 -256
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/DoorbellController.js +38 -39
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +0 -14
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +340 -415
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.js +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +56 -57
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +259 -304
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +0 -5
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +252 -269
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.js +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -106
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +2000 -2995
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -32
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +820 -1147
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +383 -679
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +29 -29
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.js +1 -1
- package/dist/lib/model/AccessoryInfo.js +101 -136
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.js +86 -89
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.js +15 -16
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.js +49 -49
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +40 -44
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -1
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +7 -11
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.js +5 -27
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.js +8 -12
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +301 -409
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.js +31 -32
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.js +9 -12
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +32 -53
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -8
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.js +8 -13
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.js +2 -3
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.js +5 -5
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +0 -27
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +71 -113
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +0 -9
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +15 -33
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +0 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +10 -10
- package/dist/BridgedCore.d.ts +0 -2
- package/dist/BridgedCore.d.ts.map +0 -1
- package/dist/BridgedCore.js +0 -43
- package/dist/BridgedCore.js.map +0 -1
- package/dist/Core.d.ts +0 -2
- package/dist/Core.d.ts.map +0 -1
- package/dist/Core.js +0 -52
- package/dist/Core.js.map +0 -1
- package/dist/lib/AccessoryLoader.d.ts +0 -28
- package/dist/lib/AccessoryLoader.d.ts.map +0 -1
- package/dist/lib/AccessoryLoader.js +0 -166
- package/dist/lib/AccessoryLoader.js.map +0 -1
- package/dist/lib/camera/Camera.d.ts +0 -43
- package/dist/lib/camera/Camera.d.ts.map +0 -1
- package/dist/lib/camera/Camera.js +0 -36
- package/dist/lib/camera/Camera.js.map +0 -1
|
@@ -1,120 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f, e_7, _g, e_8, _h, e_9, _j, e_10, _k, e_11, _l, e_12, _m, e_13, _o, e_14, _p, e_15, _q, e_16, _r, e_17, _s, e_18, _t, e_19, _u, e_20, _v, e_21, _w;
|
|
3
|
-
var _x, _y, _z, _0, _1, _2, _3;
|
|
4
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
6
4
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
7
5
|
require("./CharacteristicDefinitions");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
9
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const simple_plist_1 = tslib_1.__importDefault(require("simple-plist"));
|
|
11
|
+
const Characteristic_1 = require("../Characteristic");
|
|
12
|
+
const uuid_1 = require("../util/uuid");
|
|
13
|
+
const generator_configuration_1 = require("./generator-configuration");
|
|
16
14
|
// noinspection JSUnusedLocalSymbols
|
|
17
15
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const temp = Characteristic_1.Characteristic; // this to have "../Characteristic" not being only type import, otherwise this would not result in a require statement
|
|
17
|
+
const command = new commander_1.Command("generate-definitions")
|
|
20
18
|
.version("1.0.0")
|
|
21
19
|
.option("-f, --force")
|
|
22
20
|
.option("-m, --metadata <path>", "Define a custom location for the plain-metadata.config file", "/System/Library/PrivateFrameworks/HomeKitDaemon.framework/Resources/plain-metadata.config")
|
|
23
21
|
.requiredOption("-s, --simulator <path>", "Define the path to the accessory simulator.");
|
|
24
22
|
command.parse(process.argv);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const options = command.opts();
|
|
24
|
+
const metadataFile = options.metadata;
|
|
25
|
+
const simulator = options.simulator;
|
|
28
26
|
if (!fs_1.default.existsSync(metadataFile)) {
|
|
29
|
-
console.warn(
|
|
27
|
+
console.warn(`The metadata file at '${metadataFile}' does not exist!`);
|
|
30
28
|
process.exit(1);
|
|
31
29
|
}
|
|
32
30
|
if (!fs_1.default.existsSync(simulator)) {
|
|
33
|
-
console.warn(
|
|
31
|
+
console.warn(`The simulator app directory '${simulator}' does not exist!`);
|
|
34
32
|
process.exit(1);
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const defaultPlist = path_1.default.resolve(simulator, "Contents/Frameworks/HAPAccessoryKit.framework/Resources/default.metadata.plist");
|
|
35
|
+
const defaultMfiPlist = path_1.default.resolve(simulator, "Contents/Frameworks/HAPAccessoryKit.framework/Resources/default_mfi.metadata.plist");
|
|
36
|
+
const plistData = simple_plist_1.default.readFileSync(metadataFile);
|
|
37
|
+
const simulatorPlistData = simple_plist_1.default.readFileSync(defaultPlist);
|
|
38
|
+
const simulatorMfiPlistData = fs_1.default.existsSync(defaultMfiPlist) ? simple_plist_1.default.readFileSync(defaultMfiPlist) : undefined;
|
|
41
39
|
if (plistData.SchemaVersion !== 1) {
|
|
42
|
-
console.warn(
|
|
40
|
+
console.warn(`Detected unsupported schema version ${plistData.SchemaVersion}!`);
|
|
43
41
|
}
|
|
44
42
|
if (plistData.PlistDictionary.SchemaVersion !== 1) {
|
|
45
|
-
console.warn(
|
|
43
|
+
console.warn(`Detect unsupported PlistDictionary schema version ${plistData.PlistDictionary.SchemaVersion}!`);
|
|
46
44
|
}
|
|
47
|
-
console.log(
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
console.log(`Parsing version ${plistData.Version}...`);
|
|
46
|
+
const shouldParseCharacteristics = checkWrittenVersion("./CharacteristicDefinitions.ts", plistData.Version);
|
|
47
|
+
const shouldParseServices = checkWrittenVersion("./ServiceDefinitions.ts", plistData.Version);
|
|
50
48
|
if (!options.force && (!shouldParseCharacteristics || !shouldParseServices)) {
|
|
51
49
|
console.log("Parsed schema version " + plistData.Version + " is older than what's already generated. " +
|
|
52
50
|
"User --force option to generate and overwrite nonetheless!");
|
|
53
51
|
process.exit(1);
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
const undefinedUnits = ["micrograms/m^3", "ppm"];
|
|
54
|
+
let characteristics;
|
|
55
|
+
const simulatorCharacteristics = new Map();
|
|
56
|
+
let services;
|
|
57
|
+
let units;
|
|
58
|
+
let categories;
|
|
59
|
+
const properties = new Map();
|
|
62
60
|
try {
|
|
63
61
|
characteristics = checkDefined(plistData.PlistDictionary.HAP.Characteristics);
|
|
64
62
|
services = checkDefined(plistData.PlistDictionary.HAP.Services);
|
|
65
63
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
64
|
units = checkDefined(plistData.PlistDictionary.HAP.Units);
|
|
67
65
|
categories = checkDefined(plistData.PlistDictionary.HomeKit.Categories);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
})), _5 = _4.next(); !_5.done; _5 = _4.next()) {
|
|
77
|
-
var _6 = tslib_1.__read(_5.value, 2), id = _6[0], definition = _6[1];
|
|
78
|
-
var perm = characteristicPerm(id);
|
|
79
|
-
if (perm) {
|
|
80
|
-
var num = 1 << definition.Position;
|
|
81
|
-
properties.set(num, perm);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
-
finally {
|
|
87
|
-
try {
|
|
88
|
-
if (_5 && !_5.done && (_a = _4.return)) _a.call(_4);
|
|
89
|
-
}
|
|
90
|
-
finally { if (e_1) throw e_1.error; }
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
for (var _7 = tslib_1.__values(simulatorPlistData.Characteristics), _8 = _7.next(); !_8.done; _8 = _7.next()) {
|
|
94
|
-
var characteristic = _8.value;
|
|
95
|
-
simulatorCharacteristics.set(characteristic.UUID, characteristic);
|
|
66
|
+
const props = checkDefined(plistData.PlistDictionary.HAP.Properties);
|
|
67
|
+
// noinspection JSUnusedLocalSymbols
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
|
+
for (const [id, definition] of Object.entries(props).sort(([a, aDef], [b, bDef]) => aDef.Position - bDef.Position)) {
|
|
70
|
+
const perm = characteristicPerm(id);
|
|
71
|
+
if (perm) {
|
|
72
|
+
const num = 1 << definition.Position;
|
|
73
|
+
properties.set(num, perm);
|
|
96
74
|
}
|
|
97
75
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
if (_8 && !_8.done && (_b = _7.return)) _b.call(_7);
|
|
102
|
-
}
|
|
103
|
-
finally { if (e_2) throw e_2.error; }
|
|
76
|
+
for (const characteristic of simulatorPlistData.Characteristics) {
|
|
77
|
+
simulatorCharacteristics.set(characteristic.UUID, characteristic);
|
|
104
78
|
}
|
|
105
79
|
if (simulatorMfiPlistData) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var characteristic = _10.value;
|
|
109
|
-
simulatorCharacteristics.set(characteristic.UUID, characteristic);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
113
|
-
finally {
|
|
114
|
-
try {
|
|
115
|
-
if (_10 && !_10.done && (_c = _9.return)) _c.call(_9);
|
|
116
|
-
}
|
|
117
|
-
finally { if (e_3) throw e_3.error; }
|
|
80
|
+
for (const characteristic of simulatorMfiPlistData.Characteristics) {
|
|
81
|
+
simulatorCharacteristics.set(characteristic.UUID, characteristic);
|
|
118
82
|
}
|
|
119
83
|
}
|
|
120
84
|
}
|
|
@@ -122,507 +86,320 @@ catch (error) {
|
|
|
122
86
|
console.log("Unexpected structure of the plist file!");
|
|
123
87
|
throw error;
|
|
124
88
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (definition.Identifier > 36) {
|
|
130
|
-
console.log("Detected a new category '".concat(definition.DefaultDescription, "' with id ").concat(definition.Identifier));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
135
|
-
finally {
|
|
136
|
-
try {
|
|
137
|
-
if (_12 && !_12.done && (_d = _11.return)) _d.call(_11);
|
|
89
|
+
// first step is to check if we are up to date on categories
|
|
90
|
+
for (const definition of Object.values(categories)) {
|
|
91
|
+
if (definition.Identifier > 36) {
|
|
92
|
+
console.log(`Detected a new category '${definition.DefaultDescription}' with id ${definition.Identifier}`);
|
|
138
93
|
}
|
|
139
|
-
finally { if (e_4) throw e_4.error; }
|
|
140
94
|
}
|
|
141
|
-
|
|
95
|
+
const characteristicOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "CharacteristicDefinitions.ts"));
|
|
142
96
|
characteristicOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
|
|
143
|
-
characteristicOutput.write(
|
|
97
|
+
characteristicOutput.write(`// V=${plistData.Version}\n`);
|
|
144
98
|
characteristicOutput.write("\n");
|
|
145
99
|
characteristicOutput.write("import { Access, Characteristic, Formats, Perms, Units } from \"../Characteristic\";\n\n");
|
|
146
100
|
/**
|
|
147
101
|
* Characteristics
|
|
148
102
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for (var _13 = tslib_1.__values(Object.entries(characteristics)), _14 = _13.next(); !_14.done; _14 = _13.next()) {
|
|
153
|
-
var _15 = tslib_1.__read(_14.value, 2), id = _15[0], definition = _15[1];
|
|
154
|
-
try {
|
|
155
|
-
if (generator_configuration_1.CharacteristicHidden.has(id)) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
// "Carbon dioxide Detected" -> "Carbon Dioxide Detected"
|
|
159
|
-
var name = ((_x = generator_configuration_1.CharacteristicNameOverrides.get(id)) !== null && _x !== void 0 ? _x : definition.DefaultDescription).split(" ").map(function (entry) { return entry[0].toUpperCase() + entry.slice(1); }).join(" ");
|
|
160
|
-
var deprecatedName = generator_configuration_1.CharacteristicDeprecatedNames.get(id);
|
|
161
|
-
// "Target Door State" -> "TargetDoorState", "PM2.5" -> "PM2_5"
|
|
162
|
-
var className = name.replace(/[\s-]/g, "").replace(/[.]/g, "_");
|
|
163
|
-
var deprecatedClassName = deprecatedName === null || deprecatedName === void 0 ? void 0 : deprecatedName.replace(/[\s-]/g, "").replace(/[.]/g, "_");
|
|
164
|
-
var longUUID = (0, uuid_1.toLongForm)(definition.ShortUUID);
|
|
165
|
-
var simulatorCharacteristic = simulatorCharacteristics.get(longUUID);
|
|
166
|
-
var validValues = ((_y = simulatorCharacteristic === null || simulatorCharacteristic === void 0 ? void 0 : simulatorCharacteristic.Constraints) === null || _y === void 0 ? void 0 : _y.ValidValues) || {};
|
|
167
|
-
var validValuesOverride = generator_configuration_1.CharacteristicValidValuesOverride.get(id);
|
|
168
|
-
if (validValuesOverride) {
|
|
169
|
-
try {
|
|
170
|
-
for (var _16 = (e_6 = void 0, tslib_1.__values(Object.entries(validValuesOverride))), _17 = _16.next(); !_17.done; _17 = _16.next()) {
|
|
171
|
-
var _18 = tslib_1.__read(_17.value, 2), key = _18[0], value = _18[1];
|
|
172
|
-
validValues[key] = value;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
176
|
-
finally {
|
|
177
|
-
try {
|
|
178
|
-
if (_17 && !_17.done && (_f = _16.return)) _f.call(_16);
|
|
179
|
-
}
|
|
180
|
-
finally { if (e_6) throw e_6.error; }
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
for (var _19 = (e_7 = void 0, tslib_1.__values(Object.entries(validValues))), _20 = _19.next(); !_20.done; _20 = _19.next()) {
|
|
185
|
-
var _21 = tslib_1.__read(_20.value, 2), value = _21[0], name_1 = _21[1];
|
|
186
|
-
var constName = name_1.toUpperCase().replace(/[^\w]+/g, "_");
|
|
187
|
-
if (/^[1-9]/.test(constName)) {
|
|
188
|
-
constName = "_" + constName; // variables can't start with a number
|
|
189
|
-
}
|
|
190
|
-
validValues[value] = constName;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
194
|
-
finally {
|
|
195
|
-
try {
|
|
196
|
-
if (_20 && !_20.done && (_g = _19.return)) _g.call(_19);
|
|
197
|
-
}
|
|
198
|
-
finally { if (e_7) throw e_7.error; }
|
|
199
|
-
}
|
|
200
|
-
var validBits = (_z = simulatorCharacteristic === null || simulatorCharacteristic === void 0 ? void 0 : simulatorCharacteristic.Constraints) === null || _z === void 0 ? void 0 : _z.ValidBits;
|
|
201
|
-
var validBitMasks = undefined;
|
|
202
|
-
if (validBits) {
|
|
203
|
-
validBitMasks = {};
|
|
204
|
-
try {
|
|
205
|
-
for (var _22 = (e_8 = void 0, tslib_1.__values(Object.entries(validBits))), _23 = _22.next(); !_23.done; _23 = _22.next()) {
|
|
206
|
-
var _24 = tslib_1.__read(_23.value, 2), value = _24[0], name_2 = _24[1];
|
|
207
|
-
var constName = name_2.toUpperCase().replace(/[^\w]+/g, "_");
|
|
208
|
-
if (/^[1-9]/.test(constName)) {
|
|
209
|
-
constName = "_" + constName; // variables can't start with a number
|
|
210
|
-
}
|
|
211
|
-
validBitMasks["" + (1 << parseInt(value, 10))] = constName + "_BIT_MASK";
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
215
|
-
finally {
|
|
216
|
-
try {
|
|
217
|
-
if (_23 && !_23.done && (_h = _22.return)) _h.call(_22);
|
|
218
|
-
}
|
|
219
|
-
finally { if (e_8) throw e_8.error; }
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
var generatedCharacteristic = {
|
|
223
|
-
id: id,
|
|
224
|
-
UUID: longUUID,
|
|
225
|
-
name: name,
|
|
226
|
-
className: className,
|
|
227
|
-
deprecatedClassName: deprecatedClassName,
|
|
228
|
-
since: generator_configuration_1.CharacteristicSinceInformation.get(id),
|
|
229
|
-
format: definition.Format,
|
|
230
|
-
units: definition.Units,
|
|
231
|
-
properties: definition.Properties,
|
|
232
|
-
minValue: definition.MinValue,
|
|
233
|
-
maxValue: definition.MaxValue,
|
|
234
|
-
stepValue: definition.StepValue,
|
|
235
|
-
maxLength: definition.MaxLength,
|
|
236
|
-
validValues: validValues,
|
|
237
|
-
validBitMasks: validBitMasks,
|
|
238
|
-
classAdditions: generator_configuration_1.CharacteristicClassAdditions.get(id),
|
|
239
|
-
};
|
|
240
|
-
// call any handler which wants to manually override properties of the generated characteristic
|
|
241
|
-
(_0 = generator_configuration_1.CharacteristicOverriding.get(id)) === null || _0 === void 0 ? void 0 : _0(generatedCharacteristic);
|
|
242
|
-
generatedCharacteristics[id] = generatedCharacteristic;
|
|
243
|
-
writtenCharacteristicEntries[className] = generatedCharacteristic;
|
|
244
|
-
if (deprecatedClassName) {
|
|
245
|
-
writtenCharacteristicEntries[deprecatedClassName] = generatedCharacteristic;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
throw new Error("Error thrown generating characteristic '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
254
|
-
finally {
|
|
103
|
+
const generatedCharacteristics = {}; // indexed by id
|
|
104
|
+
const writtenCharacteristicEntries = {}; // indexed by class name
|
|
105
|
+
for (const [id, definition] of Object.entries(characteristics)) {
|
|
255
106
|
try {
|
|
256
|
-
if (
|
|
107
|
+
if (generator_configuration_1.CharacteristicHidden.has(id)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
// "Carbon dioxide Detected" -> "Carbon Dioxide Detected"
|
|
111
|
+
const name = (generator_configuration_1.CharacteristicNameOverrides.get(id)
|
|
112
|
+
?? definition.DefaultDescription).split(" ").map(entry => entry[0].toUpperCase() + entry.slice(1)).join(" ");
|
|
113
|
+
const deprecatedName = generator_configuration_1.CharacteristicDeprecatedNames.get(id);
|
|
114
|
+
// "Target Door State" -> "TargetDoorState", "PM2.5" -> "PM2_5"
|
|
115
|
+
const className = name.replace(/[\s-]/g, "").replace(/[.]/g, "_");
|
|
116
|
+
const deprecatedClassName = deprecatedName?.replace(/[\s-]/g, "").replace(/[.]/g, "_");
|
|
117
|
+
const longUUID = (0, uuid_1.toLongForm)(definition.ShortUUID);
|
|
118
|
+
const simulatorCharacteristic = simulatorCharacteristics.get(longUUID);
|
|
119
|
+
const validValues = simulatorCharacteristic?.Constraints?.ValidValues || {};
|
|
120
|
+
const validValuesOverride = generator_configuration_1.CharacteristicValidValuesOverride.get(id);
|
|
121
|
+
if (validValuesOverride) {
|
|
122
|
+
for (const [key, value] of Object.entries(validValuesOverride)) {
|
|
123
|
+
validValues[key] = value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const [value, name] of Object.entries(validValues)) {
|
|
127
|
+
let constName = name.toUpperCase().replace(/[^\w]+/g, "_");
|
|
128
|
+
if (/^[1-9]/.test(constName)) {
|
|
129
|
+
constName = "_" + constName; // variables can't start with a number
|
|
130
|
+
}
|
|
131
|
+
validValues[value] = constName;
|
|
132
|
+
}
|
|
133
|
+
const validBits = simulatorCharacteristic?.Constraints?.ValidBits;
|
|
134
|
+
let validBitMasks = undefined;
|
|
135
|
+
if (validBits) {
|
|
136
|
+
validBitMasks = {};
|
|
137
|
+
for (const [value, name] of Object.entries(validBits)) {
|
|
138
|
+
let constName = name.toUpperCase().replace(/[^\w]+/g, "_");
|
|
139
|
+
if (/^[1-9]/.test(constName)) {
|
|
140
|
+
constName = "_" + constName; // variables can't start with a number
|
|
141
|
+
}
|
|
142
|
+
validBitMasks["" + (1 << parseInt(value, 10))] = constName + "_BIT_MASK";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const generatedCharacteristic = {
|
|
146
|
+
id: id,
|
|
147
|
+
UUID: longUUID,
|
|
148
|
+
name: name,
|
|
149
|
+
className: className,
|
|
150
|
+
deprecatedClassName: deprecatedClassName,
|
|
151
|
+
since: generator_configuration_1.CharacteristicSinceInformation.get(id),
|
|
152
|
+
format: definition.Format,
|
|
153
|
+
units: definition.Units,
|
|
154
|
+
properties: definition.Properties,
|
|
155
|
+
minValue: definition.MinValue,
|
|
156
|
+
maxValue: definition.MaxValue,
|
|
157
|
+
stepValue: definition.StepValue,
|
|
158
|
+
maxLength: definition.MaxLength,
|
|
159
|
+
validValues: validValues,
|
|
160
|
+
validBitMasks: validBitMasks,
|
|
161
|
+
classAdditions: generator_configuration_1.CharacteristicClassAdditions.get(id),
|
|
162
|
+
};
|
|
163
|
+
// call any handler which wants to manually override properties of the generated characteristic
|
|
164
|
+
generator_configuration_1.CharacteristicOverriding.get(id)?.(generatedCharacteristic);
|
|
165
|
+
generatedCharacteristics[id] = generatedCharacteristic;
|
|
166
|
+
writtenCharacteristicEntries[className] = generatedCharacteristic;
|
|
167
|
+
if (deprecatedClassName) {
|
|
168
|
+
writtenCharacteristicEntries[deprecatedClassName] = generatedCharacteristic;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
throw new Error("Error thrown generating characteristic '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
|
|
257
173
|
}
|
|
258
|
-
finally { if (e_5) throw e_5.error; }
|
|
259
174
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
writtenCharacteristicEntries[generated.
|
|
265
|
-
if (generated.deprecatedClassName) {
|
|
266
|
-
writtenCharacteristicEntries[generated.deprecatedClassName] = generated;
|
|
267
|
-
}
|
|
175
|
+
for (const [id, generated] of generator_configuration_1.CharacteristicManualAdditions) {
|
|
176
|
+
generatedCharacteristics[id] = generated;
|
|
177
|
+
writtenCharacteristicEntries[generated.className] = generated;
|
|
178
|
+
if (generated.deprecatedClassName) {
|
|
179
|
+
writtenCharacteristicEntries[generated.deprecatedClassName] = generated;
|
|
268
180
|
}
|
|
269
181
|
}
|
|
270
|
-
|
|
271
|
-
|
|
182
|
+
for (const generated of Object.values(generatedCharacteristics)
|
|
183
|
+
.sort((a, b) => a.className.localeCompare(b.className))) {
|
|
272
184
|
try {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
var classAdditions = generated.classAdditions;
|
|
294
|
-
if (classAdditions) {
|
|
295
|
-
characteristicOutput.write(classAdditions.map(function (line) { return " " + line + "\n"; }).join("") + "\n");
|
|
296
|
-
}
|
|
297
|
-
var validValuesEntries = Object.entries((_1 = generated.validValues) !== null && _1 !== void 0 ? _1 : {});
|
|
298
|
-
if (validValuesEntries.length) {
|
|
299
|
-
try {
|
|
300
|
-
for (var validValuesEntries_1 = (e_11 = void 0, tslib_1.__values(validValuesEntries)), validValuesEntries_1_1 = validValuesEntries_1.next(); !validValuesEntries_1_1.done; validValuesEntries_1_1 = validValuesEntries_1.next()) {
|
|
301
|
-
var _28 = tslib_1.__read(validValuesEntries_1_1.value, 2), value = _28[0], name = _28[1];
|
|
302
|
-
if (!name) {
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
characteristicOutput.write(" public static readonly ".concat(name, " = ").concat(value, ";\n"));
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
309
|
-
finally {
|
|
310
|
-
try {
|
|
311
|
-
if (validValuesEntries_1_1 && !validValuesEntries_1_1.done && (_l = validValuesEntries_1.return)) _l.call(validValuesEntries_1);
|
|
312
|
-
}
|
|
313
|
-
finally { if (e_11) throw e_11.error; }
|
|
185
|
+
characteristicOutput.write("/**\n");
|
|
186
|
+
characteristicOutput.write(" * Characteristic \"" + generated.name + "\"\n");
|
|
187
|
+
if (generated.since) {
|
|
188
|
+
characteristicOutput.write(" * @since iOS " + generated.since + "\n");
|
|
189
|
+
}
|
|
190
|
+
if (generated.deprecatedNotice) {
|
|
191
|
+
characteristicOutput.write(" * @deprecated " + generated.deprecatedNotice + "\n");
|
|
192
|
+
}
|
|
193
|
+
characteristicOutput.write(" */\n");
|
|
194
|
+
characteristicOutput.write("export class " + generated.className + " extends Characteristic {\n\n");
|
|
195
|
+
characteristicOutput.write(" public static readonly UUID: string = \"" + generated.UUID + "\";\n\n");
|
|
196
|
+
const classAdditions = generated.classAdditions;
|
|
197
|
+
if (classAdditions) {
|
|
198
|
+
characteristicOutput.write(classAdditions.map(line => " " + line + "\n").join("") + "\n");
|
|
199
|
+
}
|
|
200
|
+
const validValuesEntries = Object.entries(generated.validValues ?? {});
|
|
201
|
+
if (validValuesEntries.length) {
|
|
202
|
+
for (const [value, name] of validValuesEntries) {
|
|
203
|
+
if (!name) {
|
|
204
|
+
continue;
|
|
314
205
|
}
|
|
315
|
-
characteristicOutput.write(
|
|
316
|
-
}
|
|
317
|
-
if (generated.validBitMasks) {
|
|
318
|
-
try {
|
|
319
|
-
for (var _29 = (e_12 = void 0, tslib_1.__values(Object.entries(generated.validBitMasks))), _30 = _29.next(); !_30.done; _30 = _29.next()) {
|
|
320
|
-
var _31 = tslib_1.__read(_30.value, 2), value = _31[0], name = _31[1];
|
|
321
|
-
characteristicOutput.write(" public static readonly ".concat(name, " = ").concat(value, ";\n"));
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
325
|
-
finally {
|
|
326
|
-
try {
|
|
327
|
-
if (_30 && !_30.done && (_m = _29.return)) _m.call(_29);
|
|
328
|
-
}
|
|
329
|
-
finally { if (e_12) throw e_12.error; }
|
|
330
|
-
}
|
|
331
|
-
characteristicOutput.write("\n");
|
|
332
|
-
}
|
|
333
|
-
characteristicOutput.write(" constructor() {\n");
|
|
334
|
-
characteristicOutput.write(" super(\"" + generated.name + "\", " + generated.className + ".UUID, {\n");
|
|
335
|
-
characteristicOutput.write(" format: Formats." + characteristicFormat(generated.format) + ",\n");
|
|
336
|
-
characteristicOutput.write(" perms: [" + generatePermsString(generated.id, generated.properties) + "],\n");
|
|
337
|
-
if (generated.units && !undefinedUnits.includes(generated.units)) {
|
|
338
|
-
characteristicOutput.write(" unit: Units." + characteristicUnit(generated.units) + ",\n");
|
|
339
|
-
}
|
|
340
|
-
if (generated.minValue != null) {
|
|
341
|
-
characteristicOutput.write(" minValue: " + generated.minValue + ",\n");
|
|
342
|
-
}
|
|
343
|
-
if (generated.maxValue != null) {
|
|
344
|
-
characteristicOutput.write(" maxValue: " + generated.maxValue + ",\n");
|
|
206
|
+
characteristicOutput.write(` public static readonly ${name} = ${value};\n`);
|
|
345
207
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
characteristicOutput.write(
|
|
351
|
-
}
|
|
352
|
-
if (validValuesEntries.length) {
|
|
353
|
-
characteristicOutput.write(" validValues: [" + Object.keys(generated.validValues).join(", ") + "],\n");
|
|
354
|
-
}
|
|
355
|
-
if (generated.adminOnlyAccess) {
|
|
356
|
-
characteristicOutput.write(" adminOnlyAccess: ["
|
|
357
|
-
+ generated.adminOnlyAccess.map(function (value) { return "Access." + characteristicAccess(value); }).join(", ") + "],\n");
|
|
358
|
-
}
|
|
359
|
-
characteristicOutput.write(" });\n");
|
|
360
|
-
characteristicOutput.write(" this.value = this.getDefaultValue();\n");
|
|
361
|
-
characteristicOutput.write(" }\n");
|
|
362
|
-
characteristicOutput.write("}\n");
|
|
363
|
-
if (generated.deprecatedClassName) {
|
|
364
|
-
characteristicOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
365
|
-
characteristicOutput.write("Characteristic." + generated.deprecatedClassName + " = " + generated.className + ";\n");
|
|
366
|
-
}
|
|
367
|
-
if (generated.deprecatedNotice) {
|
|
368
|
-
characteristicOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
208
|
+
characteristicOutput.write("\n");
|
|
209
|
+
}
|
|
210
|
+
if (generated.validBitMasks) {
|
|
211
|
+
for (const [value, name] of Object.entries(generated.validBitMasks)) {
|
|
212
|
+
characteristicOutput.write(` public static readonly ${name} = ${value};\n`);
|
|
369
213
|
}
|
|
370
|
-
characteristicOutput.write("
|
|
214
|
+
characteristicOutput.write("\n");
|
|
215
|
+
}
|
|
216
|
+
characteristicOutput.write(" constructor() {\n");
|
|
217
|
+
characteristicOutput.write(" super(\"" + generated.name + "\", " + generated.className + ".UUID, {\n");
|
|
218
|
+
characteristicOutput.write(" format: Formats." + characteristicFormat(generated.format) + ",\n");
|
|
219
|
+
characteristicOutput.write(" perms: [" + generatePermsString(generated.id, generated.properties) + "],\n");
|
|
220
|
+
if (generated.units && !undefinedUnits.includes(generated.units)) {
|
|
221
|
+
characteristicOutput.write(" unit: Units." + characteristicUnit(generated.units) + ",\n");
|
|
222
|
+
}
|
|
223
|
+
if (generated.minValue != null) {
|
|
224
|
+
characteristicOutput.write(" minValue: " + generated.minValue + ",\n");
|
|
225
|
+
}
|
|
226
|
+
if (generated.maxValue != null) {
|
|
227
|
+
characteristicOutput.write(" maxValue: " + generated.maxValue + ",\n");
|
|
371
228
|
}
|
|
372
|
-
|
|
373
|
-
|
|
229
|
+
if (generated.stepValue != null) {
|
|
230
|
+
characteristicOutput.write(" minStep: " + generated.stepValue + ",\n");
|
|
374
231
|
}
|
|
232
|
+
if (generated.maxLength != null) {
|
|
233
|
+
characteristicOutput.write(" maxLen: " + generated.maxLength + ",\n");
|
|
234
|
+
}
|
|
235
|
+
if (validValuesEntries.length) {
|
|
236
|
+
characteristicOutput.write(" validValues: [" + Object.keys(generated.validValues).join(", ") + "],\n");
|
|
237
|
+
}
|
|
238
|
+
if (generated.adminOnlyAccess) {
|
|
239
|
+
characteristicOutput.write(" adminOnlyAccess: ["
|
|
240
|
+
+ generated.adminOnlyAccess.map(value => "Access." + characteristicAccess(value)).join(", ") + "],\n");
|
|
241
|
+
}
|
|
242
|
+
characteristicOutput.write(" });\n");
|
|
243
|
+
characteristicOutput.write(" this.value = this.getDefaultValue();\n");
|
|
244
|
+
characteristicOutput.write(" }\n");
|
|
245
|
+
characteristicOutput.write("}\n");
|
|
246
|
+
if (generated.deprecatedClassName) {
|
|
247
|
+
characteristicOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
248
|
+
characteristicOutput.write("Characteristic." + generated.deprecatedClassName + " = " + generated.className + ";\n");
|
|
249
|
+
}
|
|
250
|
+
if (generated.deprecatedNotice) {
|
|
251
|
+
characteristicOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
252
|
+
}
|
|
253
|
+
characteristicOutput.write("Characteristic." + generated.className + " = " + generated.className + ";\n\n");
|
|
375
254
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
finally {
|
|
379
|
-
try {
|
|
380
|
-
if (_27 && !_27.done && (_k = _26.return)) _k.call(_26);
|
|
255
|
+
catch (error) {
|
|
256
|
+
throw new Error("Error thrown writing characteristic '" + generated.id + "' (" + generated.className + "): " + error.message);
|
|
381
257
|
}
|
|
382
|
-
finally { if (e_10) throw e_10.error; }
|
|
383
258
|
}
|
|
384
259
|
characteristicOutput.end();
|
|
385
|
-
|
|
386
|
-
var _c = tslib_1.__read(_a, 1), a = _c[0];
|
|
387
|
-
var _d = tslib_1.__read(_b, 1), b = _d[0];
|
|
388
|
-
return a.localeCompare(b);
|
|
389
|
-
});
|
|
260
|
+
const characteristicProperties = Object.entries(writtenCharacteristicEntries).sort(([a], [b]) => a.localeCompare(b));
|
|
390
261
|
rewriteProperties("Characteristic", characteristicProperties);
|
|
391
262
|
writeCharacteristicTestFile();
|
|
392
263
|
/**
|
|
393
264
|
* Services
|
|
394
265
|
*/
|
|
395
|
-
|
|
266
|
+
const serviceOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "ServiceDefinitions.ts"));
|
|
396
267
|
serviceOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
|
|
397
|
-
serviceOutput.write(
|
|
268
|
+
serviceOutput.write(`// V=${plistData.Version}\n`);
|
|
398
269
|
serviceOutput.write("\n");
|
|
399
270
|
serviceOutput.write("import { Characteristic } from \"../Characteristic\";\n");
|
|
400
271
|
serviceOutput.write("import { Service } from \"../Service\";\n\n");
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
var entry = _36.value;
|
|
421
|
-
var index = requiredCharacteristics.indexOf(entry);
|
|
422
|
-
if (index !== -1) {
|
|
423
|
-
requiredCharacteristics.splice(index, 1);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
428
|
-
finally {
|
|
429
|
-
try {
|
|
430
|
-
if (_36 && !_36.done && (_p = _35.return)) _p.call(_35);
|
|
431
|
-
}
|
|
432
|
-
finally { if (e_14) throw e_14.error; }
|
|
272
|
+
const generatedServices = {}; // indexed by id
|
|
273
|
+
const writtenServiceEntries = {}; // indexed by class name
|
|
274
|
+
for (const [id, definition] of Object.entries(services)) {
|
|
275
|
+
try {
|
|
276
|
+
// "Carbon dioxide Sensor" -> "Carbon Dioxide Sensor"
|
|
277
|
+
const name = (generator_configuration_1.ServiceNameOverrides.get(id) ?? definition.DefaultDescription).split(" ").map(entry => entry[0].toUpperCase() + entry.slice(1)).join(" ");
|
|
278
|
+
const deprecatedName = generator_configuration_1.ServiceDeprecatedNames.get(id);
|
|
279
|
+
const className = name.replace(/[\s-]/g, "").replace(/[.]/g, "_");
|
|
280
|
+
const deprecatedClassName = deprecatedName?.replace(/[\s-]/g, "").replace(/[.]/g, "_");
|
|
281
|
+
const longUUID = (0, uuid_1.toLongForm)(definition.ShortUUID);
|
|
282
|
+
const requiredCharacteristics = definition.Characteristics.Required;
|
|
283
|
+
const optionalCharacteristics = definition.Characteristics.Optional;
|
|
284
|
+
const configurationOverride = generator_configuration_1.ServiceCharacteristicConfigurationOverrides.get(id);
|
|
285
|
+
if (configurationOverride) {
|
|
286
|
+
if (configurationOverride.removedRequired) {
|
|
287
|
+
for (const entry of configurationOverride.removedRequired) {
|
|
288
|
+
const index = requiredCharacteristics.indexOf(entry);
|
|
289
|
+
if (index !== -1) {
|
|
290
|
+
requiredCharacteristics.splice(index, 1);
|
|
433
291
|
}
|
|
434
292
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
optionalCharacteristics.splice(index, 1);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
446
|
-
finally {
|
|
447
|
-
try {
|
|
448
|
-
if (_38 && !_38.done && (_q = _37.return)) _q.call(_37);
|
|
449
|
-
}
|
|
450
|
-
finally { if (e_15) throw e_15.error; }
|
|
293
|
+
}
|
|
294
|
+
if (configurationOverride.removedOptional) {
|
|
295
|
+
for (const entry of configurationOverride.removedOptional) {
|
|
296
|
+
const index = optionalCharacteristics.indexOf(entry);
|
|
297
|
+
if (index !== -1) {
|
|
298
|
+
optionalCharacteristics.splice(index, 1);
|
|
451
299
|
}
|
|
452
300
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
requiredCharacteristics.push(entry);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
463
|
-
finally {
|
|
464
|
-
try {
|
|
465
|
-
if (_40 && !_40.done && (_r = _39.return)) _r.call(_39);
|
|
466
|
-
}
|
|
467
|
-
finally { if (e_16) throw e_16.error; }
|
|
301
|
+
}
|
|
302
|
+
if (configurationOverride.addedRequired) {
|
|
303
|
+
for (const entry of configurationOverride.addedRequired) {
|
|
304
|
+
if (!requiredCharacteristics.includes(entry)) {
|
|
305
|
+
requiredCharacteristics.push(entry);
|
|
468
306
|
}
|
|
469
307
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
optionalCharacteristics.push(entry);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
480
|
-
finally {
|
|
481
|
-
try {
|
|
482
|
-
if (_42 && !_42.done && (_s = _41.return)) _s.call(_41);
|
|
483
|
-
}
|
|
484
|
-
finally { if (e_17) throw e_17.error; }
|
|
308
|
+
}
|
|
309
|
+
if (configurationOverride.addedOptional) {
|
|
310
|
+
for (const entry of configurationOverride.addedOptional) {
|
|
311
|
+
if (!optionalCharacteristics.includes(entry)) {
|
|
312
|
+
optionalCharacteristics.push(entry);
|
|
485
313
|
}
|
|
486
314
|
}
|
|
487
315
|
}
|
|
488
|
-
var generatedService = {
|
|
489
|
-
id: id,
|
|
490
|
-
UUID: longUUID,
|
|
491
|
-
name: name,
|
|
492
|
-
className: className,
|
|
493
|
-
deprecatedClassName: deprecatedClassName,
|
|
494
|
-
since: generator_configuration_1.ServiceSinceInformation.get(id),
|
|
495
|
-
requiredCharacteristics: requiredCharacteristics,
|
|
496
|
-
optionalCharacteristics: optionalCharacteristics,
|
|
497
|
-
};
|
|
498
|
-
generatedServices[id] = generatedService;
|
|
499
|
-
writtenServiceEntries[className] = generatedService;
|
|
500
|
-
if (deprecatedClassName) {
|
|
501
|
-
writtenServiceEntries[deprecatedClassName] = generatedService;
|
|
502
|
-
}
|
|
503
316
|
}
|
|
504
|
-
|
|
505
|
-
|
|
317
|
+
const generatedService = {
|
|
318
|
+
id: id,
|
|
319
|
+
UUID: longUUID,
|
|
320
|
+
name: name,
|
|
321
|
+
className: className,
|
|
322
|
+
deprecatedClassName: deprecatedClassName,
|
|
323
|
+
since: generator_configuration_1.ServiceSinceInformation.get(id),
|
|
324
|
+
requiredCharacteristics: requiredCharacteristics,
|
|
325
|
+
optionalCharacteristics: optionalCharacteristics,
|
|
326
|
+
};
|
|
327
|
+
generatedServices[id] = generatedService;
|
|
328
|
+
writtenServiceEntries[className] = generatedService;
|
|
329
|
+
if (deprecatedClassName) {
|
|
330
|
+
writtenServiceEntries[deprecatedClassName] = generatedService;
|
|
506
331
|
}
|
|
507
332
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
finally {
|
|
511
|
-
try {
|
|
512
|
-
if (_33 && !_33.done && (_o = _32.return)) _o.call(_32);
|
|
333
|
+
catch (error) {
|
|
334
|
+
throw new Error("Error thrown generating service '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
|
|
513
335
|
}
|
|
514
|
-
finally { if (e_13) throw e_13.error; }
|
|
515
336
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
writtenServiceEntries[generated.
|
|
521
|
-
if (generated.deprecatedClassName) {
|
|
522
|
-
writtenServiceEntries[generated.deprecatedClassName] = generated;
|
|
523
|
-
}
|
|
337
|
+
for (const [id, generated] of generator_configuration_1.ServiceManualAdditions) {
|
|
338
|
+
generatedServices[id] = generated;
|
|
339
|
+
writtenServiceEntries[generated.className] = generated;
|
|
340
|
+
if (generated.deprecatedClassName) {
|
|
341
|
+
writtenServiceEntries[generated.deprecatedClassName] = generated;
|
|
524
342
|
}
|
|
525
343
|
}
|
|
526
|
-
|
|
527
|
-
|
|
344
|
+
for (const generated of Object.values(generatedServices)
|
|
345
|
+
.sort((a, b) => a.className.localeCompare(b.className))) {
|
|
528
346
|
try {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
347
|
+
serviceOutput.write("/**\n");
|
|
348
|
+
serviceOutput.write(" * Service \"" + generated.name + "\"\n");
|
|
349
|
+
if (generated.since) {
|
|
350
|
+
serviceOutput.write(" * @since iOS " + generated.since + "\n");
|
|
351
|
+
}
|
|
352
|
+
if (generated.deprecatedNotice) {
|
|
353
|
+
serviceOutput.write(" * @deprecated " + generated.deprecatedNotice + "\n");
|
|
354
|
+
}
|
|
355
|
+
serviceOutput.write(" */\n");
|
|
356
|
+
serviceOutput.write("export class " + generated.className + " extends Service {\n\n");
|
|
357
|
+
serviceOutput.write(" public static readonly UUID: string = \"" + generated.UUID + "\";\n\n");
|
|
358
|
+
serviceOutput.write(" constructor(displayName?: string, subtype?: string) {\n");
|
|
359
|
+
serviceOutput.write(" super(displayName, " + generated.className + ".UUID, subtype);\n\n");
|
|
360
|
+
serviceOutput.write(" // Required Characteristics\n");
|
|
361
|
+
for (const required of generated.requiredCharacteristics) {
|
|
362
|
+
const characteristic = generatedCharacteristics[required];
|
|
363
|
+
if (!characteristic) {
|
|
364
|
+
console.warn("Could not find required characteristic " + required + " for " + generated.className);
|
|
365
|
+
continue;
|
|
545
366
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
serviceOutput.write(" super(displayName, " + generated.className + ".UUID, subtype);\n\n");
|
|
551
|
-
serviceOutput.write(" // Required Characteristics\n");
|
|
552
|
-
try {
|
|
553
|
-
for (var _46 = (e_20 = void 0, tslib_1.__values(generated.requiredCharacteristics)), _47 = _46.next(); !_47.done; _47 = _46.next()) {
|
|
554
|
-
var required = _47.value;
|
|
555
|
-
var characteristic = generatedCharacteristics[required];
|
|
556
|
-
if (!characteristic) {
|
|
557
|
-
console.warn("Could not find required characteristic " + required + " for " + generated.className);
|
|
558
|
-
continue;
|
|
559
|
-
}
|
|
560
|
-
if (required === "name") {
|
|
561
|
-
serviceOutput.write(" if (!this.testCharacteristic(Characteristic.Name)) { // workaround for Name characteristic collision in constructor\n");
|
|
562
|
-
serviceOutput.write(" this.addCharacteristic(Characteristic.Name).updateValue(\"Unnamed Service\");\n");
|
|
563
|
-
serviceOutput.write(" }\n");
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
serviceOutput.write(" this.addCharacteristic(Characteristic." + characteristic.className + ");\n");
|
|
567
|
-
}
|
|
568
|
-
}
|
|
367
|
+
if (required === "name") {
|
|
368
|
+
serviceOutput.write(" if (!this.testCharacteristic(Characteristic.Name)) { // workaround for Name characteristic collision in constructor\n");
|
|
369
|
+
serviceOutput.write(" this.addCharacteristic(Characteristic.Name).updateValue(\"Unnamed Service\");\n");
|
|
370
|
+
serviceOutput.write(" }\n");
|
|
569
371
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
try {
|
|
573
|
-
if (_47 && !_47.done && (_v = _46.return)) _v.call(_46);
|
|
574
|
-
}
|
|
575
|
-
finally { if (e_20) throw e_20.error; }
|
|
372
|
+
else {
|
|
373
|
+
serviceOutput.write(" this.addCharacteristic(Characteristic." + characteristic.className + ");\n");
|
|
576
374
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
continue;
|
|
586
|
-
}
|
|
587
|
-
serviceOutput.write(" this.addOptionalCharacteristic(Characteristic." + characteristic.className + ");\n");
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
591
|
-
finally {
|
|
592
|
-
try {
|
|
593
|
-
if (_49 && !_49.done && (_w = _48.return)) _w.call(_48);
|
|
594
|
-
}
|
|
595
|
-
finally { if (e_21) throw e_21.error; }
|
|
375
|
+
}
|
|
376
|
+
if (generated.optionalCharacteristics?.length) {
|
|
377
|
+
serviceOutput.write("\n // Optional Characteristics\n");
|
|
378
|
+
for (const optional of generated.optionalCharacteristics) {
|
|
379
|
+
const characteristic = generatedCharacteristics[optional];
|
|
380
|
+
if (!characteristic) {
|
|
381
|
+
console.warn("Could not find optional characteristic " + optional + " for " + generated.className);
|
|
382
|
+
continue;
|
|
596
383
|
}
|
|
384
|
+
serviceOutput.write(" this.addOptionalCharacteristic(Characteristic." + characteristic.className + ");\n");
|
|
597
385
|
}
|
|
598
|
-
serviceOutput.write(" }\n}\n");
|
|
599
|
-
if (generated.deprecatedClassName) {
|
|
600
|
-
serviceOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
601
|
-
serviceOutput.write("Service." + generated.deprecatedClassName + " = " + generated.className + ";\n");
|
|
602
|
-
}
|
|
603
|
-
if (generated.deprecatedNotice) {
|
|
604
|
-
serviceOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
605
|
-
}
|
|
606
|
-
serviceOutput.write("Service." + generated.className + " = " + generated.className + ";\n\n");
|
|
607
386
|
}
|
|
608
|
-
|
|
609
|
-
|
|
387
|
+
serviceOutput.write(" }\n}\n");
|
|
388
|
+
if (generated.deprecatedClassName) {
|
|
389
|
+
serviceOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
390
|
+
serviceOutput.write("Service." + generated.deprecatedClassName + " = " + generated.className + ";\n");
|
|
391
|
+
}
|
|
392
|
+
if (generated.deprecatedNotice) {
|
|
393
|
+
serviceOutput.write("// noinspection JSDeprecatedSymbols\n");
|
|
610
394
|
}
|
|
395
|
+
serviceOutput.write("Service." + generated.className + " = " + generated.className + ";\n\n");
|
|
611
396
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
finally {
|
|
615
|
-
try {
|
|
616
|
-
if (_45 && !_45.done && (_u = _44.return)) _u.call(_44);
|
|
397
|
+
catch (error) {
|
|
398
|
+
throw new Error("Error thrown writing service '" + generated.id + "' (" + generated.className + "): " + error.message);
|
|
617
399
|
}
|
|
618
|
-
finally { if (e_19) throw e_19.error; }
|
|
619
400
|
}
|
|
620
401
|
serviceOutput.end();
|
|
621
|
-
|
|
622
|
-
var _c = tslib_1.__read(_a, 1), a = _c[0];
|
|
623
|
-
var _d = tslib_1.__read(_b, 1), b = _d[0];
|
|
624
|
-
return a.localeCompare(b);
|
|
625
|
-
});
|
|
402
|
+
const serviceProperties = Object.entries(writtenServiceEntries).sort(([a], [b]) => a.localeCompare(b));
|
|
626
403
|
rewriteProperties("Service", serviceProperties);
|
|
627
404
|
writeServicesTestFile();
|
|
628
405
|
// ------------------------ utils ------------------------
|
|
@@ -633,63 +410,30 @@ function checkDefined(input) {
|
|
|
633
410
|
return input;
|
|
634
411
|
}
|
|
635
412
|
function characteristicFormat(format) {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
|
|
641
|
-
if (value === format) {
|
|
642
|
-
return key;
|
|
643
|
-
}
|
|
413
|
+
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
414
|
+
for (const [key, value] of Object.entries(Characteristic_1.Formats)) {
|
|
415
|
+
if (value === format) {
|
|
416
|
+
return key;
|
|
644
417
|
}
|
|
645
418
|
}
|
|
646
|
-
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
647
|
-
finally {
|
|
648
|
-
try {
|
|
649
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
650
|
-
}
|
|
651
|
-
finally { if (e_22) throw e_22.error; }
|
|
652
|
-
}
|
|
653
419
|
throw new Error("Unknown characteristic format '" + format + "'");
|
|
654
420
|
}
|
|
655
421
|
function characteristicUnit(unit) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
|
|
661
|
-
if (value === unit) {
|
|
662
|
-
return key;
|
|
663
|
-
}
|
|
422
|
+
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
423
|
+
for (const [key, value] of Object.entries(Characteristic_1.Units)) {
|
|
424
|
+
if (value === unit) {
|
|
425
|
+
return key;
|
|
664
426
|
}
|
|
665
427
|
}
|
|
666
|
-
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
667
|
-
finally {
|
|
668
|
-
try {
|
|
669
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
670
|
-
}
|
|
671
|
-
finally { if (e_23) throw e_23.error; }
|
|
672
|
-
}
|
|
673
428
|
throw new Error("Unknown characteristic format '" + unit + "'");
|
|
674
429
|
}
|
|
675
430
|
function characteristicAccess(access) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
|
|
681
|
-
if (value === access) {
|
|
682
|
-
return key;
|
|
683
|
-
}
|
|
431
|
+
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
432
|
+
for (const [key, value] of Object.entries(Characteristic_1.Access)) {
|
|
433
|
+
if (value === access) {
|
|
434
|
+
return key;
|
|
684
435
|
}
|
|
685
436
|
}
|
|
686
|
-
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
687
|
-
finally {
|
|
688
|
-
try {
|
|
689
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
690
|
-
}
|
|
691
|
-
finally { if (e_24) throw e_24.error; }
|
|
692
|
-
}
|
|
693
437
|
throw new Error("Unknown access for '" + access + "'");
|
|
694
438
|
}
|
|
695
439
|
function characteristicPerm(id) {
|
|
@@ -717,54 +461,43 @@ function characteristicPerm(id) {
|
|
|
717
461
|
}
|
|
718
462
|
}
|
|
719
463
|
function generatePermsString(id, propertiesBitMap) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
if (name === "ADDITIONAL_AUTHORIZATION") {
|
|
726
|
-
// aa set by homed just signals that aa may be supported. Setting up aa will always require a custom made app though
|
|
727
|
-
continue;
|
|
728
|
-
}
|
|
729
|
-
if ((propertiesBitMap | bitMap) === propertiesBitMap) { // if it stays the same the bit is set
|
|
730
|
-
perms.push("Perms." + name);
|
|
731
|
-
}
|
|
464
|
+
const perms = [];
|
|
465
|
+
for (const [bitMap, name] of properties) {
|
|
466
|
+
if (name === "ADDITIONAL_AUTHORIZATION") {
|
|
467
|
+
// aa set by homed just signals that aa may be supported. Setting up aa will always require a custom made app though
|
|
468
|
+
continue;
|
|
732
469
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
finally {
|
|
736
|
-
try {
|
|
737
|
-
if (properties_1_1 && !properties_1_1.done && (_a = properties_1.return)) _a.call(properties_1);
|
|
470
|
+
if ((propertiesBitMap | bitMap) === propertiesBitMap) { // if it stays the same the bit is set
|
|
471
|
+
perms.push("Perms." + name);
|
|
738
472
|
}
|
|
739
|
-
finally { if (e_25) throw e_25.error; }
|
|
740
473
|
}
|
|
741
|
-
|
|
474
|
+
const result = perms.join(", ");
|
|
742
475
|
(0, assert_1.default)(!!result, "perms string cannot be empty (" + propertiesBitMap + ")");
|
|
743
476
|
return result;
|
|
744
477
|
}
|
|
745
478
|
function checkWrittenVersion(filePath, parsingVersion) {
|
|
746
479
|
filePath = path_1.default.resolve(__dirname, filePath);
|
|
747
|
-
|
|
748
|
-
|
|
480
|
+
const content = fs_1.default.readFileSync(filePath, { encoding: "utf8" }).split("\n", 3);
|
|
481
|
+
const v = content[1];
|
|
749
482
|
if (!v.startsWith("// V=")) {
|
|
750
483
|
throw new Error("Could not detect definition version for '" + filePath + "'");
|
|
751
484
|
}
|
|
752
|
-
|
|
485
|
+
const version = parseInt(v.replace("// V=", ""), 10);
|
|
753
486
|
return parsingVersion >= version;
|
|
754
487
|
}
|
|
755
488
|
function rewriteProperties(className, properties) {
|
|
756
|
-
|
|
489
|
+
const filePath = path_1.default.resolve(__dirname, "../" + className + ".ts");
|
|
757
490
|
if (!fs_1.default.existsSync(filePath)) {
|
|
758
491
|
throw new Error("File '" + filePath + "' does not exist!");
|
|
759
492
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
493
|
+
const file = fs_1.default.readFileSync(filePath, { encoding: "utf8" });
|
|
494
|
+
const lines = file.split("\n");
|
|
495
|
+
let i = 0;
|
|
496
|
+
let importStart = -1;
|
|
497
|
+
let importEnd = -1;
|
|
498
|
+
let foundImport = false;
|
|
766
499
|
for (; i < lines.length; i++) {
|
|
767
|
-
|
|
500
|
+
const line = lines[i];
|
|
768
501
|
if (line === "import type {") {
|
|
769
502
|
importStart = i; // save last import start;
|
|
770
503
|
}
|
|
@@ -777,8 +510,8 @@ function rewriteProperties(className, properties) {
|
|
|
777
510
|
if (!foundImport) {
|
|
778
511
|
throw new Error("Could not find import section!");
|
|
779
512
|
}
|
|
780
|
-
|
|
781
|
-
|
|
513
|
+
let startIndex = -1;
|
|
514
|
+
let stopIndex = -1;
|
|
782
515
|
for (; i < lines.length; i++) {
|
|
783
516
|
if (lines[i] === " // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-") {
|
|
784
517
|
startIndex = i;
|
|
@@ -797,25 +530,18 @@ function rewriteProperties(className, properties) {
|
|
|
797
530
|
if (stopIndex === -1) {
|
|
798
531
|
throw new Error("Could not find stop pattern in file!");
|
|
799
532
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
.filter(
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
.map(function (_a) {
|
|
807
|
-
var _b = tslib_1.__read(_a, 1), key = _b[0];
|
|
808
|
-
return " " + key + ",";
|
|
809
|
-
});
|
|
810
|
-
lines.splice.apply(lines, tslib_1.__spreadArray([importStart + 1, importSize], tslib_1.__read(newImports), false)); // remove current imports
|
|
811
|
-
var importDelta = newImports.length - importSize;
|
|
533
|
+
const importSize = importEnd - importStart - 1;
|
|
534
|
+
const newImports = properties
|
|
535
|
+
.filter(([key, value]) => key === value.className)
|
|
536
|
+
.map(([key]) => " " + key + ",");
|
|
537
|
+
lines.splice(importStart + 1, importSize, ...newImports); // remove current imports
|
|
538
|
+
const importDelta = newImports.length - importSize;
|
|
812
539
|
startIndex += importDelta;
|
|
813
540
|
stopIndex += importDelta;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
var deprecatedNotice = value.deprecatedNotice;
|
|
541
|
+
const amount = stopIndex - startIndex - 1;
|
|
542
|
+
const newContentLines = properties.map(([key, value]) => {
|
|
543
|
+
let line = "";
|
|
544
|
+
let deprecatedNotice = value.deprecatedNotice;
|
|
819
545
|
if (key !== value.className) {
|
|
820
546
|
deprecatedNotice = "Please use {@link " + className + "." + value.className + "}." // prepend deprecated notice
|
|
821
547
|
+ (deprecatedNotice ? " " + deprecatedNotice : "");
|
|
@@ -829,88 +555,66 @@ function rewriteProperties(className, properties) {
|
|
|
829
555
|
line += " public static " + key + ": typeof " + value.className + ";";
|
|
830
556
|
return line;
|
|
831
557
|
});
|
|
832
|
-
lines.splice
|
|
833
|
-
|
|
558
|
+
lines.splice(startIndex + 1, amount, ...newContentLines); // insert new lines
|
|
559
|
+
const resultContent = lines.join("\n");
|
|
834
560
|
fs_1.default.writeFileSync(filePath, resultContent, { encoding: "utf8" });
|
|
835
561
|
}
|
|
836
562
|
function writeCharacteristicTestFile() {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
var testOutput = fs_1.default.createWriteStream(path_1.default.resolve(__dirname, "./CharacteristicDefinitions.spec.ts"), { encoding: "utf8" });
|
|
563
|
+
const characteristics = Object.values(generatedCharacteristics).sort((a, b) => a.className.localeCompare(b.className));
|
|
564
|
+
const testOutput = fs_1.default.createWriteStream(path_1.default.resolve(__dirname, "./CharacteristicDefinitions.spec.ts"), { encoding: "utf8" });
|
|
840
565
|
testOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
|
|
841
566
|
testOutput.write("import \"./\";\n\n");
|
|
842
567
|
testOutput.write("import { Characteristic } from \"../Characteristic\";\n\n");
|
|
843
568
|
testOutput.write("describe(\"CharacteristicDefinitions\", () => {");
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
testOutput.write("
|
|
852
|
-
|
|
853
|
-
testOutput.write(" // noinspection JSDeprecatedSymbols\n");
|
|
854
|
-
testOutput.write(" new Characteristic." + generated.deprecatedClassName + "();\n");
|
|
855
|
-
}
|
|
856
|
-
testOutput.write(" });\n");
|
|
857
|
-
testOutput.write(" });\n");
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
catch (e_26_1) { e_26 = { error: e_26_1 }; }
|
|
861
|
-
finally {
|
|
862
|
-
try {
|
|
863
|
-
if (characteristics_1_1 && !characteristics_1_1.done && (_a = characteristics_1.return)) _a.call(characteristics_1);
|
|
569
|
+
for (const generated of characteristics) {
|
|
570
|
+
testOutput.write("\n");
|
|
571
|
+
testOutput.write(" describe(\"" + generated.className + "\", () => {\n");
|
|
572
|
+
// first test is just calling the constructor
|
|
573
|
+
testOutput.write(" it(\"should be able to construct\", () => {\n");
|
|
574
|
+
testOutput.write(" new Characteristic." + generated.className + "();\n");
|
|
575
|
+
if (generated.deprecatedClassName) {
|
|
576
|
+
testOutput.write(" // noinspection JSDeprecatedSymbols\n");
|
|
577
|
+
testOutput.write(" new Characteristic." + generated.deprecatedClassName + "();\n");
|
|
864
578
|
}
|
|
865
|
-
|
|
579
|
+
testOutput.write(" });\n");
|
|
580
|
+
testOutput.write(" });\n");
|
|
866
581
|
}
|
|
867
582
|
testOutput.write("});\n");
|
|
868
583
|
testOutput.end();
|
|
869
584
|
}
|
|
870
585
|
function writeServicesTestFile() {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
var testOutput = fs_1.default.createWriteStream(path_1.default.resolve(__dirname, "./ServiceDefinitions.spec.ts"), { encoding: "utf8" });
|
|
586
|
+
const services = Object.values(generatedServices).sort((a, b) => a.className.localeCompare(b.className));
|
|
587
|
+
const testOutput = fs_1.default.createWriteStream(path_1.default.resolve(__dirname, "./ServiceDefinitions.spec.ts"), { encoding: "utf8" });
|
|
874
588
|
testOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
|
|
875
589
|
testOutput.write("import \"./\";\n\n");
|
|
876
590
|
testOutput.write("import { Characteristic } from \"../Characteristic\";\n");
|
|
877
591
|
testOutput.write("import { Service } from \"../Service\";\n\n");
|
|
878
592
|
testOutput.write("describe(\"ServiceDefinitions\", () => {");
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
testOutput.write("
|
|
900
|
-
|
|
901
|
-
testOutput.write(" // noinspection JSDeprecatedSymbols\n");
|
|
902
|
-
testOutput.write("\n new Service." + generated.deprecatedClassName + "();\n");
|
|
903
|
-
}
|
|
904
|
-
testOutput.write(" });\n");
|
|
905
|
-
testOutput.write(" });\n");
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
catch (e_27_1) { e_27 = { error: e_27_1 }; }
|
|
909
|
-
finally {
|
|
910
|
-
try {
|
|
911
|
-
if (services_1_1 && !services_1_1.done && (_a = services_1.return)) _a.call(services_1);
|
|
593
|
+
for (const generated of services) {
|
|
594
|
+
testOutput.write("\n");
|
|
595
|
+
testOutput.write(" describe(\"" + generated.className + "\", () => {\n");
|
|
596
|
+
// first test is just calling the constructor
|
|
597
|
+
testOutput.write(" it(\"should be able to construct\", () => {\n");
|
|
598
|
+
testOutput.write(" const service0 = new Service." + generated.className + "();\n");
|
|
599
|
+
testOutput.write(" const service1 = new Service." + generated.className + "(\"test name\");\n");
|
|
600
|
+
testOutput.write(" const service2 = new Service." + generated.className + "(\"test name\", \"test sub type\");\n\n");
|
|
601
|
+
testOutput.write(" expect(service0.displayName).toBe(\"\");\n");
|
|
602
|
+
testOutput.write(" expect(service0.testCharacteristic(Characteristic.Name)).toBe(" + generated.requiredCharacteristics.includes("name") + ");\n");
|
|
603
|
+
testOutput.write(" expect(service0.subtype).toBeUndefined();\n\n");
|
|
604
|
+
testOutput.write(" expect(service1.displayName).toBe(\"test name\");\n");
|
|
605
|
+
testOutput.write(" expect(service1.testCharacteristic(Characteristic.Name)).toBe(true);\n");
|
|
606
|
+
testOutput.write(" expect(service1.getCharacteristic(Characteristic.Name).value).toBe(\"test name\");\n");
|
|
607
|
+
testOutput.write(" expect(service1.subtype).toBeUndefined();\n\n");
|
|
608
|
+
testOutput.write(" expect(service2.displayName).toBe(\"test name\");\n");
|
|
609
|
+
testOutput.write(" expect(service2.testCharacteristic(Characteristic.Name)).toBe(true);\n");
|
|
610
|
+
testOutput.write(" expect(service2.getCharacteristic(Characteristic.Name).value).toBe(\"test name\");\n");
|
|
611
|
+
testOutput.write(" expect(service2.subtype).toBe(\"test sub type\");\n");
|
|
612
|
+
if (generated.deprecatedClassName) {
|
|
613
|
+
testOutput.write(" // noinspection JSDeprecatedSymbols\n");
|
|
614
|
+
testOutput.write("\n new Service." + generated.deprecatedClassName + "();\n");
|
|
912
615
|
}
|
|
913
|
-
|
|
616
|
+
testOutput.write(" });\n");
|
|
617
|
+
testOutput.write(" });\n");
|
|
914
618
|
}
|
|
915
619
|
testOutput.write("});\n");
|
|
916
620
|
testOutput.end();
|