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.
Files changed (175) hide show
  1. package/README.md +1 -0
  2. package/dist/accessories/AirConditioner_accessory.js +24 -24
  3. package/dist/accessories/AirConditioner_accessory.js.map +1 -1
  4. package/dist/accessories/AppleTVRemote_accessory.js +23 -23
  5. package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
  6. package/dist/accessories/Camera_accessory.js +292 -373
  7. package/dist/accessories/Camera_accessory.js.map +1 -1
  8. package/dist/accessories/Fan_accessory.js +15 -21
  9. package/dist/accessories/Fan_accessory.js.map +1 -1
  10. package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
  11. package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
  12. package/dist/accessories/Light-AdaptiveLighting_accessory.js +31 -21
  13. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
  14. package/dist/accessories/Light_accessory.js +45 -48
  15. package/dist/accessories/Light_accessory.js.map +1 -1
  16. package/dist/accessories/Lock_accessory.js +11 -11
  17. package/dist/accessories/Lock_accessory.js.map +1 -1
  18. package/dist/accessories/MotionSensor_accessory.js +8 -8
  19. package/dist/accessories/MotionSensor_accessory.js.map +1 -1
  20. package/dist/accessories/Outlet_accessory.js +10 -10
  21. package/dist/accessories/Outlet_accessory.js.map +1 -1
  22. package/dist/accessories/SmartSpeaker_accessory.js +11 -11
  23. package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
  24. package/dist/accessories/Sprinkler_accessory.js +19 -19
  25. package/dist/accessories/Sprinkler_accessory.js.map +1 -1
  26. package/dist/accessories/TV_accessory.js +17 -17
  27. package/dist/accessories/TV_accessory.js.map +1 -1
  28. package/dist/accessories/TemperatureSensor_accessory.js +6 -6
  29. package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
  30. package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
  31. package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
  32. package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
  33. package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
  34. package/dist/accessories/gstreamer-audioProducer.js +36 -47
  35. package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
  36. package/dist/accessories/types.js +2 -2
  37. package/dist/accessories/types.js.map +1 -1
  38. package/dist/index.d.ts +0 -14
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +5 -28
  41. package/dist/index.js.map +1 -1
  42. package/dist/lib/Accessory.d.ts +1 -58
  43. package/dist/lib/Accessory.d.ts.map +1 -1
  44. package/dist/lib/Accessory.js +747 -1149
  45. package/dist/lib/Accessory.js.map +1 -1
  46. package/dist/lib/Advertiser.d.ts +1 -2
  47. package/dist/lib/Advertiser.d.ts.map +1 -1
  48. package/dist/lib/Advertiser.js +392 -524
  49. package/dist/lib/Advertiser.js.map +1 -1
  50. package/dist/lib/Bridge.js +6 -10
  51. package/dist/lib/Bridge.js.map +1 -1
  52. package/dist/lib/Characteristic.d.ts +2 -133
  53. package/dist/lib/Characteristic.d.ts.map +1 -1
  54. package/dist/lib/Characteristic.js +1467 -669
  55. package/dist/lib/Characteristic.js.map +1 -1
  56. package/dist/lib/HAPServer.d.ts +0 -10
  57. package/dist/lib/HAPServer.d.ts.map +1 -1
  58. package/dist/lib/HAPServer.js +216 -280
  59. package/dist/lib/HAPServer.js.map +1 -1
  60. package/dist/lib/Service.d.ts +1 -51
  61. package/dist/lib/Service.d.ts.map +1 -1
  62. package/dist/lib/Service.js +474 -322
  63. package/dist/lib/Service.js.map +1 -1
  64. package/dist/lib/camera/RTPProxy.js +112 -104
  65. package/dist/lib/camera/RTPProxy.js.map +1 -1
  66. package/dist/lib/camera/RTPStreamManagement.d.ts +0 -65
  67. package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
  68. package/dist/lib/camera/RTPStreamManagement.js +255 -278
  69. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  70. package/dist/lib/camera/RecordingManagement.js +318 -381
  71. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  72. package/dist/lib/camera/index.d.ts +0 -1
  73. package/dist/lib/camera/index.d.ts.map +1 -1
  74. package/dist/lib/camera/index.js +1 -2
  75. package/dist/lib/camera/index.js.map +1 -1
  76. package/dist/lib/controller/AdaptiveLightingController.d.ts +19 -3
  77. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
  78. package/dist/lib/controller/AdaptiveLightingController.js +217 -218
  79. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  80. package/dist/lib/controller/CameraController.d.ts +0 -4
  81. package/dist/lib/controller/CameraController.d.ts.map +1 -1
  82. package/dist/lib/controller/CameraController.js +189 -256
  83. package/dist/lib/controller/CameraController.js.map +1 -1
  84. package/dist/lib/controller/DoorbellController.js +38 -39
  85. package/dist/lib/controller/DoorbellController.js.map +1 -1
  86. package/dist/lib/controller/RemoteController.d.ts +0 -14
  87. package/dist/lib/controller/RemoteController.d.ts.map +1 -1
  88. package/dist/lib/controller/RemoteController.js +340 -415
  89. package/dist/lib/controller/RemoteController.js.map +1 -1
  90. package/dist/lib/controller/index.js +1 -1
  91. package/dist/lib/datastream/DataStreamManagement.js +56 -57
  92. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  93. package/dist/lib/datastream/DataStreamParser.js +259 -304
  94. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  95. package/dist/lib/datastream/DataStreamServer.d.ts +0 -5
  96. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
  97. package/dist/lib/datastream/DataStreamServer.js +252 -269
  98. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  99. package/dist/lib/datastream/index.js +1 -1
  100. package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -106
  101. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
  102. package/dist/lib/definitions/CharacteristicDefinitions.js +2000 -2995
  103. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  104. package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -32
  105. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
  106. package/dist/lib/definitions/ServiceDefinitions.js +820 -1147
  107. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  108. package/dist/lib/definitions/generate-definitions.js +383 -679
  109. package/dist/lib/definitions/generate-definitions.js.map +1 -1
  110. package/dist/lib/definitions/generator-configuration.js +29 -29
  111. package/dist/lib/definitions/generator-configuration.js.map +1 -1
  112. package/dist/lib/definitions/index.js +1 -1
  113. package/dist/lib/model/AccessoryInfo.js +101 -136
  114. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  115. package/dist/lib/model/ControllerStorage.js +86 -89
  116. package/dist/lib/model/ControllerStorage.js.map +1 -1
  117. package/dist/lib/model/HAPStorage.js +15 -16
  118. package/dist/lib/model/HAPStorage.js.map +1 -1
  119. package/dist/lib/model/IdentifierCache.js +49 -49
  120. package/dist/lib/model/IdentifierCache.js.map +1 -1
  121. package/dist/lib/tv/AccessControlManagement.js +40 -44
  122. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  123. package/dist/lib/util/checkName.d.ts +2 -1
  124. package/dist/lib/util/checkName.d.ts.map +1 -1
  125. package/dist/lib/util/checkName.js +7 -11
  126. package/dist/lib/util/checkName.js.map +1 -1
  127. package/dist/lib/util/clone.js +5 -27
  128. package/dist/lib/util/clone.js.map +1 -1
  129. package/dist/lib/util/color-utils.js +8 -12
  130. package/dist/lib/util/color-utils.js.map +1 -1
  131. package/dist/lib/util/eventedhttp.d.ts.map +1 -1
  132. package/dist/lib/util/eventedhttp.js +301 -409
  133. package/dist/lib/util/eventedhttp.js.map +1 -1
  134. package/dist/lib/util/hapCrypto.js +31 -32
  135. package/dist/lib/util/hapCrypto.js.map +1 -1
  136. package/dist/lib/util/hapStatusError.js +9 -12
  137. package/dist/lib/util/hapStatusError.js.map +1 -1
  138. package/dist/lib/util/net-utils.js +32 -53
  139. package/dist/lib/util/net-utils.js.map +1 -1
  140. package/dist/lib/util/once.js +3 -8
  141. package/dist/lib/util/once.js.map +1 -1
  142. package/dist/lib/util/promise-utils.js +8 -13
  143. package/dist/lib/util/promise-utils.js.map +1 -1
  144. package/dist/lib/util/request-util.js +2 -3
  145. package/dist/lib/util/request-util.js.map +1 -1
  146. package/dist/lib/util/time.js +5 -5
  147. package/dist/lib/util/time.js.map +1 -1
  148. package/dist/lib/util/tlv.d.ts +0 -27
  149. package/dist/lib/util/tlv.d.ts.map +1 -1
  150. package/dist/lib/util/tlv.js +71 -113
  151. package/dist/lib/util/tlv.js.map +1 -1
  152. package/dist/lib/util/uuid.d.ts +0 -9
  153. package/dist/lib/util/uuid.d.ts.map +1 -1
  154. package/dist/lib/util/uuid.js +15 -33
  155. package/dist/lib/util/uuid.js.map +1 -1
  156. package/dist/types.d.ts +0 -35
  157. package/dist/types.d.ts.map +1 -1
  158. package/dist/types.js.map +1 -1
  159. package/package.json +10 -10
  160. package/dist/BridgedCore.d.ts +0 -2
  161. package/dist/BridgedCore.d.ts.map +0 -1
  162. package/dist/BridgedCore.js +0 -43
  163. package/dist/BridgedCore.js.map +0 -1
  164. package/dist/Core.d.ts +0 -2
  165. package/dist/Core.d.ts.map +0 -1
  166. package/dist/Core.js +0 -52
  167. package/dist/Core.js.map +0 -1
  168. package/dist/lib/AccessoryLoader.d.ts +0 -28
  169. package/dist/lib/AccessoryLoader.d.ts.map +0 -1
  170. package/dist/lib/AccessoryLoader.js +0 -166
  171. package/dist/lib/AccessoryLoader.js.map +0 -1
  172. package/dist/lib/camera/Camera.d.ts +0 -43
  173. package/dist/lib/camera/Camera.d.ts.map +0 -1
  174. package/dist/lib/camera/Camera.js +0 -36
  175. 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
