@homebridge/hap-nodejs 2.2.4-beta.7 → 2.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -17
- package/dist/accessories/AirConditioner_accessory.js +27 -29
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +63 -76
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +151 -134
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +18 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +33 -35
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +41 -44
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +32 -34
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +24 -26
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +13 -15
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +20 -22
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +18 -20
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +36 -38
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +43 -45
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +12 -14
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +9 -12
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +11 -14
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +3 -3
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +38 -38
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.d.ts +63 -63
- package/dist/accessories/types.d.ts.map +1 -1
- package/dist/accessories/types.js +83 -87
- package/dist/accessories/types.js.map +1 -1
- package/dist/hap.d.ts +50 -0
- package/dist/hap.d.ts.map +1 -0
- package/dist/hap.js +49 -0
- package/dist/hap.js.map +1 -0
- package/dist/index.d.ts +3 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -53
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +1 -1
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +19 -19
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +37 -37
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +286 -280
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +6 -6
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +143 -139
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +2 -6
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +40 -41
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +290 -240
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +31 -30
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +245 -247
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +21 -22
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +60 -68
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +2 -1
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +35 -37
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +34 -33
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +184 -137
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +18 -17
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +189 -164
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +3 -3
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +3 -6
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +8 -8
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +112 -99
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +21 -20
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +92 -89
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +1 -1
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js +5 -8
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +4 -4
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +9 -13
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +40 -39
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +213 -186
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +5 -5
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/index.js +5 -8
- package/dist/lib/controller/index.js.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts +2 -2
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +36 -35
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +1 -0
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +53 -69
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +24 -23
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +151 -154
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/datastream/index.d.ts.map +1 -1
- package/dist/lib/datastream/index.js +3 -6
- package/dist/lib/datastream/index.js.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +1103 -1288
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +644 -722
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts +2 -2
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +241 -241
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +572 -309
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.d.ts +2 -2
- package/dist/lib/definitions/index.d.ts.map +1 -1
- package/dist/lib/definitions/index.js +2 -5
- package/dist/lib/definitions/index.js.map +1 -1
- package/dist/lib/gen/HomeKit.js +1 -2
- package/dist/lib/gen/HomeKit.js.map +1 -1
- package/dist/lib/model/AccessoryInfo.d.ts +4 -3
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +53 -56
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +3 -3
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +31 -30
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPFileStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPFileStorage.js +71 -50
- package/dist/lib/model/HAPFileStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +1 -1
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +11 -14
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +1 -1
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +23 -27
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +6 -6
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +23 -24
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -2
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +8 -14
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.d.ts.map +1 -1
- package/dist/lib/util/clone.js +1 -5
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +1 -1
- package/dist/lib/util/color-utils.d.ts.map +1 -1
- package/dist/lib/util/color-utils.js +1608 -410
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +23 -22
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +127 -122
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +2 -1
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +72 -59
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +1 -1
- package/dist/lib/util/hapStatusError.d.ts.map +1 -1
- package/dist/lib/util/hapStatusError.js +5 -9
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +13 -19
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -6
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +1 -1
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +9 -11
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.d.ts +3 -3
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +14 -23
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +1 -0
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +6 -11
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +1 -0
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +38 -44
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +1 -0
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +26 -38
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +24 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/package.json +49 -42
|
@@ -1,43 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const Characteristic_1 = require("../Characteristic");
|
|
12
|
-
const uuid_1 = require("../util/uuid");
|
|
13
|
-
const generator_configuration_1 = require("./generator-configuration");
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import * as plist from 'simple-plist';
|
|
7
|
+
import { Characteristic } from '../Characteristic.js';
|
|
8
|
+
import { toLongForm } from '../util/uuid.js';
|
|
9
|
+
import { CharacteristicClassAdditions, CharacteristicDeprecatedNames, CharacteristicHidden, CharacteristicManualAdditions, CharacteristicNameOverrides, CharacteristicOverriding, CharacteristicSinceInformation, CharacteristicValidValuesOverride, ServiceCharacteristicConfigurationOverrides, ServiceDeprecatedNames, ServiceManualAdditions, ServiceNameOverrides, ServiceSinceInformation, } from './generator-configuration.js';
|
|
10
|
+
import './CharacteristicDefinitions.js';
|
|
14
11
|
// noinspection JSUnusedLocalSymbols
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
const temp =
|
|
17
|
-
const command = new
|
|
18
|
-
.version(
|
|
19
|
-
.option(
|
|
20
|
-
.option(
|
|
21
|
-
.requiredOption(
|
|
12
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
13
|
+
const temp = Characteristic; // this to have "../Characteristic" not being only type import, otherwise this would not result in a require statement
|
|
14
|
+
const command = new Command('generate-definitions')
|
|
15
|
+
.version('1.0.0')
|
|
16
|
+
.option('-f, --force')
|
|
17
|
+
.option('-m, --metadata <path>', 'Define a custom location for the plain-metadata.config file', '/System/Library/PrivateFrameworks/HomeKitDaemon.framework/Resources/plain-metadata.config')
|
|
18
|
+
.requiredOption('-s, --simulator <path>', 'Define the path to the accessory simulator.');
|
|
22
19
|
command.parse(process.argv);
|
|
23
20
|
const options = command.opts();
|
|
24
21
|
const metadataFile = options.metadata;
|
|
25
22
|
const simulator = options.simulator;
|
|
26
|
-
if (!
|
|
23
|
+
if (!fs.existsSync(metadataFile)) {
|
|
27
24
|
console.warn(`The metadata file at '${metadataFile}' does not exist!`);
|
|
28
25
|
process.exit(1);
|
|
29
26
|
}
|
|
30
|
-
if (!
|
|
27
|
+
if (!fs.existsSync(simulator)) {
|
|
31
28
|
console.warn(`The simulator app directory '${simulator}' does not exist!`);
|
|
32
29
|
process.exit(1);
|
|
33
30
|
}
|
|
34
|
-
const defaultPlist =
|
|
35
|
-
const defaultMfiPlist =
|
|
36
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
31
|
+
const defaultPlist = path.resolve(simulator, 'Contents/Frameworks/HAPAccessoryKit.framework/Resources/default.metadata.plist');
|
|
32
|
+
const defaultMfiPlist = path.resolve(simulator, 'Contents/Frameworks/HAPAccessoryKit.framework/Resources/default_mfi.metadata.plist');
|
|
37
33
|
const plistData = plist.readFileSync(metadataFile);
|
|
38
34
|
const simulatorPlistData = plist.readFileSync(defaultPlist);
|
|
39
|
-
const simulatorMfiPlistData =
|
|
40
|
-
|
|
35
|
+
const simulatorMfiPlistData = fs.existsSync(defaultMfiPlist)
|
|
36
|
+
? plist.readFileSync(defaultMfiPlist)
|
|
37
|
+
: undefined;
|
|
41
38
|
if (plistData.SchemaVersion !== 1) {
|
|
42
39
|
console.warn(`Detected unsupported schema version ${plistData.SchemaVersion}!`);
|
|
43
40
|
}
|
|
@@ -45,14 +42,14 @@ if (plistData.PlistDictionary.SchemaVersion !== 1) {
|
|
|
45
42
|
console.warn(`Detect unsupported PlistDictionary schema version ${plistData.PlistDictionary.SchemaVersion}!`);
|
|
46
43
|
}
|
|
47
44
|
console.log(`Parsing version ${plistData.Version}...`);
|
|
48
|
-
const shouldParseCharacteristics = checkWrittenVersion(
|
|
49
|
-
const shouldParseServices = checkWrittenVersion(
|
|
45
|
+
const shouldParseCharacteristics = checkWrittenVersion('./CharacteristicDefinitions.ts', plistData.Version);
|
|
46
|
+
const shouldParseServices = checkWrittenVersion('./ServiceDefinitions.ts', plistData.Version);
|
|
50
47
|
if (!options.force && (!shouldParseCharacteristics || !shouldParseServices)) {
|
|
51
|
-
console.log(
|
|
52
|
-
|
|
48
|
+
console.log(`Parsed schema version ${plistData.Version} is older than what's already generated. `
|
|
49
|
+
+ 'User --force option to generate and overwrite nonetheless!');
|
|
53
50
|
process.exit(1);
|
|
54
51
|
}
|
|
55
|
-
const undefinedUnits = [
|
|
52
|
+
const undefinedUnits = ['micrograms/m^3', 'ppm'];
|
|
56
53
|
let characteristics;
|
|
57
54
|
const simulatorCharacteristics = new Map();
|
|
58
55
|
let services;
|
|
@@ -62,7 +59,7 @@ const properties = new Map();
|
|
|
62
59
|
try {
|
|
63
60
|
characteristics = checkDefined(plistData.PlistDictionary.HAP.Characteristics);
|
|
64
61
|
services = checkDefined(plistData.PlistDictionary.HAP.Services);
|
|
65
|
-
// eslint-disable-next-line
|
|
62
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
66
63
|
units = checkDefined(plistData.PlistDictionary.HAP.Units);
|
|
67
64
|
categories = checkDefined(plistData.PlistDictionary.HomeKit.Categories);
|
|
68
65
|
const props = checkDefined(plistData.PlistDictionary.HAP.Properties);
|
|
@@ -84,7 +81,7 @@ try {
|
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
83
|
catch (error) {
|
|
87
|
-
console.log(
|
|
84
|
+
console.log('Unexpected structure of the plist file!');
|
|
88
85
|
throw error;
|
|
89
86
|
}
|
|
90
87
|
// first step is to check if we are up to date on categories
|
|
@@ -93,11 +90,11 @@ for (const definition of Object.values(categories)) {
|
|
|
93
90
|
console.log(`Detected a new category '${definition.DefaultDescription}' with id ${definition.Identifier}`);
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
|
-
const characteristicOutput =
|
|
97
|
-
characteristicOutput.write(
|
|
93
|
+
const characteristicOutput = fs.createWriteStream(path.join(import.meta.dirname, 'CharacteristicDefinitions.ts'));
|
|
94
|
+
characteristicOutput.write('// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n');
|
|
98
95
|
characteristicOutput.write(`// V=${plistData.Version}\n`);
|
|
99
|
-
characteristicOutput.write(
|
|
100
|
-
characteristicOutput.write(
|
|
96
|
+
characteristicOutput.write('\n');
|
|
97
|
+
characteristicOutput.write('import { Access, Characteristic, Formats, Perms, Units } from "../Characteristic";\n\n');
|
|
101
98
|
/**
|
|
102
99
|
* Characteristics
|
|
103
100
|
*/
|
|
@@ -105,51 +102,51 @@ const generatedCharacteristics = {}; // indexed by id
|
|
|
105
102
|
const writtenCharacteristicEntries = {}; // indexed by class name
|
|
106
103
|
for (const [id, definition] of Object.entries(characteristics)) {
|
|
107
104
|
try {
|
|
108
|
-
if (
|
|
105
|
+
if (CharacteristicHidden.has(id)) {
|
|
109
106
|
continue;
|
|
110
107
|
}
|
|
111
108
|
// "Carbon dioxide Detected" -> "Carbon Dioxide Detected"
|
|
112
|
-
const name = (
|
|
113
|
-
?? definition.DefaultDescription).split(
|
|
114
|
-
const deprecatedName =
|
|
109
|
+
const name = (CharacteristicNameOverrides.get(id)
|
|
110
|
+
?? definition.DefaultDescription).split(' ').map(entry => entry[0].toUpperCase() + entry.slice(1)).join(' ');
|
|
111
|
+
const deprecatedName = CharacteristicDeprecatedNames.get(id);
|
|
115
112
|
// "Target Door State" -> "TargetDoorState", "PM2.5" -> "PM2_5"
|
|
116
|
-
const className = name.replace(/[\s-]/g,
|
|
117
|
-
const deprecatedClassName = deprecatedName?.replace(/[\s-]/g,
|
|
118
|
-
const longUUID =
|
|
113
|
+
const className = name.replace(/[\s-]/g, '').replace(/\./g, '_');
|
|
114
|
+
const deprecatedClassName = deprecatedName?.replace(/[\s-]/g, '').replace(/\./g, '_');
|
|
115
|
+
const longUUID = toLongForm(definition.ShortUUID);
|
|
119
116
|
const simulatorCharacteristic = simulatorCharacteristics.get(longUUID);
|
|
120
117
|
const validValues = simulatorCharacteristic?.Constraints?.ValidValues || {};
|
|
121
|
-
const validValuesOverride =
|
|
118
|
+
const validValuesOverride = CharacteristicValidValuesOverride.get(id);
|
|
122
119
|
if (validValuesOverride) {
|
|
123
120
|
for (const [key, value] of Object.entries(validValuesOverride)) {
|
|
124
121
|
validValues[key] = value;
|
|
125
122
|
}
|
|
126
123
|
}
|
|
127
124
|
for (const [value, name] of Object.entries(validValues)) {
|
|
128
|
-
let constName = name.toUpperCase().replace(
|
|
125
|
+
let constName = name.toUpperCase().replace(/\W+/g, '_');
|
|
129
126
|
if (/^[1-9]/.test(constName)) {
|
|
130
|
-
constName =
|
|
127
|
+
constName = `_${constName}`; // variables can't start with a number
|
|
131
128
|
}
|
|
132
129
|
validValues[value] = constName;
|
|
133
130
|
}
|
|
134
131
|
const validBits = simulatorCharacteristic?.Constraints?.ValidBits;
|
|
135
|
-
let validBitMasks
|
|
132
|
+
let validBitMasks;
|
|
136
133
|
if (validBits) {
|
|
137
134
|
validBitMasks = {};
|
|
138
135
|
for (const [value, name] of Object.entries(validBits)) {
|
|
139
|
-
let constName = name.toUpperCase().replace(
|
|
136
|
+
let constName = name.toUpperCase().replace(/\W+/g, '_');
|
|
140
137
|
if (/^[1-9]/.test(constName)) {
|
|
141
|
-
constName =
|
|
138
|
+
constName = `_${constName}`; // variables can't start with a number
|
|
142
139
|
}
|
|
143
|
-
validBitMasks[
|
|
140
|
+
validBitMasks[`${1 << parseInt(value, 10)}`] = `${constName}_BIT_MASK`;
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
143
|
const generatedCharacteristic = {
|
|
147
|
-
id
|
|
144
|
+
id,
|
|
148
145
|
UUID: longUUID,
|
|
149
|
-
name
|
|
150
|
-
className
|
|
151
|
-
deprecatedClassName
|
|
152
|
-
since:
|
|
146
|
+
name,
|
|
147
|
+
className,
|
|
148
|
+
deprecatedClassName,
|
|
149
|
+
since: CharacteristicSinceInformation.get(id),
|
|
153
150
|
format: definition.Format,
|
|
154
151
|
units: definition.Units,
|
|
155
152
|
properties: definition.Properties,
|
|
@@ -157,12 +154,12 @@ for (const [id, definition] of Object.entries(characteristics)) {
|
|
|
157
154
|
maxValue: definition.MaxValue,
|
|
158
155
|
stepValue: definition.StepValue,
|
|
159
156
|
maxLength: definition.MaxLength,
|
|
160
|
-
validValues
|
|
161
|
-
validBitMasks
|
|
162
|
-
classAdditions:
|
|
157
|
+
validValues,
|
|
158
|
+
validBitMasks,
|
|
159
|
+
classAdditions: CharacteristicClassAdditions.get(id),
|
|
163
160
|
};
|
|
164
161
|
// call any handler which wants to manually override properties of the generated characteristic
|
|
165
|
-
|
|
162
|
+
CharacteristicOverriding.get(id)?.(generatedCharacteristic);
|
|
166
163
|
generatedCharacteristics[id] = generatedCharacteristic;
|
|
167
164
|
writtenCharacteristicEntries[className] = generatedCharacteristic;
|
|
168
165
|
if (deprecatedClassName) {
|
|
@@ -170,10 +167,10 @@ for (const [id, definition] of Object.entries(characteristics)) {
|
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
catch (error) {
|
|
173
|
-
throw new Error(
|
|
170
|
+
throw new Error(`Error thrown generating characteristic '${id}' (${definition.DefaultDescription}): ${error.message}`, { cause: error });
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
|
-
for (const [id, generated] of
|
|
173
|
+
for (const [id, generated] of CharacteristicManualAdditions) {
|
|
177
174
|
generatedCharacteristics[id] = generated;
|
|
178
175
|
writtenCharacteristicEntries[generated.className] = generated;
|
|
179
176
|
if (generated.deprecatedClassName) {
|
|
@@ -183,20 +180,20 @@ for (const [id, generated] of generator_configuration_1.CharacteristicManualAddi
|
|
|
183
180
|
for (const generated of Object.values(generatedCharacteristics)
|
|
184
181
|
.sort((a, b) => a.className.localeCompare(b.className))) {
|
|
185
182
|
try {
|
|
186
|
-
characteristicOutput.write(
|
|
187
|
-
characteristicOutput.write(
|
|
183
|
+
characteristicOutput.write('/**\n');
|
|
184
|
+
characteristicOutput.write(` * Characteristic "${generated.name}"\n`);
|
|
188
185
|
if (generated.since) {
|
|
189
|
-
characteristicOutput.write(
|
|
186
|
+
characteristicOutput.write(` * @since iOS ${generated.since}\n`);
|
|
190
187
|
}
|
|
191
188
|
if (generated.deprecatedNotice) {
|
|
192
|
-
characteristicOutput.write(
|
|
189
|
+
characteristicOutput.write(` * @deprecated ${generated.deprecatedNotice}\n`);
|
|
193
190
|
}
|
|
194
|
-
characteristicOutput.write(
|
|
195
|
-
characteristicOutput.write(
|
|
196
|
-
characteristicOutput.write(
|
|
191
|
+
characteristicOutput.write(' */\n');
|
|
192
|
+
characteristicOutput.write(`export class ${generated.className} extends Characteristic {\n\n`);
|
|
193
|
+
characteristicOutput.write(` public static readonly UUID: string = "${generated.UUID}";\n\n`);
|
|
197
194
|
const classAdditions = generated.classAdditions;
|
|
198
195
|
if (classAdditions) {
|
|
199
|
-
characteristicOutput.write(classAdditions.map(line =>
|
|
196
|
+
characteristicOutput.write(`${classAdditions.map(line => ` ${line}\n`).join('')}\n`);
|
|
200
197
|
}
|
|
201
198
|
const validValuesEntries = Object.entries(generated.validValues ?? {});
|
|
202
199
|
if (validValuesEntries.length) {
|
|
@@ -204,86 +201,85 @@ for (const generated of Object.values(generatedCharacteristics)
|
|
|
204
201
|
if (!name) {
|
|
205
202
|
continue;
|
|
206
203
|
}
|
|
207
|
-
const cleanName = name.replace(/_+$/,
|
|
204
|
+
const cleanName = name.replace(/_+$/, ''); // remove any underscores at the end of the name
|
|
208
205
|
characteristicOutput.write(` public static readonly ${cleanName} = ${value};\n`);
|
|
209
206
|
}
|
|
210
|
-
characteristicOutput.write(
|
|
207
|
+
characteristicOutput.write('\n');
|
|
211
208
|
}
|
|
212
209
|
if (generated.validBitMasks) {
|
|
213
210
|
for (const [value, name] of Object.entries(generated.validBitMasks)) {
|
|
214
211
|
characteristicOutput.write(` public static readonly ${name} = ${value};\n`);
|
|
215
212
|
}
|
|
216
|
-
characteristicOutput.write(
|
|
213
|
+
characteristicOutput.write('\n');
|
|
217
214
|
}
|
|
218
|
-
characteristicOutput.write(
|
|
219
|
-
characteristicOutput.write(
|
|
220
|
-
characteristicOutput.write(
|
|
221
|
-
characteristicOutput.write(
|
|
215
|
+
characteristicOutput.write(' constructor() {\n');
|
|
216
|
+
characteristicOutput.write(` super("${generated.name}", ${generated.className}.UUID, {\n`);
|
|
217
|
+
characteristicOutput.write(` format: Formats.${characteristicFormat(generated.format)},\n`);
|
|
218
|
+
characteristicOutput.write(` perms: [${generatePermsString(generated.id, generated.properties)}],\n`);
|
|
222
219
|
if (generated.units && !undefinedUnits.includes(generated.units)) {
|
|
223
|
-
characteristicOutput.write(
|
|
220
|
+
characteristicOutput.write(` unit: Units.${characteristicUnit(generated.units)},\n`);
|
|
224
221
|
}
|
|
225
222
|
if (generated.minValue != null) {
|
|
226
|
-
characteristicOutput.write(
|
|
223
|
+
characteristicOutput.write(` minValue: ${generated.minValue},\n`);
|
|
227
224
|
}
|
|
228
225
|
if (generated.maxValue != null) {
|
|
229
|
-
characteristicOutput.write(
|
|
226
|
+
characteristicOutput.write(` maxValue: ${generated.maxValue},\n`);
|
|
230
227
|
}
|
|
231
228
|
if (generated.stepValue != null) {
|
|
232
|
-
characteristicOutput.write(
|
|
229
|
+
characteristicOutput.write(` minStep: ${generated.stepValue},\n`);
|
|
233
230
|
}
|
|
234
231
|
if (generated.maxLength != null) {
|
|
235
|
-
characteristicOutput.write(
|
|
232
|
+
characteristicOutput.write(` maxLen: ${generated.maxLength},\n`);
|
|
236
233
|
}
|
|
237
234
|
if (validValuesEntries.length) {
|
|
238
|
-
characteristicOutput.write(
|
|
235
|
+
characteristicOutput.write(` validValues: [${Object.keys(generated.validValues).join(', ')}],\n`);
|
|
239
236
|
}
|
|
240
237
|
if (generated.adminOnlyAccess) {
|
|
241
|
-
characteristicOutput.write(
|
|
242
|
-
+ generated.adminOnlyAccess.map(value => "Access." + characteristicAccess(value)).join(", ") + "],\n");
|
|
238
|
+
characteristicOutput.write(` adminOnlyAccess: [${generated.adminOnlyAccess.map(value => `Access.${characteristicAccess(value)}`).join(', ')}],\n`);
|
|
243
239
|
}
|
|
244
|
-
characteristicOutput.write(
|
|
245
|
-
characteristicOutput.write(
|
|
246
|
-
characteristicOutput.write(
|
|
247
|
-
characteristicOutput.write(
|
|
240
|
+
characteristicOutput.write(' });\n');
|
|
241
|
+
characteristicOutput.write(' this.value = this.getDefaultValue();\n');
|
|
242
|
+
characteristicOutput.write(' }\n');
|
|
243
|
+
characteristicOutput.write('}\n');
|
|
248
244
|
if (generated.deprecatedClassName) {
|
|
249
|
-
characteristicOutput.write(
|
|
250
|
-
characteristicOutput.write(
|
|
245
|
+
characteristicOutput.write('// noinspection JSDeprecatedSymbols\n');
|
|
246
|
+
characteristicOutput.write(`Characteristic.${generated.deprecatedClassName} = ${generated.className};\n`);
|
|
251
247
|
}
|
|
252
248
|
if (generated.deprecatedNotice) {
|
|
253
|
-
characteristicOutput.write(
|
|
249
|
+
characteristicOutput.write('// noinspection JSDeprecatedSymbols\n');
|
|
254
250
|
}
|
|
255
|
-
characteristicOutput.write(
|
|
251
|
+
characteristicOutput.write(`Characteristic.${generated.className} = ${generated.className};\n\n`);
|
|
256
252
|
}
|
|
257
253
|
catch (error) {
|
|
258
|
-
throw new Error(
|
|
254
|
+
throw new Error(`Error thrown writing characteristic '${generated.id}' (${generated.className}): ${error.message}`, { cause: error });
|
|
259
255
|
}
|
|
260
256
|
}
|
|
261
257
|
characteristicOutput.end();
|
|
262
258
|
const characteristicProperties = Object.entries(writtenCharacteristicEntries).sort(([a], [b]) => a.localeCompare(b));
|
|
263
|
-
rewriteProperties(
|
|
259
|
+
rewriteProperties('Characteristic', characteristicProperties);
|
|
264
260
|
writeCharacteristicTestFile();
|
|
265
261
|
/**
|
|
266
262
|
* Services
|
|
267
263
|
*/
|
|
268
|
-
const serviceOutput =
|
|
269
|
-
serviceOutput.write(
|
|
264
|
+
const serviceOutput = fs.createWriteStream(path.join(import.meta.dirname, 'ServiceDefinitions.ts'));
|
|
265
|
+
serviceOutput.write('// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n');
|
|
270
266
|
serviceOutput.write(`// V=${plistData.Version}\n`);
|
|
271
|
-
serviceOutput.write(
|
|
272
|
-
serviceOutput.write(
|
|
273
|
-
serviceOutput.write(
|
|
267
|
+
serviceOutput.write('\n');
|
|
268
|
+
serviceOutput.write('import { Characteristic } from "../Characteristic";\n');
|
|
269
|
+
serviceOutput.write('import { Service } from "../Service";\n\n');
|
|
274
270
|
const generatedServices = {}; // indexed by id
|
|
275
271
|
const writtenServiceEntries = {}; // indexed by class name
|
|
276
272
|
for (const [id, definition] of Object.entries(services)) {
|
|
277
273
|
try {
|
|
278
274
|
// "Carbon dioxide Sensor" -> "Carbon Dioxide Sensor"
|
|
279
|
-
const name = (
|
|
280
|
-
const deprecatedName =
|
|
281
|
-
const className = name.replace(/[\s-]/g,
|
|
282
|
-
const deprecatedClassName = deprecatedName?.replace(/[\s-]/g,
|
|
283
|
-
const longUUID =
|
|
275
|
+
const name = (ServiceNameOverrides.get(id) ?? definition.DefaultDescription).split(' ').map(entry => entry[0].toUpperCase() + entry.slice(1)).join(' ');
|
|
276
|
+
const deprecatedName = ServiceDeprecatedNames.get(id);
|
|
277
|
+
const className = name.replace(/[\s-]/g, '').replace(/\./g, '_');
|
|
278
|
+
const deprecatedClassName = deprecatedName?.replace(/[\s-]/g, '').replace(/\./g, '_');
|
|
279
|
+
const longUUID = toLongForm(definition.ShortUUID);
|
|
284
280
|
const requiredCharacteristics = definition.Characteristics.Required;
|
|
285
281
|
const optionalCharacteristics = definition.Characteristics.Optional;
|
|
286
|
-
const configurationOverride =
|
|
282
|
+
const configurationOverride = ServiceCharacteristicConfigurationOverrides.get(id);
|
|
287
283
|
if (configurationOverride) {
|
|
288
284
|
if (configurationOverride.removedRequired) {
|
|
289
285
|
for (const entry of configurationOverride.removedRequired) {
|
|
@@ -317,14 +313,14 @@ for (const [id, definition] of Object.entries(services)) {
|
|
|
317
313
|
}
|
|
318
314
|
}
|
|
319
315
|
const generatedService = {
|
|
320
|
-
id
|
|
316
|
+
id,
|
|
321
317
|
UUID: longUUID,
|
|
322
|
-
name
|
|
323
|
-
className
|
|
324
|
-
deprecatedClassName
|
|
325
|
-
since:
|
|
326
|
-
requiredCharacteristics
|
|
327
|
-
optionalCharacteristics
|
|
318
|
+
name,
|
|
319
|
+
className,
|
|
320
|
+
deprecatedClassName,
|
|
321
|
+
since: ServiceSinceInformation.get(id),
|
|
322
|
+
requiredCharacteristics,
|
|
323
|
+
optionalCharacteristics,
|
|
328
324
|
};
|
|
329
325
|
generatedServices[id] = generatedService;
|
|
330
326
|
writtenServiceEntries[className] = generatedService;
|
|
@@ -333,10 +329,10 @@ for (const [id, definition] of Object.entries(services)) {
|
|
|
333
329
|
}
|
|
334
330
|
}
|
|
335
331
|
catch (error) {
|
|
336
|
-
throw new Error(
|
|
332
|
+
throw new Error(`Error thrown generating service '${id}' (${definition.DefaultDescription}): ${error.message}`, { cause: error });
|
|
337
333
|
}
|
|
338
334
|
}
|
|
339
|
-
for (const [id, generated] of
|
|
335
|
+
for (const [id, generated] of ServiceManualAdditions) {
|
|
340
336
|
generatedServices[id] = generated;
|
|
341
337
|
writtenServiceEntries[generated.className] = generated;
|
|
342
338
|
if (generated.deprecatedClassName) {
|
|
@@ -346,279 +342,283 @@ for (const [id, generated] of generator_configuration_1.ServiceManualAdditions)
|
|
|
346
342
|
for (const generated of Object.values(generatedServices)
|
|
347
343
|
.sort((a, b) => a.className.localeCompare(b.className))) {
|
|
348
344
|
try {
|
|
349
|
-
serviceOutput.write(
|
|
350
|
-
serviceOutput.write(
|
|
345
|
+
serviceOutput.write('/**\n');
|
|
346
|
+
serviceOutput.write(` * Service "${generated.name}"\n`);
|
|
351
347
|
if (generated.since) {
|
|
352
|
-
serviceOutput.write(
|
|
348
|
+
serviceOutput.write(` * @since iOS ${generated.since}\n`);
|
|
353
349
|
}
|
|
354
350
|
if (generated.deprecatedNotice) {
|
|
355
|
-
serviceOutput.write(
|
|
356
|
-
}
|
|
357
|
-
serviceOutput.write(
|
|
358
|
-
serviceOutput.write(
|
|
359
|
-
serviceOutput.write(
|
|
360
|
-
serviceOutput.write(
|
|
361
|
-
serviceOutput.write(
|
|
362
|
-
serviceOutput.write(
|
|
351
|
+
serviceOutput.write(` * @deprecated ${generated.deprecatedNotice}\n`);
|
|
352
|
+
}
|
|
353
|
+
serviceOutput.write(' */\n');
|
|
354
|
+
serviceOutput.write(`export class ${generated.className} extends Service {\n\n`);
|
|
355
|
+
serviceOutput.write(` public static readonly UUID: string = "${generated.UUID}";\n\n`);
|
|
356
|
+
serviceOutput.write(' constructor(displayName?: string, subtype?: string) {\n');
|
|
357
|
+
serviceOutput.write(` super(displayName, ${generated.className}.UUID, subtype);\n\n`);
|
|
358
|
+
serviceOutput.write(' // Required Characteristics\n');
|
|
363
359
|
for (const required of generated.requiredCharacteristics) {
|
|
364
360
|
const characteristic = generatedCharacteristics[required];
|
|
365
361
|
if (!characteristic) {
|
|
366
|
-
console.warn(
|
|
362
|
+
console.warn(`Could not find required characteristic ${required} for ${generated.className}`);
|
|
367
363
|
continue;
|
|
368
364
|
}
|
|
369
|
-
if (required ===
|
|
370
|
-
serviceOutput.write(
|
|
371
|
-
serviceOutput.write(
|
|
372
|
-
serviceOutput.write(
|
|
365
|
+
if (required === 'name') {
|
|
366
|
+
serviceOutput.write(' if (!this.testCharacteristic(Characteristic.Name)) { // workaround for Name characteristic collision in constructor\n');
|
|
367
|
+
serviceOutput.write(' this.addCharacteristic(Characteristic.Name).updateValue("Unnamed Service");\n');
|
|
368
|
+
serviceOutput.write(' }\n');
|
|
373
369
|
}
|
|
374
370
|
else {
|
|
375
|
-
serviceOutput.write(
|
|
371
|
+
serviceOutput.write(` this.addCharacteristic(Characteristic.${characteristic.className});\n`);
|
|
376
372
|
}
|
|
377
373
|
}
|
|
378
374
|
if (generated.optionalCharacteristics?.length) {
|
|
379
|
-
serviceOutput.write(
|
|
375
|
+
serviceOutput.write('\n // Optional Characteristics\n');
|
|
380
376
|
for (const optional of generated.optionalCharacteristics) {
|
|
381
377
|
const characteristic = generatedCharacteristics[optional];
|
|
382
378
|
if (!characteristic) {
|
|
383
|
-
console.warn(
|
|
379
|
+
console.warn(`Could not find optional characteristic ${optional} for ${generated.className}`);
|
|
384
380
|
continue;
|
|
385
381
|
}
|
|
386
|
-
serviceOutput.write(
|
|
382
|
+
serviceOutput.write(` this.addOptionalCharacteristic(Characteristic.${characteristic.className});\n`);
|
|
387
383
|
}
|
|
388
384
|
}
|
|
389
|
-
serviceOutput.write(
|
|
385
|
+
serviceOutput.write(' }\n}\n');
|
|
390
386
|
if (generated.deprecatedClassName) {
|
|
391
|
-
serviceOutput.write(
|
|
392
|
-
serviceOutput.write(
|
|
387
|
+
serviceOutput.write('// noinspection JSDeprecatedSymbols\n');
|
|
388
|
+
serviceOutput.write(`Service.${generated.deprecatedClassName} = ${generated.className};\n`);
|
|
393
389
|
}
|
|
394
390
|
if (generated.deprecatedNotice) {
|
|
395
|
-
serviceOutput.write(
|
|
391
|
+
serviceOutput.write('// noinspection JSDeprecatedSymbols\n');
|
|
396
392
|
}
|
|
397
|
-
serviceOutput.write(
|
|
393
|
+
serviceOutput.write(`Service.${generated.className} = ${generated.className};\n\n`);
|
|
398
394
|
}
|
|
399
395
|
catch (error) {
|
|
400
|
-
throw new Error(
|
|
396
|
+
throw new Error(`Error thrown writing service '${generated.id}' (${generated.className}): ${error.message}`, { cause: error });
|
|
401
397
|
}
|
|
402
398
|
}
|
|
403
399
|
serviceOutput.end();
|
|
404
400
|
const serviceProperties = Object.entries(writtenServiceEntries).sort(([a], [b]) => a.localeCompare(b));
|
|
405
|
-
rewriteProperties(
|
|
401
|
+
rewriteProperties('Service', serviceProperties);
|
|
406
402
|
writeServicesTestFile();
|
|
407
403
|
// ------------------------ utils ------------------------
|
|
408
404
|
function checkDefined(input) {
|
|
409
405
|
if (!input) {
|
|
410
|
-
throw new Error(
|
|
406
|
+
throw new Error('value is undefined!');
|
|
411
407
|
}
|
|
412
408
|
return input;
|
|
413
409
|
}
|
|
414
410
|
function characteristicFormat(format) {
|
|
415
411
|
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
416
|
-
for (const [key, value] of Object.entries(
|
|
412
|
+
for (const [key, value] of Object.entries(Formats)) {
|
|
417
413
|
if (value === format) {
|
|
418
414
|
return key;
|
|
419
415
|
}
|
|
420
416
|
}
|
|
421
|
-
throw new Error(
|
|
417
|
+
throw new Error(`Unknown characteristic format '${format}'`);
|
|
422
418
|
}
|
|
423
419
|
function characteristicUnit(unit) {
|
|
424
420
|
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
425
|
-
for (const [key, value] of Object.entries(
|
|
421
|
+
for (const [key, value] of Object.entries(Units)) {
|
|
426
422
|
if (value === unit) {
|
|
427
423
|
return key;
|
|
428
424
|
}
|
|
429
425
|
}
|
|
430
|
-
throw new Error(
|
|
426
|
+
throw new Error(`Unknown characteristic format '${unit}'`);
|
|
431
427
|
}
|
|
432
428
|
function characteristicAccess(access) {
|
|
433
429
|
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
434
|
-
for (const [key, value] of Object.entries(
|
|
430
|
+
for (const [key, value] of Object.entries(Access)) {
|
|
435
431
|
if (value === access) {
|
|
436
432
|
return key;
|
|
437
433
|
}
|
|
438
434
|
}
|
|
439
|
-
throw new Error(
|
|
435
|
+
throw new Error(`Unknown access for '${access}'`);
|
|
440
436
|
}
|
|
441
437
|
function characteristicPerm(id) {
|
|
442
438
|
switch (id) {
|
|
443
|
-
case
|
|
444
|
-
return
|
|
445
|
-
case
|
|
446
|
-
return
|
|
447
|
-
case
|
|
448
|
-
return
|
|
449
|
-
case
|
|
450
|
-
return
|
|
451
|
-
case
|
|
452
|
-
return
|
|
453
|
-
case
|
|
454
|
-
return
|
|
455
|
-
case
|
|
456
|
-
return
|
|
457
|
-
case
|
|
439
|
+
case 'aa':
|
|
440
|
+
return 'ADDITIONAL_AUTHORIZATION';
|
|
441
|
+
case 'hidden':
|
|
442
|
+
return 'HIDDEN';
|
|
443
|
+
case 'notify':
|
|
444
|
+
return 'NOTIFY';
|
|
445
|
+
case 'read':
|
|
446
|
+
return 'PAIRED_READ';
|
|
447
|
+
case 'timedWrite':
|
|
448
|
+
return 'TIMED_WRITE';
|
|
449
|
+
case 'write':
|
|
450
|
+
return 'PAIRED_WRITE';
|
|
451
|
+
case 'writeResponse':
|
|
452
|
+
return 'WRITE_RESPONSE';
|
|
453
|
+
case 'broadcast': // used for bluetooth
|
|
458
454
|
return undefined;
|
|
459
|
-
case
|
|
455
|
+
case 'adminOnly':
|
|
460
456
|
return undefined; // TODO add support for it (currently unused though)
|
|
461
457
|
default:
|
|
462
|
-
throw new Error(
|
|
458
|
+
throw new Error(`Received unknown perms id: ${id}`);
|
|
463
459
|
}
|
|
464
460
|
}
|
|
465
461
|
function generatePermsString(id, propertiesBitMap) {
|
|
466
462
|
const perms = [];
|
|
467
463
|
for (const [bitMap, name] of properties) {
|
|
468
|
-
if (name ===
|
|
464
|
+
if (name === 'ADDITIONAL_AUTHORIZATION') {
|
|
469
465
|
// aa set by homed just signals that aa may be supported. Setting up aa will always require a custom made app though
|
|
470
466
|
continue;
|
|
471
467
|
}
|
|
472
468
|
if ((propertiesBitMap | bitMap) === propertiesBitMap) { // if it stays the same the bit is set
|
|
473
|
-
perms.push(
|
|
469
|
+
perms.push(`Perms.${name}`);
|
|
474
470
|
}
|
|
475
471
|
}
|
|
476
|
-
const result = perms.join(
|
|
477
|
-
(
|
|
472
|
+
const result = perms.join(', ');
|
|
473
|
+
assert(!!result, `perms string cannot be empty (${propertiesBitMap})`);
|
|
478
474
|
return result;
|
|
479
475
|
}
|
|
480
476
|
function checkWrittenVersion(filePath, parsingVersion) {
|
|
481
|
-
filePath =
|
|
482
|
-
const content =
|
|
477
|
+
filePath = path.resolve(import.meta.dirname, filePath);
|
|
478
|
+
const content = fs.readFileSync(filePath, { encoding: 'utf8' }).split('\n', 3);
|
|
483
479
|
const v = content[1];
|
|
484
|
-
if (!v.startsWith(
|
|
485
|
-
throw new Error(
|
|
480
|
+
if (!v.startsWith('// V=')) {
|
|
481
|
+
throw new Error(`Could not detect definition version for '${filePath}'`);
|
|
486
482
|
}
|
|
487
|
-
const version = parseInt(v.replace(
|
|
483
|
+
const version = parseInt(v.replace('// V=', ''), 10);
|
|
488
484
|
return parsingVersion >= version;
|
|
489
485
|
}
|
|
490
486
|
function rewriteProperties(className, properties) {
|
|
491
|
-
const filePath =
|
|
492
|
-
if (!
|
|
493
|
-
throw new Error(
|
|
487
|
+
const filePath = path.resolve(import.meta.dirname, `../${className}.ts`);
|
|
488
|
+
if (!fs.existsSync(filePath)) {
|
|
489
|
+
throw new Error(`File '${filePath}' does not exist!`);
|
|
494
490
|
}
|
|
495
|
-
const file =
|
|
496
|
-
const lines = file.split(
|
|
491
|
+
const file = fs.readFileSync(filePath, { encoding: 'utf8' });
|
|
492
|
+
const lines = file.split('\n');
|
|
497
493
|
let i = 0;
|
|
498
494
|
let importStart = -1;
|
|
499
495
|
let importEnd = -1;
|
|
500
496
|
let foundImport = false;
|
|
501
497
|
for (; i < lines.length; i++) {
|
|
502
498
|
const line = lines[i];
|
|
503
|
-
if (line ===
|
|
499
|
+
if (line === 'import type {') {
|
|
504
500
|
importStart = i; // save last import start;
|
|
505
501
|
}
|
|
506
|
-
else if (line ===
|
|
502
|
+
else if (line === '} from "./definitions";') {
|
|
507
503
|
importEnd = i;
|
|
508
504
|
foundImport = true;
|
|
509
505
|
break;
|
|
510
506
|
}
|
|
511
507
|
}
|
|
512
508
|
if (!foundImport) {
|
|
513
|
-
throw new Error(
|
|
509
|
+
throw new Error('Could not find import section!');
|
|
514
510
|
}
|
|
515
511
|
let startIndex = -1;
|
|
516
512
|
let stopIndex = -1;
|
|
517
513
|
for (; i < lines.length; i++) {
|
|
518
|
-
if (lines[i] ===
|
|
514
|
+
if (lines[i] === ' // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-') {
|
|
519
515
|
startIndex = i;
|
|
520
516
|
break;
|
|
521
517
|
}
|
|
522
518
|
}
|
|
523
519
|
if (startIndex === -1) {
|
|
524
|
-
throw new Error(
|
|
520
|
+
throw new Error('Could not find start pattern in file!');
|
|
525
521
|
}
|
|
526
522
|
for (; i < lines.length; i++) {
|
|
527
|
-
if (lines[i] ===
|
|
523
|
+
if (lines[i] === ' // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=') {
|
|
528
524
|
stopIndex = i;
|
|
529
525
|
break;
|
|
530
526
|
}
|
|
531
527
|
}
|
|
532
528
|
if (stopIndex === -1) {
|
|
533
|
-
throw new Error(
|
|
529
|
+
throw new Error('Could not find stop pattern in file!');
|
|
534
530
|
}
|
|
535
531
|
const importSize = importEnd - importStart - 1;
|
|
536
532
|
const newImports = properties
|
|
537
533
|
.filter(([key, value]) => key === value.className)
|
|
538
|
-
.map(([key]) =>
|
|
534
|
+
.map(([key]) => ` ${key},`);
|
|
539
535
|
lines.splice(importStart + 1, importSize, ...newImports); // remove current imports
|
|
540
536
|
const importDelta = newImports.length - importSize;
|
|
541
537
|
startIndex += importDelta;
|
|
542
538
|
stopIndex += importDelta;
|
|
543
539
|
const amount = stopIndex - startIndex - 1;
|
|
544
540
|
const newContentLines = properties.map(([key, value]) => {
|
|
545
|
-
let line =
|
|
541
|
+
let line = '';
|
|
546
542
|
let deprecatedNotice = value.deprecatedNotice;
|
|
547
543
|
if (key !== value.className) {
|
|
548
|
-
deprecatedNotice =
|
|
549
|
-
|
|
544
|
+
deprecatedNotice = `Please use {@link ${className}.${value.className}}.${ // prepend deprecated notice
|
|
545
|
+
deprecatedNotice
|
|
546
|
+
? ` ${deprecatedNotice}`
|
|
547
|
+
: ''}`;
|
|
550
548
|
}
|
|
551
|
-
line +=
|
|
552
|
-
line +=
|
|
549
|
+
line += ' /**\n';
|
|
550
|
+
line += ` * @group ${className} Definitions\n`;
|
|
553
551
|
if (deprecatedNotice) {
|
|
554
|
-
line +=
|
|
552
|
+
line += ` * @deprecated ${deprecatedNotice}\n`;
|
|
555
553
|
}
|
|
556
|
-
line +=
|
|
557
|
-
line +=
|
|
554
|
+
line += ' */\n';
|
|
555
|
+
line += ` public static ${key}: typeof ${value.className};`;
|
|
558
556
|
return line;
|
|
559
557
|
});
|
|
560
558
|
lines.splice(startIndex + 1, amount, ...newContentLines); // insert new lines
|
|
561
|
-
const resultContent = lines.join(
|
|
562
|
-
|
|
559
|
+
const resultContent = lines.join('\n');
|
|
560
|
+
fs.writeFileSync(filePath, resultContent, { encoding: 'utf8' });
|
|
563
561
|
}
|
|
564
562
|
function writeCharacteristicTestFile() {
|
|
565
563
|
const characteristics = Object.values(generatedCharacteristics).sort((a, b) => a.className.localeCompare(b.className));
|
|
566
|
-
const testOutput =
|
|
567
|
-
testOutput.write(
|
|
568
|
-
testOutput.write(
|
|
569
|
-
testOutput.write(
|
|
570
|
-
testOutput.write(
|
|
564
|
+
const testOutput = fs.createWriteStream(path.resolve(import.meta.dirname, './CharacteristicDefinitions.spec.ts'), { encoding: 'utf8' });
|
|
565
|
+
testOutput.write('// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n');
|
|
566
|
+
testOutput.write('import { describe, expect, it } from "vitest";\n');
|
|
567
|
+
testOutput.write('import "./";\n\n');
|
|
568
|
+
testOutput.write('import { Characteristic } from "../Characteristic";\n\n');
|
|
569
|
+
testOutput.write('describe("CharacteristicDefinitions", () => {');
|
|
571
570
|
for (const generated of characteristics) {
|
|
572
|
-
testOutput.write(
|
|
573
|
-
testOutput.write(
|
|
571
|
+
testOutput.write('\n');
|
|
572
|
+
testOutput.write(` describe("${generated.className}", () => {\n`);
|
|
574
573
|
// first test is just calling the constructor
|
|
575
|
-
testOutput.write(
|
|
576
|
-
testOutput.write(
|
|
574
|
+
testOutput.write(' it("should be able to construct", () => {\n');
|
|
575
|
+
testOutput.write(` expect(() => new Characteristic.${generated.className}()).not.toThrow();\n`);
|
|
577
576
|
if (generated.deprecatedClassName) {
|
|
578
|
-
testOutput.write(
|
|
579
|
-
testOutput.write(
|
|
577
|
+
testOutput.write(' // noinspection JSDeprecatedSymbols\n');
|
|
578
|
+
testOutput.write(` expect(() => new Characteristic.${generated.deprecatedClassName}()).not.toThrow();\n`);
|
|
580
579
|
}
|
|
581
|
-
testOutput.write(
|
|
582
|
-
testOutput.write(
|
|
580
|
+
testOutput.write(' });\n');
|
|
581
|
+
testOutput.write(' });\n');
|
|
583
582
|
}
|
|
584
|
-
testOutput.write(
|
|
583
|
+
testOutput.write('});\n');
|
|
585
584
|
testOutput.end();
|
|
586
585
|
}
|
|
587
586
|
function writeServicesTestFile() {
|
|
588
587
|
const services = Object.values(generatedServices).sort((a, b) => a.className.localeCompare(b.className));
|
|
589
|
-
const testOutput =
|
|
590
|
-
testOutput.write(
|
|
591
|
-
testOutput.write(
|
|
592
|
-
testOutput.write(
|
|
593
|
-
testOutput.write(
|
|
594
|
-
testOutput.write(
|
|
588
|
+
const testOutput = fs.createWriteStream(path.resolve(import.meta.dirname, './ServiceDefinitions.spec.ts'), { encoding: 'utf8' });
|
|
589
|
+
testOutput.write('// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n');
|
|
590
|
+
testOutput.write('import { describe, expect, it } from "vitest";\n');
|
|
591
|
+
testOutput.write('import "./";\n\n');
|
|
592
|
+
testOutput.write('import { Characteristic } from "../Characteristic";\n');
|
|
593
|
+
testOutput.write('import { Service } from "../Service";\n\n');
|
|
594
|
+
testOutput.write('describe("ServiceDefinitions", () => {');
|
|
595
595
|
for (const generated of services) {
|
|
596
|
-
testOutput.write(
|
|
597
|
-
testOutput.write(
|
|
596
|
+
testOutput.write('\n');
|
|
597
|
+
testOutput.write(` describe("${generated.className}", () => {\n`);
|
|
598
598
|
// first test is just calling the constructor
|
|
599
|
-
testOutput.write(
|
|
600
|
-
testOutput.write(
|
|
601
|
-
testOutput.write(
|
|
602
|
-
testOutput.write(
|
|
603
|
-
testOutput.write(
|
|
604
|
-
testOutput.write(
|
|
605
|
-
testOutput.write(
|
|
606
|
-
testOutput.write(
|
|
607
|
-
testOutput.write(
|
|
608
|
-
testOutput.write(
|
|
609
|
-
testOutput.write(
|
|
610
|
-
testOutput.write(
|
|
611
|
-
testOutput.write(
|
|
612
|
-
testOutput.write(
|
|
613
|
-
testOutput.write(
|
|
599
|
+
testOutput.write(' it("should be able to construct", () => {\n');
|
|
600
|
+
testOutput.write(` const service0 = new Service.${generated.className}();\n`);
|
|
601
|
+
testOutput.write(` const service1 = new Service.${generated.className}("test name");\n`);
|
|
602
|
+
testOutput.write(` const service2 = new Service.${generated.className}("test name", "test sub type");\n\n`);
|
|
603
|
+
testOutput.write(' expect(service0.displayName).toBe("");\n');
|
|
604
|
+
testOutput.write(` expect(service0.testCharacteristic(Characteristic.Name)).toBe(${generated.requiredCharacteristics.includes('name')});\n`);
|
|
605
|
+
testOutput.write(' expect(service0.subtype).toBeUndefined();\n\n');
|
|
606
|
+
testOutput.write(' expect(service1.displayName).toBe("test name");\n');
|
|
607
|
+
testOutput.write(' expect(service1.testCharacteristic(Characteristic.Name)).toBe(true);\n');
|
|
608
|
+
testOutput.write(' expect(service1.getCharacteristic(Characteristic.Name).value).toBe("test name");\n');
|
|
609
|
+
testOutput.write(' expect(service1.subtype).toBeUndefined();\n\n');
|
|
610
|
+
testOutput.write(' expect(service2.displayName).toBe("test name");\n');
|
|
611
|
+
testOutput.write(' expect(service2.testCharacteristic(Characteristic.Name)).toBe(true);\n');
|
|
612
|
+
testOutput.write(' expect(service2.getCharacteristic(Characteristic.Name).value).toBe("test name");\n');
|
|
613
|
+
testOutput.write(' expect(service2.subtype).toBe("test sub type");\n');
|
|
614
614
|
if (generated.deprecatedClassName) {
|
|
615
|
-
testOutput.write(
|
|
616
|
-
testOutput.write(
|
|
615
|
+
testOutput.write(' // noinspection JSDeprecatedSymbols\n');
|
|
616
|
+
testOutput.write(`\n expect(() => new Service.${generated.deprecatedClassName}()).not.toThrow();\n`);
|
|
617
617
|
}
|
|
618
|
-
testOutput.write(
|
|
619
|
-
testOutput.write(
|
|
618
|
+
testOutput.write(' });\n');
|
|
619
|
+
testOutput.write(' });\n');
|
|
620
620
|
}
|
|
621
|
-
testOutput.write(
|
|
621
|
+
testOutput.write('});\n');
|
|
622
622
|
testOutput.end();
|
|
623
623
|
}
|
|
624
624
|
//# sourceMappingURL=generate-definitions.js.map
|