hap-nodejs 0.12.3-beta.26 → 0.12.3-beta.28

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 (139) hide show
  1. package/README.md +0 -1
  2. package/dist/BridgedCore.js +19 -18
  3. package/dist/BridgedCore.js.map +1 -1
  4. package/dist/Core.js +20 -17
  5. package/dist/Core.js.map +1 -1
  6. package/dist/accessories/AirConditioner_accessory.js +24 -24
  7. package/dist/accessories/AirConditioner_accessory.js.map +1 -1
  8. package/dist/accessories/AppleTVRemote_accessory.js +23 -23
  9. package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
  10. package/dist/accessories/Camera_accessory.js +373 -292
  11. package/dist/accessories/Camera_accessory.js.map +1 -1
  12. package/dist/accessories/Fan_accessory.js +21 -15
  13. package/dist/accessories/Fan_accessory.js.map +1 -1
  14. package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
  15. package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
  16. package/dist/accessories/Light-AdaptiveLighting_accessory.js +21 -31
  17. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
  18. package/dist/accessories/Light_accessory.js +48 -45
  19. package/dist/accessories/Light_accessory.js.map +1 -1
  20. package/dist/accessories/Lock_accessory.js +11 -11
  21. package/dist/accessories/Lock_accessory.js.map +1 -1
  22. package/dist/accessories/MotionSensor_accessory.js +8 -8
  23. package/dist/accessories/MotionSensor_accessory.js.map +1 -1
  24. package/dist/accessories/Outlet_accessory.js +10 -10
  25. package/dist/accessories/Outlet_accessory.js.map +1 -1
  26. package/dist/accessories/SmartSpeaker_accessory.js +11 -11
  27. package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
  28. package/dist/accessories/Sprinkler_accessory.js +19 -19
  29. package/dist/accessories/Sprinkler_accessory.js.map +1 -1
  30. package/dist/accessories/TV_accessory.js +17 -17
  31. package/dist/accessories/TV_accessory.js.map +1 -1
  32. package/dist/accessories/TemperatureSensor_accessory.js +6 -6
  33. package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
  34. package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
  35. package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
  36. package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
  37. package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
  38. package/dist/accessories/gstreamer-audioProducer.js +47 -36
  39. package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
  40. package/dist/accessories/types.js +2 -2
  41. package/dist/accessories/types.js.map +1 -1
  42. package/dist/index.js +5 -5
  43. package/dist/index.js.map +1 -1
  44. package/dist/lib/Accessory.d.ts.map +1 -1
  45. package/dist/lib/Accessory.js +1088 -780
  46. package/dist/lib/Accessory.js.map +1 -1
  47. package/dist/lib/AccessoryLoader.js +40 -40
  48. package/dist/lib/AccessoryLoader.js.map +1 -1
  49. package/dist/lib/Advertiser.js +524 -392
  50. package/dist/lib/Advertiser.js.map +1 -1
  51. package/dist/lib/Bridge.js +10 -6
  52. package/dist/lib/Bridge.js.map +1 -1
  53. package/dist/lib/Characteristic.d.ts.map +1 -1
  54. package/dist/lib/Characteristic.js +539 -1510
  55. package/dist/lib/Characteristic.js.map +1 -1
  56. package/dist/lib/HAPServer.js +265 -215
  57. package/dist/lib/HAPServer.js.map +1 -1
  58. package/dist/lib/Service.d.ts.map +1 -1
  59. package/dist/lib/Service.js +320 -519
  60. package/dist/lib/Service.js.map +1 -1
  61. package/dist/lib/camera/Camera.js +14 -14
  62. package/dist/lib/camera/Camera.js.map +1 -1
  63. package/dist/lib/camera/RTPProxy.js +104 -112
  64. package/dist/lib/camera/RTPProxy.js.map +1 -1
  65. package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
  66. package/dist/lib/camera/RTPStreamManagement.js +257 -286
  67. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  68. package/dist/lib/camera/RecordingManagement.js +384 -319
  69. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  70. package/dist/lib/camera/index.js +1 -1
  71. package/dist/lib/controller/AdaptiveLightingController.d.ts +3 -19
  72. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
  73. package/dist/lib/controller/AdaptiveLightingController.js +218 -217
  74. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  75. package/dist/lib/controller/CameraController.js +250 -191
  76. package/dist/lib/controller/CameraController.js.map +1 -1
  77. package/dist/lib/controller/DoorbellController.d.ts +1 -1
  78. package/dist/lib/controller/DoorbellController.js +40 -39
  79. package/dist/lib/controller/DoorbellController.js.map +1 -1
  80. package/dist/lib/controller/RemoteController.js +401 -343
  81. package/dist/lib/controller/RemoteController.js.map +1 -1
  82. package/dist/lib/controller/index.js +1 -1
  83. package/dist/lib/datastream/DataStreamManagement.js +57 -56
  84. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  85. package/dist/lib/datastream/DataStreamParser.js +304 -259
  86. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  87. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
  88. package/dist/lib/datastream/DataStreamServer.js +269 -252
  89. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  90. package/dist/lib/datastream/index.js +1 -1
  91. package/dist/lib/definitions/CharacteristicDefinitions.js +2858 -2089
  92. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  93. package/dist/lib/definitions/ServiceDefinitions.js +1096 -864
  94. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  95. package/dist/lib/definitions/generate-definitions.js +679 -383
  96. package/dist/lib/definitions/generate-definitions.js.map +1 -1
  97. package/dist/lib/definitions/generator-configuration.js +29 -29
  98. package/dist/lib/definitions/generator-configuration.js.map +1 -1
  99. package/dist/lib/definitions/index.js +1 -1
  100. package/dist/lib/model/AccessoryInfo.js +136 -101
  101. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  102. package/dist/lib/model/ControllerStorage.js +89 -86
  103. package/dist/lib/model/ControllerStorage.js.map +1 -1
  104. package/dist/lib/model/HAPStorage.js +16 -15
  105. package/dist/lib/model/HAPStorage.js.map +1 -1
  106. package/dist/lib/model/IdentifierCache.js +49 -49
  107. package/dist/lib/model/IdentifierCache.js.map +1 -1
  108. package/dist/lib/tv/AccessControlManagement.js +44 -40
  109. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  110. package/dist/lib/util/clone.js +27 -5
  111. package/dist/lib/util/clone.js.map +1 -1
  112. package/dist/lib/util/color-utils.js +12 -8
  113. package/dist/lib/util/color-utils.js.map +1 -1
  114. package/dist/lib/util/eventedhttp.d.ts.map +1 -1
  115. package/dist/lib/util/eventedhttp.js +409 -301
  116. package/dist/lib/util/eventedhttp.js.map +1 -1
  117. package/dist/lib/util/hapCrypto.js +32 -31
  118. package/dist/lib/util/hapCrypto.js.map +1 -1
  119. package/dist/lib/util/hapStatusError.js +12 -9
  120. package/dist/lib/util/hapStatusError.js.map +1 -1
  121. package/dist/lib/util/net-utils.js +53 -32
  122. package/dist/lib/util/net-utils.js.map +1 -1
  123. package/dist/lib/util/once.js +8 -3
  124. package/dist/lib/util/once.js.map +1 -1
  125. package/dist/lib/util/promise-utils.js +13 -8
  126. package/dist/lib/util/promise-utils.js.map +1 -1
  127. package/dist/lib/util/request-util.js +3 -2
  128. package/dist/lib/util/request-util.js.map +1 -1
  129. package/dist/lib/util/time.js +5 -5
  130. package/dist/lib/util/time.js.map +1 -1
  131. package/dist/lib/util/tlv.js +75 -57
  132. package/dist/lib/util/tlv.js.map +1 -1
  133. package/dist/lib/util/uuid.js +19 -15
  134. package/dist/lib/util/uuid.js.map +1 -1
  135. package/package.json +16 -16
  136. package/dist/lib/util/checkName.d.ts +0 -8
  137. package/dist/lib/util/checkName.d.ts.map +0 -1
  138. package/dist/lib/util/checkName.js +0 -17
  139. package/dist/lib/util/checkName.js.map +0 -1