- var tslib_1 = require("tslib");
3
+ const tslib_1 = require("tslib");
6
4
  /* eslint-disable @typescript-eslint/no-use-before-define */
7
5
  require("./CharacteristicDefinitions");
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");
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
- 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")
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
- var options = command.opts();
26
- var metadataFile = options.metadata;
27
- var simulator = options.simulator;
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("The metadata file at '".concat(metadataFile, "' does not exist!"));
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("The simulator app directory '".concat(simulator, "' does not exist!"));
31
+ console.warn(`The simulator app directory '${simulator}' does not exist!`);
34
32
  process.exit(1);
35
33
  }
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;
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("Detected unsupported schema version ".concat(plistData.SchemaVersion, "!"));
40
+ console.warn(`Detected unsupported schema version ${plistData.SchemaVersion}!`);
43
41
  }
44
42
  if (plistData.PlistDictionary.SchemaVersion !== 1) {
45
- console.warn("Detect unsupported PlistDictionary schema version ".concat(plistData.PlistDictionary.SchemaVersion, "!"));
43
+ console.warn(`Detect unsupported PlistDictionary schema version ${plistData.PlistDictionary.SchemaVersion}!`);
46
44
  }
47
- console.log("Parsing version ".concat(plistData.Version, "..."));
48
- var shouldParseCharacteristics = checkWrittenVersion("./CharacteristicDefinitions.ts", plistData.Version);
49
- var shouldParseServices = checkWrittenVersion("./ServiceDefinitions.ts", plistData.Version);
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
- 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();
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
- 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
- }
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
- 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; }
76
+ for (const characteristic of simulatorPlistData.Characteristics) {
77
+ simulatorCharacteristics.set(characteristic.UUID, characteristic);
104
78
  }
