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