@@ -1,405 +1,628 @@
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;
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
5
+ var tslib_1 = require("tslib");
4
6
  /* eslint-disable @typescript-eslint/no-use-before-define */
5
7
  require("./CharacteristicDefinitions");
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");
8
+ var assert_1 = tslib_1.__importDefault(require("assert"));
9
+ var commander_1 = require("commander");
10
+ var fs_1 = tslib_1.__importDefault(require("fs"));
11
+ var path_1 = tslib_1.__importDefault(require("path"));
12
+ var simple_plist_1 = tslib_1.__importDefault(require("simple-plist"));
13
+ var Characteristic_1 = require("../Characteristic");
14
+ var uuid_1 = require("../util/uuid");
15
+ var generator_configuration_1 = require("./generator-configuration");
14
16
  // noinspection JSUnusedLocalSymbols
15
17
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
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")
18
+ var temp = Characteristic_1.Characteristic; // this to have "../Characteristic" not being only type import, otherwise this would not result in a require statement
19
+ var command = new commander_1.Command("generate-definitions")
18
20
  .version("1.0.0")
19
21
  .option("-f, --force")
20
22
  .option("-m, --metadata <path>", "Define a custom location for the plain-metadata.config file", "/System/Library/PrivateFrameworks/HomeKitDaemon.framework/Resources/plain-metadata.config")
21
23
  .requiredOption("-s, --simulator <path>", "Define the path to the accessory simulator.");
22
24
  command.parse(process.argv);
23
- const options = command.opts();
24
- const metadataFile = options.metadata;
25
- const simulator = options.simulator;
25
+ var options = command.opts();
26
+ var metadataFile = options.metadata;
27
+ var simulator = options.simulator;
26
28
  if (!fs_1.default.existsSync(metadataFile)) {
27
- console.warn(`The metadata file at '${metadataFile}' does not exist!`);
29
+ console.warn("The metadata file at '".concat(metadataFile, "' does not exist!"));
28
30
  process.exit(1);
29
31
  }