105
79
  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; }
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
- 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);
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
- var characteristicOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "CharacteristicDefinitions.ts"));
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("// V=".concat(plistData.Version, "\n"));
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
- 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; }
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 (_14 && !_14.done && (_e = _13.return)) _e.call(_13);
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
- 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
- }
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
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
271
- finally {
182
+ for (const generated of Object.values(generatedCharacteristics)
183
+ .sort((a, b) => a.className.localeCompare(b.className))) {
272
184
  try {
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; }
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("\n");
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
- 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");
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("Characteristic." + generated.className + " = " + generated.className + ";\n\n");
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
- catch (error) {
373
- throw new Error("Error thrown writing characteristic '" + generated.id + "' (" + generated.className + "): " + error.message);
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
- 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);
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
- 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
- });
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
- var serviceOutput = fs_1.default.createWriteStream(path_1.default.join(__dirname, "ServiceDefinitions.ts"));
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("// V=".concat(plistData.Version, "\n"));
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
- 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; }
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
- 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; }
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
- 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; }
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
- 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; }
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
- catch (error) {
505
- throw new Error("Error thrown generating service '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
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
- 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);
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
- 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
- }
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
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
527
- finally {
344
+ for (const generated of Object.values(generatedServices)
345
+ .sort((a, b) => a.className.localeCompare(b.className))) {
528
346
  try {
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");
542
- }
543
- if (generated.deprecatedNotice) {
544
- serviceOutput.write(" * @deprecated " + generated.deprecatedNotice + "\n");
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
- 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
- }
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
- 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);
574
- }
575
- finally { if (e_20) throw e_20.error; }
372
+ else {
373
+ serviceOutput.write(" this.addCharacteristic(Characteristic." + characteristic.className + ");\n");
576
374
  }
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; }
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
- catch (error) {
609
- throw new Error("Error thrown writing service '" + generated.id + "' (" + generated.className + "): " + error.message);
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
- 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);
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
- 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
- });
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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);
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
- var result = perms.join(", ");
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
- var content = fs_1.default.readFileSync(filePath, { encoding: "utf8" }).split("\n", 3);
748
- var v = content[1];
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
- var version = parseInt(v.replace("// V=", ""), 10);
485
+ const version = parseInt(v.replace("// V=", ""), 10);
753
486
  return parsingVersion >= version;
754
487
  }
755
488
  function rewriteProperties(className, properties) {
756
- var filePath = path_1.default.resolve(__dirname, "../" + className + ".ts");
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
- 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;
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
- var line = lines[i];
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
- var startIndex = -1;
781
- var stopIndex = -1;
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
- 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;
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
- 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;
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.apply(lines, tslib_1.__spreadArray([startIndex + 1, amount], tslib_1.__read(newContentLines), false)); // insert new lines
833
- var resultContent = lines.join("\n");
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
- 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" });
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
- 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);
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
- finally { if (e_26) throw e_26.error; }
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
- 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" });
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
- 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);
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
- finally { if (e_27) throw e_27.error; }
616
+ testOutput.write(" });\n");
617
+ testOutput.write(" });\n");
914
618
  }
915
619
  testOutput.write("});\n");
916
620
  testOutput.end();