30
32
  if (!fs_1.default.existsSync(simulator)) {
31
- console.warn(`The simulator app directory '${simulator}' does not exist!`);
33
+ console.warn("The simulator app directory '".concat(simulator, "' does not exist!"));
32
34
  process.exit(1);
33
35
  }
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;
36
+ var defaultPlist = path_1.default.resolve(simulator, "Contents/Frameworks/HAPAccessoryKit.framework/Resources/default.metadata.plist");
37
+ var defaultMfiPlist = path_1.default.resolve(simulator, "Contents/Frameworks/HAPAccessoryKit.framework/Resources/default_mfi.metadata.plist");
38
+ var plistData = simple_plist_1.default.readFileSync(metadataFile);
39
+ var simulatorPlistData = simple_plist_1.default.readFileSync(defaultPlist);
40
+ var simulatorMfiPlistData = fs_1.default.existsSync(defaultMfiPlist) ? simple_plist_1.default.readFileSync(defaultMfiPlist) : undefined;
39
41
  if (plistData.SchemaVersion !== 1) {
40
- console.warn(`Detected unsupported schema version ${plistData.SchemaVersion}!`);
42
+ console.warn("Detected unsupported schema version ".concat(plistData.SchemaVersion, "!"));
41
43
  }
42
44
  if (plistData.PlistDictionary.SchemaVersion !== 1) {
43
- console.warn(`Detect unsupported PlistDictionary schema version ${plistData.PlistDictionary.SchemaVersion}!`);
45
+ console.warn("Detect unsupported PlistDictionary schema version ".concat(plistData.PlistDictionary.SchemaVersion, "!"));
44
46
  }
45
- console.log(`Parsing version ${plistData.Version}...`);
46
- const shouldParseCharacteristics = checkWrittenVersion("./CharacteristicDefinitions.ts", plistData.Version);
47
- const shouldParseServices = checkWrittenVersion("./ServiceDefinitions.ts", plistData.Version);
47
+ console.log("Parsing version ".concat(plistData.Version, "..."));
48
+ var shouldParseCharacteristics = checkWrittenVersion("./CharacteristicDefinitions.ts", plistData.Version);
49
+ var shouldParseServices = checkWrittenVersion("./ServiceDefinitions.ts", plistData.Version);
48
50
  if (!options.force && (!shouldParseCharacteristics || !shouldParseServices)) {
49
51
  console.log("Parsed schema version " + plistData.Version + " is older than what's already generated. " +
50
52
  "User --force option to generate and overwrite nonetheless!");
51
53
  process.exit(1);
52
54
  }
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();
55
+ var undefinedUnits = ["micrograms/m^3", "ppm"];
56
+ var characteristics;
57
+ var simulatorCharacteristics = new Map();
58
+ var services;
59
+ var units;
60
+ var categories;
61
+ var properties = new Map();
60
62
  try {
61
63
  characteristics = checkDefined(plistData.PlistDictionary.HAP.Characteristics);
62
64
  services = checkDefined(plistData.PlistDictionary.HAP.Services);
63
65
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
64
66
  units = checkDefined(plistData.PlistDictionary.HAP.Units);
65
67
  categories = checkDefined(plistData.PlistDictionary.HomeKit.Categories);
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);
68
+ var props = checkDefined(plistData.PlistDictionary.HAP.Properties);
69
+ try {
70
+ // noinspection JSUnusedLocalSymbols
71
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
72
+ for (var _4 = tslib_1.__values(Object.entries(props).sort(function (_a, _b) {
73
+ var _c = tslib_1.__read(_a, 2), a = _c[0], aDef = _c[1];
74
+ var _d = tslib_1.__read(_b, 2), b = _d[0], bDef = _d[1];
75
+ return aDef.Position - bDef.Position;
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
+ }
74
83
  }
75
84
  }
76
- for (const characteristic of simulatorPlistData.Characteristics) {
77
- simulatorCharacteristics.set(characteristic.UUID, characteristic);
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; }
78
91
  }
79
- if (simulatorMfiPlistData) {
80
- for (const characteristic of simulatorMfiPlistData.Characteristics) {
92
+ try {
93
+ for (var _7 = tslib_1.__values(simulatorPlistData.Characteristics), _8 = _7.next(); !_8.done; _8 = _7.next()) {
94
+ var characteristic = _8.value;
81
95
  simulatorCharacteristics.set(characteristic.UUID, characteristic);
82
96
  }
83
97
  }
98
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
99
+ finally {
100
+ try {
101
+ if (_8 && !_8.done && (_b = _7.return)) _b.call(_7);
102
+ }
103
+ finally { if (e_2) throw e_2.error; }
104
+ }
105
+ if (simulatorMfiPlistData) {
106
+ try {
107
+ for (var _9 = tslib_1.__values(simulatorMfiPlistData.Characteristics), _10 = _9.next(); !_10.done; _10 = _9.next()) {
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; }
118
+ }
119
+ }
84
120
  }
85
121
  catch (error) {
86
122
  console.log("Unexpected structure of the plist file!");
87
123
  throw error;
88
124
  }
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}`);
125
+ try {
126
+ // first step is to check if we are up to date on categories
127
+ for (var _11 = tslib_1.__values(Object.values(categories)), _12 = _11.next(); !_12.done; _12 = _11.next()) {
128
+ var definition = _12.value;
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);
93
138
  }
139
+ finally { if (e_4) throw e_4.error; }
94
140
  }
95
- const characteristicOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "CharacteristicDefinitions.ts"));
141
+ var characteristicOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "CharacteristicDefinitions.ts"));
96
142
  characteristicOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
97
- characteristicOutput.write(`// V=${plistData.Version}\n`);
143
+ characteristicOutput.write("// V=".concat(plistData.Version, "\n"));
98
144
  characteristicOutput.write("\n");
99
145
  characteristicOutput.write("import { Access, Characteristic, Formats, Perms, Units } from \"../Characteristic\";\n\n");
100
146
  /**
101
147
  * Characteristics
102
148
  */
103
- const generatedCharacteristics = {}; // indexed by id
104
- const writtenCharacteristicEntries = {}; // indexed by class name
105
- for (const [id, definition] of Object.entries(characteristics)) {
106
- try {
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
149
+ var generatedCharacteristics = {}; // indexed by id
150
+ var writtenCharacteristicEntries = {}; // indexed by class name
151
+ try {
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; }
141
220
  }
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);
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
+ }
173
251
  }
174
252
  }
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;
253
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
254
+ finally {
255
+ try {
256
+ if (_14 && !_14.done && (_e = _13.return)) _e.call(_13);
257
+ }
258
+ finally { if (e_5) throw e_5.error; }
259
+ }
260
+ try {
261
+ for (var CharacteristicManualAdditions_1 = tslib_1.__values(generator_configuration_1.CharacteristicManualAdditions), CharacteristicManualAdditions_1_1 = CharacteristicManualAdditions_1.next(); !CharacteristicManualAdditions_1_1.done; CharacteristicManualAdditions_1_1 = CharacteristicManualAdditions_1.next()) {
262
+ var _25 = tslib_1.__read(CharacteristicManualAdditions_1_1.value, 2), id = _25[0], generated = _25[1];
263
+ generatedCharacteristics[id] = generated;
264
+ writtenCharacteristicEntries[generated.className] = generated;
265
+ if (generated.deprecatedClassName) {
266
+ writtenCharacteristicEntries[generated.deprecatedClassName] = generated;
267
+ }
180
268
  }
181
269
  }
182
- for (const generated of Object.values(generatedCharacteristics)
183
- .sort((a, b) => a.className.localeCompare(b.className))) {
270
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
271
+ finally {
184
272
  try {
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;
273
+ if (CharacteristicManualAdditions_1_1 && !CharacteristicManualAdditions_1_1.done && (_j = CharacteristicManualAdditions_1.return)) _j.call(CharacteristicManualAdditions_1);
274
+ }
275
+ finally { if (e_9) throw e_9.error; }
276
+ }
277
+ try {
278
+ for (var _26 = tslib_1.__values(Object.values(generatedCharacteristics)
279
+ .sort(function (a, b) { return a.className.localeCompare(b.className); })), _27 = _26.next(); !_27.done; _27 = _26.next()) {
280
+ var generated = _27.value;
281
+ try {
282
+ characteristicOutput.write("/**\n");
283
+ characteristicOutput.write(" * Characteristic \"" + generated.name + "\"\n");
284
+ if (generated.since) {
285
+ characteristicOutput.write(" * @since iOS " + generated.since + "\n");
286
+ }
287
+ if (generated.deprecatedNotice) {
288
+ characteristicOutput.write(" * @deprecated " + generated.deprecatedNotice + "\n");
289
+ }
290
+ characteristicOutput.write(" */\n");
291
+ characteristicOutput.write("export class " + generated.className + " extends Characteristic {\n\n");
292
+ characteristicOutput.write(" public static readonly UUID: string = \"" + generated.UUID + "\";\n\n");
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; }
205
314
  }
206
- characteristicOutput.write(` public static readonly ${name} = ${value};\n`);
315
+ characteristicOutput.write("\n");
207
316
  }
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`);
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");
213
332
  }
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");
228
- }
229
- if (generated.stepValue != null) {
230
- characteristicOutput.write(" minStep: " + generated.stepValue + ",\n");
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");
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");
345
+ }
346
+ if (generated.stepValue != null) {
347
+ characteristicOutput.write(" minStep: " + generated.stepValue + ",\n");
348
+ }
349
+ if (generated.maxLength != null) {
350
+ characteristicOutput.write(" maxLen: " + generated.maxLength + ",\n");
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");
369
+ }
370
+ characteristicOutput.write("Characteristic." + generated.className + " = " + generated.className + ";\n\n");
249
371
  }
250
- if (generated.deprecatedNotice) {
251
- characteristicOutput.write("// noinspection JSDeprecatedSymbols\n");
372
+ catch (error) {
373
+ throw new Error("Error thrown writing characteristic '" + generated.id + "' (" + generated.className + "): " + error.message);
252
374
  }
253
- characteristicOutput.write("Characteristic." + generated.className + " = " + generated.className + ";\n\n");
254
375
  }
255
- catch (error) {
256
- throw new Error("Error thrown writing characteristic '" + generated.id + "' (" + generated.className + "): " + error.message);
376
+ }
377
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
378
+ finally {
379
+ try {
380
+ if (_27 && !_27.done && (_k = _26.return)) _k.call(_26);
257
381
  }
382
+ finally { if (e_10) throw e_10.error; }
258
383
  }
259
384
  characteristicOutput.end();
260
- const characteristicProperties = Object.entries(writtenCharacteristicEntries).sort(([a], [b]) => a.localeCompare(b));
385
+ var characteristicProperties = Object.entries(writtenCharacteristicEntries).sort(function (_a, _b) {
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
+ });
261
390
  rewriteProperties("Characteristic", characteristicProperties);
262
391
  writeCharacteristicTestFile();
263
392
  /**
264
393
  * Services
265
394
  */
266
- const serviceOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "ServiceDefinitions.ts"));
395
+ var serviceOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "ServiceDefinitions.ts"));
267
396
  serviceOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
268
- serviceOutput.write(`// V=${plistData.Version}\n`);
397
+ serviceOutput.write("// V=".concat(plistData.Version, "\n"));
269
398
  serviceOutput.write("\n");
270
399
  serviceOutput.write("import { Characteristic } from \"../Characteristic\";\n");
271
400
  serviceOutput.write("import { Service } from \"../Service\";\n\n");
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);
401
+ var generatedServices = {}; // indexed by id
402
+ var writtenServiceEntries = {}; // indexed by class name
403
+ try {
404
+ for (var _32 = tslib_1.__values(Object.entries(services)), _33 = _32.next(); !_33.done; _33 = _32.next()) {
405
+ var _34 = tslib_1.__read(_33.value, 2), id = _34[0], definition = _34[1];
406
+ try {
407
+ // "Carbon dioxide Sensor" -> "Carbon Dioxide Sensor"
408
+ var name = ((_2 = generator_configuration_1.ServiceNameOverrides.get(id)) !== null && _2 !== void 0 ? _2 : definition.DefaultDescription).split(" ").map(function (entry) { return entry[0].toUpperCase() + entry.slice(1); }).join(" ");
409
+ var deprecatedName = generator_configuration_1.ServiceDeprecatedNames.get(id);
410
+ var className = name.replace(/[\s-]/g, "").replace(/[.]/g, "_");
411
+ var deprecatedClassName = deprecatedName === null || deprecatedName === void 0 ? void 0 : deprecatedName.replace(/[\s-]/g, "").replace(/[.]/g, "_");
412
+ var longUUID = (0, uuid_1.toLongForm)(definition.ShortUUID);
413
+ var requiredCharacteristics = definition.Characteristics.Required;
414
+ var optionalCharacteristics = definition.Characteristics.Optional;
415
+ var configurationOverride = generator_configuration_1.ServiceCharacteristicConfigurationOverrides.get(id);
416
+ if (configurationOverride) {
417
+ if (configurationOverride.removedRequired) {
418
+ try {
419
+ for (var _35 = (e_14 = void 0, tslib_1.__values(configurationOverride.removedRequired)), _36 = _35.next(); !_36.done; _36 = _35.next()) {
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; }
291
433
  }
292
434
  }
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);
435
+ if (configurationOverride.removedOptional) {
436
+ try {
437
+ for (var _37 = (e_15 = void 0, tslib_1.__values(configurationOverride.removedOptional)), _38 = _37.next(); !_38.done; _38 = _37.next()) {
438
+ var entry = _38.value;
439
+ var index = optionalCharacteristics.indexOf(entry);
440
+ if (index !== -1) {
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; }
299
451
  }
300
452
  }
301
- }
302
- if (configurationOverride.addedRequired) {
303
- for (const entry of configurationOverride.addedRequired) {
304
- if (!requiredCharacteristics.includes(entry)) {
305
- requiredCharacteristics.push(entry);
453
+ if (configurationOverride.addedRequired) {
454
+ try {
455
+ for (var _39 = (e_16 = void 0, tslib_1.__values(configurationOverride.addedRequired)), _40 = _39.next(); !_40.done; _40 = _39.next()) {
456
+ var entry = _40.value;
457
+ if (!requiredCharacteristics.includes(entry)) {
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; }
306
468
  }
307
469
  }
308
- }
309
- if (configurationOverride.addedOptional) {
310
- for (const entry of configurationOverride.addedOptional) {
311
- if (!optionalCharacteristics.includes(entry)) {
312
- optionalCharacteristics.push(entry);
470
+ if (configurationOverride.addedOptional) {
471
+ try {
472
+ for (var _41 = (e_17 = void 0, tslib_1.__values(configurationOverride.addedOptional)), _42 = _41.next(); !_42.done; _42 = _41.next()) {
473
+ var entry = _42.value;
474
+ if (!optionalCharacteristics.includes(entry)) {
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; }
313
485
  }
314
486
  }
315
487
  }
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
+ }
316
503
  }
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;
504
+ catch (error) {
505
+ throw new Error("Error thrown generating service '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
331
506
  }
332
507
  }
333
- catch (error) {
334
- throw new Error("Error thrown generating service '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
508
+ }
509
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
510
+ finally {
511
+ try {
512
+ if (_33 && !_33.done && (_o = _32.return)) _o.call(_32);
335
513
  }
514
+ finally { if (e_13) throw e_13.error; }
336
515
  }
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;
516
+ try {
517
+ for (var ServiceManualAdditions_1 = tslib_1.__values(generator_configuration_1.ServiceManualAdditions), ServiceManualAdditions_1_1 = ServiceManualAdditions_1.next(); !ServiceManualAdditions_1_1.done; ServiceManualAdditions_1_1 = ServiceManualAdditions_1.next()) {
518
+ var _43 = tslib_1.__read(ServiceManualAdditions_1_1.value, 2), id = _43[0], generated = _43[1];
519
+ generatedServices[id] = generated;
520
+ writtenServiceEntries[generated.className] = generated;
521
+ if (generated.deprecatedClassName) {
522
+ writtenServiceEntries[generated.deprecatedClassName] = generated;
523
+ }
342
524
  }
343
525
  }
344
- for (const generated of Object.values(generatedServices)
345
- .sort((a, b) => a.className.localeCompare(b.className))) {
526
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
527
+ finally {
346
528
  try {
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;
529
+ if (ServiceManualAdditions_1_1 && !ServiceManualAdditions_1_1.done && (_t = ServiceManualAdditions_1.return)) _t.call(ServiceManualAdditions_1);
530
+ }
531
+ finally { if (e_18) throw e_18.error; }
532
+ }
533
+ try {
534
+ for (var _44 = tslib_1.__values(Object.values(generatedServices)
535
+ .sort(function (a, b) { return a.className.localeCompare(b.className); })), _45 = _44.next(); !_45.done; _45 = _44.next()) {
536
+ var generated = _45.value;
537
+ try {
538
+ serviceOutput.write("/**\n");
539
+ serviceOutput.write(" * Service \"" + generated.name + "\"\n");
540
+ if (generated.since) {
541
+ serviceOutput.write(" * @since iOS " + generated.since + "\n");
366
542
  }
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");
543
+ if (generated.deprecatedNotice) {
544
+ serviceOutput.write(" * @deprecated " + generated.deprecatedNotice + "\n");
371
545
  }
372
- else {
373
- serviceOutput.write(" this.addCharacteristic(Characteristic." + characteristic.className + ");\n");
546
+ serviceOutput.write(" */\n");
547
+ serviceOutput.write("export class " + generated.className + " extends Service {\n\n");
548
+ serviceOutput.write(" public static readonly UUID: string = \"" + generated.UUID + "\";\n\n");
549
+ serviceOutput.write(" constructor(displayName?: string, subtype?: string) {\n");
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
+ }
374
569
  }
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;
570
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
571
+ finally {
572
+ try {
573
+ if (_47 && !_47.done && (_v = _46.return)) _v.call(_46);
383
574
  }
384
- serviceOutput.write(" this.addOptionalCharacteristic(Characteristic." + characteristic.className + ");\n");
575
+ finally { if (e_20) throw e_20.error; }
385
576
  }
577
+ if ((_3 = generated.optionalCharacteristics) === null || _3 === void 0 ? void 0 : _3.length) {
578
+ serviceOutput.write("\n // Optional Characteristics\n");
579
+ try {
580
+ for (var _48 = (e_21 = void 0, tslib_1.__values(generated.optionalCharacteristics)), _49 = _48.next(); !_49.done; _49 = _48.next()) {
581
+ var optional = _49.value;
582
+ var characteristic = generatedCharacteristics[optional];
583
+ if (!characteristic) {
584
+ console.warn("Could not find optional characteristic " + optional + " for " + generated.className);
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; }
596
+ }
597
+ }
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");
386
607
  }
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");
608
+ catch (error) {
609
+ throw new Error("Error thrown writing service '" + generated.id + "' (" + generated.className + "): " + error.message);
394
610
  }
395
- serviceOutput.write("Service." + generated.className + " = " + generated.className + ";\n\n");
396
611
  }
397
- catch (error) {
398
- throw new Error("Error thrown writing service '" + generated.id + "' (" + generated.className + "): " + error.message);
612
+ }
613
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
614
+ finally {
615
+ try {
616
+ if (_45 && !_45.done && (_u = _44.return)) _u.call(_44);
399
617
  }
618
+ finally { if (e_19) throw e_19.error; }
400
619
  }
401
620
  serviceOutput.end();
402
- const serviceProperties = Object.entries(writtenServiceEntries).sort(([a], [b]) => a.localeCompare(b));
621
+ var serviceProperties = Object.entries(writtenServiceEntries).sort(function (_a, _b) {
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
+ });
403
626
  rewriteProperties("Service", serviceProperties);
404
627
  writeServicesTestFile();
405
628
  // ------------------------ utils ------------------------
@@ -410,30 +633,63 @@ function checkDefined(input) {
410
633
  return input;
411
634
  }
412
635
  function characteristicFormat(format) {
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;
636
+ var e_22, _a;
637
+ try {
638
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
639
+ for (var _b = tslib_1.__values(Object.entries(Characteristic_1.Formats)), _c = _b.next(); !_c.done; _c = _b.next()) {
640
+ var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
641
+ if (value === format) {
642
+ return key;
643
+ }
417
644
  }
418
645
  }
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
+ }
419
653
  throw new Error("Unknown characteristic format '" + format + "'");
420
654
  }
421
655
  function characteristicUnit(unit) {
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;
656
+ var e_23, _a;
657
+ try {
658
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
659
+ for (var _b = tslib_1.__values(Object.entries(Characteristic_1.Units)), _c = _b.next(); !_c.done; _c = _b.next()) {
660
+ var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
661
+ if (value === unit) {
662
+ return key;
663
+ }
426
664
  }
427
665
  }
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
+ }
428
673
  throw new Error("Unknown characteristic format '" + unit + "'");
429
674
  }
430
675
  function characteristicAccess(access) {
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;
676
+ var e_24, _a;
677
+ try {
678
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
679
+ for (var _b = tslib_1.__values(Object.entries(Characteristic_1.Access)), _c = _b.next(); !_c.done; _c = _b.next()) {
680
+ var _d = tslib_1.__read(_c.value, 2), key = _d[0], value = _d[1];
681
+ if (value === access) {
682
+ return key;
683
+ }
435
684
  }
436
685
  }
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
+ }
437
693
  throw new Error("Unknown access for '" + access + "'");
438
694
  }
439
695
  function characteristicPerm(id) {
@@ -461,43 +717,54 @@ function characteristicPerm(id) {
461
717
  }
462
718
  }
463
719
  function generatePermsString(id, propertiesBitMap) {
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;
720
+ var e_25, _a;
721
+ var perms = [];
722
+ try {
723
+ for (var properties_1 = tslib_1.__values(properties), properties_1_1 = properties_1.next(); !properties_1_1.done; properties_1_1 = properties_1.next()) {
724
+ var _b = tslib_1.__read(properties_1_1.value, 2), bitMap = _b[0], name = _b[1];
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
+ }
469
732
  }
470
- if ((propertiesBitMap | bitMap) === propertiesBitMap) { // if it stays the same the bit is set
471
- perms.push("Perms." + name);
733
+ }
734
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
735
+ finally {
736
+ try {
737
+ if (properties_1_1 && !properties_1_1.done && (_a = properties_1.return)) _a.call(properties_1);
472
738
  }
739
+ finally { if (e_25) throw e_25.error; }
473
740
  }
474
- const result = perms.join(", ");
741
+ var result = perms.join(", ");
475
742
  (0, assert_1.default)(!!result, "perms string cannot be empty (" + propertiesBitMap + ")");
476
743
  return result;
477
744
  }
478
745
  function checkWrittenVersion(filePath, parsingVersion) {
479
746
  filePath = path_1.default.resolve(__dirname, filePath);
480
- const content = fs_1.default.readFileSync(filePath, { encoding: "utf8" }).split("\n", 3);
481
- const v = content[1];
747
+ var content = fs_1.default.readFileSync(filePath, { encoding: "utf8" }).split("\n", 3);
748
+ var v = content[1];
482
749
  if (!v.startsWith("// V=")) {
483
750
  throw new Error("Could not detect definition version for '" + filePath + "'");
484
751
  }
485
- const version = parseInt(v.replace("// V=", ""), 10);
752
+ var version = parseInt(v.replace("// V=", ""), 10);
486
753
  return parsingVersion >= version;
487
754
  }
488
755
  function rewriteProperties(className, properties) {
489
- const filePath = path_1.default.resolve(__dirname, "../" + className + ".ts");
756
+ var filePath = path_1.default.resolve(__dirname, "../" + className + ".ts");
490
757
  if (!fs_1.default.existsSync(filePath)) {
491
758
  throw new Error("File '" + filePath + "' does not exist!");
492
759
  }
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;
760
+ var file = fs_1.default.readFileSync(filePath, { encoding: "utf8" });
761
+ var lines = file.split("\n");
762
+ var i = 0;
763
+ var importStart = -1;
764
+ var importEnd = -1;
765
+ var foundImport = false;
499
766
  for (; i < lines.length; i++) {
500
- const line = lines[i];
767
+ var line = lines[i];
501
768
  if (line === "import type {") {
502
769
  importStart = i; // save last import start;
503
770
  }
@@ -510,8 +777,8 @@ function rewriteProperties(className, properties) {
510
777
  if (!foundImport) {
511
778
  throw new Error("Could not find import section!");
512
779
  }
513
- let startIndex = -1;
514
- let stopIndex = -1;
780
+ var startIndex = -1;
781
+ var stopIndex = -1;
515
782
  for (; i < lines.length; i++) {
516
783
  if (lines[i] === " // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-") {
517
784
  startIndex = i;
@@ -530,18 +797,25 @@ function rewriteProperties(className, properties) {
530
797
  if (stopIndex === -1) {
531
798
  throw new Error("Could not find stop pattern in file!");
532
799
  }
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;
800
+ var importSize = importEnd - importStart - 1;
801
+ var newImports = properties
802
+ .filter(function (_a) {
803
+ var _b = tslib_1.__read(_a, 2), key = _b[0], value = _b[1];
804
+ return key === value.className;
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;
539
812
  startIndex += importDelta;
540
813
  stopIndex += importDelta;
541
- const amount = stopIndex - startIndex - 1;
542
- const newContentLines = properties.map(([key, value]) => {
543
- let line = "";
544
- let deprecatedNotice = value.deprecatedNotice;
814
+ var amount = stopIndex - startIndex - 1;
815
+ var newContentLines = properties.map(function (_a) {
816
+ var _b = tslib_1.__read(_a, 2), key = _b[0], value = _b[1];
817
+ var line = "";
818
+ var deprecatedNotice = value.deprecatedNotice;
545
819
  if (key !== value.className) {
546
820
  deprecatedNotice = "Please use {@link " + className + "." + value.className + "}." // prepend deprecated notice
547
821
  + (deprecatedNotice ? " " + deprecatedNotice : "");
@@ -555,66 +829,88 @@ function rewriteProperties(className, properties) {
555
829
  line += " public static " + key + ": typeof " + value.className + ";";
556
830
  return line;
557
831
  });
558
- lines.splice(startIndex + 1, amount, ...newContentLines); // insert new lines
559
- const resultContent = lines.join("\n");
832
+ lines.splice.apply(lines, tslib_1.__spreadArray([startIndex + 1, amount], tslib_1.__read(newContentLines), false)); // insert new lines
833
+ var resultContent = lines.join("\n");
560
834
  fs_1.default.writeFileSync(filePath, resultContent, { encoding: "utf8" });
561
835
  }
562
836
  function writeCharacteristicTestFile() {
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" });
837
+ var e_26, _a;
838
+ var characteristics = Object.values(generatedCharacteristics).sort(function (a, b) { return a.className.localeCompare(b.className); });
839
+ var testOutput = fs_1.default.createWriteStream(path_1.default.resolve(__dirname, "./CharacteristicDefinitions.spec.ts"), { encoding: "utf8" });
565
840
  testOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
566
841
  testOutput.write("import \"./\";\n\n");
567
842
  testOutput.write("import { Characteristic } from \"../Characteristic\";\n\n");
568
843
  testOutput.write("describe(\"CharacteristicDefinitions\", () => {");
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");
844
+ try {
845
+ for (var characteristics_1 = tslib_1.__values(characteristics), characteristics_1_1 = characteristics_1.next(); !characteristics_1_1.done; characteristics_1_1 = characteristics_1.next()) {
846
+ var generated = characteristics_1_1.value;
847
+ testOutput.write("\n");
848
+ testOutput.write(" describe(\"" + generated.className + "\", () => {\n");
849
+ // first test is just calling the constructor
850
+ testOutput.write(" it(\"should be able to construct\", () => {\n");
851
+ testOutput.write(" new Characteristic." + generated.className + "();\n");
852
+ if (generated.deprecatedClassName) {
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);
578
864
  }
579
- testOutput.write(" });\n");
580
- testOutput.write(" });\n");
865
+ finally { if (e_26) throw e_26.error; }
581
866
  }
582
867
  testOutput.write("});\n");
583
868
  testOutput.end();
584
869
  }
585
870
  function writeServicesTestFile() {
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" });
871
+ var e_27, _a;
872
+ var services = Object.values(generatedServices).sort(function (a, b) { return a.className.localeCompare(b.className); });
873
+ var testOutput = fs_1.default.createWriteStream(path_1.default.resolve(__dirname, "./ServiceDefinitions.spec.ts"), { encoding: "utf8" });
588
874
  testOutput.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
589
875
  testOutput.write("import \"./\";\n\n");
590
876
  testOutput.write("import { Characteristic } from \"../Characteristic\";\n");
591
877
  testOutput.write("import { Service } from \"../Service\";\n\n");
592
878
  testOutput.write("describe(\"ServiceDefinitions\", () => {");
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");
879
+ try {
880
+ for (var services_1 = tslib_1.__values(services), services_1_1 = services_1.next(); !services_1_1.done; services_1_1 = services_1.next()) {
881
+ var generated = services_1_1.value;
882
+ testOutput.write("\n");
883
+ testOutput.write(" describe(\"" + generated.className + "\", () => {\n");
884
+ // first test is just calling the constructor
885
+ testOutput.write(" it(\"should be able to construct\", () => {\n");
886
+ testOutput.write(" const service0 = new Service." + generated.className + "();\n");
887
+ testOutput.write(" const service1 = new Service." + generated.className + "(\"test name\");\n");
888
+ testOutput.write(" const service2 = new Service." + generated.className + "(\"test name\", \"test sub type\");\n\n");
889
+ testOutput.write(" expect(service0.displayName).toBe(\"\");\n");
890
+ testOutput.write(" expect(service0.testCharacteristic(Characteristic.Name)).toBe(" + generated.requiredCharacteristics.includes("name") + ");\n");
891
+ testOutput.write(" expect(service0.subtype).toBeUndefined();\n\n");
892
+ testOutput.write(" expect(service1.displayName).toBe(\"test name\");\n");
893
+ testOutput.write(" expect(service1.testCharacteristic(Characteristic.Name)).toBe(true);\n");
894
+ testOutput.write(" expect(service1.getCharacteristic(Characteristic.Name).value).toBe(\"test name\");\n");
895
+ testOutput.write(" expect(service1.subtype).toBeUndefined();\n\n");
896
+ testOutput.write(" expect(service2.displayName).toBe(\"test name\");\n");
897
+ testOutput.write(" expect(service2.testCharacteristic(Characteristic.Name)).toBe(true);\n");
898
+ testOutput.write(" expect(service2.getCharacteristic(Characteristic.Name).value).toBe(\"test name\");\n");
899
+ testOutput.write(" expect(service2.subtype).toBe(\"test sub type\");\n");
900
+ if (generated.deprecatedClassName) {
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);
615
912
  }
616
- testOutput.write(" });\n");
617
- testOutput.write(" });\n");
913
+ finally { if (e_27) throw e_27.error; }
618
914
  }
619
915
  testOutput.write("});\n");
620
916
  testOutput.end();