Skip to content

Commit

Permalink
Add deprecated CameraControl service again
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Oct 18, 2020
1 parent 1b47a4c commit 75452d7
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/lib/Service.ts
Expand Up @@ -16,6 +16,7 @@ import {
AirQualitySensor,
AudioStreamManagement,
Battery,
CameraControl,
CameraOperatingMode,
CameraRecordingManagement,
CameraRTPStreamManagement,
Expand Down Expand Up @@ -155,6 +156,10 @@ export class Service extends EventEmitter {
* @deprecated Please use {@link Service.Battery}.
*/
public static BatteryService: typeof Battery;
/**
* @deprecated This service has no usage anymore and will be ignored by iOS
*/
public static CameraControl: typeof CameraControl;
/**
* @deprecated Please use {@link Service.CameraRecordingManagement}.
*/
Expand Down
22 changes: 22 additions & 0 deletions src/lib/definitions/ServiceDefinitions.spec.ts
Expand Up @@ -162,6 +162,28 @@ describe("ServiceDefinitions", () => {
});
});

describe("CameraControl", () => {
it("should be able to construct", () => {
const service0 = new Service.CameraControl();
const service1 = new Service.CameraControl("test name");
const service2 = new Service.CameraControl("test name", "test sub type");

expect(service0.displayName).toBe("");
expect(service0.testCharacteristic(Characteristic.Name)).toBe(false);
expect(service0.subtype).toBeUndefined();

expect(service1.displayName).toBe("test name");
expect(service1.testCharacteristic(Characteristic.Name)).toBe(true);
expect(service1.getCharacteristic(Characteristic.Name).value).toBe("test name");
expect(service1.subtype).toBeUndefined();

expect(service2.displayName).toBe("test name");
expect(service2.testCharacteristic(Characteristic.Name)).toBe(true);
expect(service2.getCharacteristic(Characteristic.Name).value).toBe("test name");
expect(service2.subtype).toBe("test sub type");
});
});

describe("CameraOperatingMode", () => {
it("should be able to construct", () => {
const service0 = new Service.CameraOperatingMode();
Expand Down
29 changes: 29 additions & 0 deletions src/lib/definitions/ServiceDefinitions.ts
Expand Up @@ -168,6 +168,35 @@ export class Battery extends Service {
Service.BatteryService = Battery;
Service.Battery = Battery;

/**
* Service "Camera Control"
* @deprecated This service has no usage anymore and will be ignored by iOS
*/
export class CameraControl extends Service {

public static readonly UUID: string = "00000111-0000-1000-8000-0026BB765291";

constructor(displayName?: string, subtype?: string) {
super(displayName, CameraControl.UUID, subtype);

// Required Characteristics
this.addCharacteristic(Characteristic.On);

// Optional Characteristics
this.addOptionalCharacteristic(Characteristic.CurrentHorizontalTiltAngle);
this.addOptionalCharacteristic(Characteristic.CurrentVerticalTiltAngle);
this.addOptionalCharacteristic(Characteristic.TargetHorizontalTiltAngle);
this.addOptionalCharacteristic(Characteristic.TargetVerticalTiltAngle);
this.addOptionalCharacteristic(Characteristic.NightVision);
this.addOptionalCharacteristic(Characteristic.OpticalZoom);
this.addOptionalCharacteristic(Characteristic.DigitalZoom);
this.addOptionalCharacteristic(Characteristic.ImageRotation);
this.addOptionalCharacteristic(Characteristic.ImageMirroring);
this.addOptionalCharacteristic(Characteristic.Name);
}
}
Service.CameraControl = CameraControl;

/**
* Service "Camera Operating Mode"
*/
Expand Down
60 changes: 39 additions & 21 deletions src/lib/definitions/generate-definitions.ts
Expand Up @@ -111,6 +111,7 @@ export interface GeneratedCharacteristic {
className: string,
deprecatedClassName?: string;
since?: string,
deprecatedNotice?: string;

format: string,
units?: string,
Expand All @@ -133,6 +134,7 @@ export interface GeneratedService {
className: string,
deprecatedClassName?: string,
since?: string,
deprecatedNotice?: string,

requiredCharacteristics: string[];
optionalCharacteristics?: string[];
Expand Down Expand Up @@ -216,8 +218,8 @@ characteristicOutput.write("import { Characteristic, Formats, Perms, Units } fro
* Characteristics
*/

const generatedCharacteristics: Record<string, GeneratedCharacteristic> = {};
const writtenCharacteristicEntries: Record<string, string> = {}; // Characteristic.<Key> = <Value>
const generatedCharacteristics: Record<string, GeneratedCharacteristic> = {}; // indexed by id
const writtenCharacteristicEntries: Record<string, GeneratedCharacteristic> = {}; // indexed by class name

for (const [id, definition] of Object.entries(characteristics)) {
try {
Expand Down Expand Up @@ -263,7 +265,7 @@ for (const [id, definition] of Object.entries(characteristics)) {
}
}

generatedCharacteristics[id] = {
const generatedCharacteristic: GeneratedCharacteristic = {
id: id,
UUID: longUUID,
name: name,
Expand All @@ -284,9 +286,10 @@ for (const [id, definition] of Object.entries(characteristics)) {
validBitMasks: validBitMasks,
classAdditions: CharacteristicClassAdditions.get(id),
};
writtenCharacteristicEntries[className] = className;
generatedCharacteristics[id] = generatedCharacteristic;
writtenCharacteristicEntries[className] = generatedCharacteristic;
if (deprecatedClassName) {
writtenCharacteristicEntries[deprecatedClassName] = className;
writtenCharacteristicEntries[deprecatedClassName] = generatedCharacteristic;
}
} catch (error) {
throw new Error("Error thrown generating characteristic '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
Expand All @@ -295,9 +298,9 @@ for (const [id, definition] of Object.entries(characteristics)) {

for (const [id, generated] of CharacteristicManualAdditions) {
generatedCharacteristics[id] = generated;
writtenCharacteristicEntries[generated.className] = generated.className;
writtenCharacteristicEntries[generated.className] = generated;
if (generated.deprecatedClassName) {
writtenCharacteristicEntries[generated.deprecatedClassName] = generated.className;
writtenCharacteristicEntries[generated.deprecatedClassName] = generated;
}
}

Expand All @@ -309,6 +312,9 @@ for (const generated of Object.values(generatedCharacteristics)
if (generated.since) {
characteristicOutput.write(" * @since iOS " + generated.since + "\n");
}
if (generated.deprecatedNotice) {
characteristicOutput.write(" * @deprecated " + generated.deprecatedNotice + "\n");
}
characteristicOutput.write(" */\n");


Expand Down Expand Up @@ -386,8 +392,8 @@ serviceOutput.write("\n");
serviceOutput.write("import { Characteristic } from \"../Characteristic\";\n");
serviceOutput.write("import { Service } from \"../Service\";\n\n");

const generatedServices: Record<string, GeneratedService> = {};
const writtenServiceEntries: Record<string, string> = {}; // Service.<Key> = <Value>
const generatedServices: Record<string, GeneratedService> = {}; // indexed by id
const writtenServiceEntries: Record<string, GeneratedService> = {}; // indexed by class name

for (const [id, definition] of Object.entries(services)) {
try {
Expand Down Expand Up @@ -438,7 +444,7 @@ for (const [id, definition] of Object.entries(services)) {
}
}

generatedServices[id] = {
const generatedService: GeneratedService = {
id: id,
UUID: longUUID,
name: name,
Expand All @@ -448,10 +454,11 @@ for (const [id, definition] of Object.entries(services)) {

requiredCharacteristics: requiredCharacteristics,
optionalCharacteristics: optionalCharacteristics,
}
writtenServiceEntries[className] = className;
};
generatedServices[id] = generatedService;
writtenServiceEntries[className] = generatedService;
if (deprecatedClassName) {
writtenServiceEntries[deprecatedClassName] = className;
writtenServiceEntries[deprecatedClassName] = generatedService;
}
} catch (error) {
throw new Error("Error thrown generating service '" + id + "' (" + definition.DefaultDescription + "): " + error.message);
Expand All @@ -460,9 +467,9 @@ for (const [id, definition] of Object.entries(services)) {

for (const [id, generated] of ServiceManualAdditions) {
generatedServices[id] = generated;
writtenServiceEntries[generated.className] = generated.className;
writtenServiceEntries[generated.className] = generated;
if (generated.deprecatedClassName) {
writtenServiceEntries[generated.deprecatedClassName] = generated.className;
writtenServiceEntries[generated.deprecatedClassName] = generated;
}
}

Expand All @@ -474,6 +481,9 @@ for (const generated of Object.values(generatedServices)
if (generated.since) {
serviceOutput.write(" * @since iOS " + generated.since + "\n");
}
if (generated.deprecatedNotice) {
serviceOutput.write(" * @deprecated " + generated.deprecatedNotice + "\n");
}
serviceOutput.write(" */\n");

serviceOutput.write("export class " + generated.className + " extends Service {\n\n");
Expand Down Expand Up @@ -611,7 +621,7 @@ function checkWrittenVersion(filePath: string, parsingVersion: number): boolean
return parsingVersion >= version;
}

function rewriteProperties(className: string, properties: [key: string, value: string][]): void {
function rewriteProperties(className: string, properties: [key: string, value: GeneratedCharacteristic | GeneratedService][]): void {
const filePath = path.resolve(__dirname, "../" + className + ".ts");
if (!fs.existsSync(filePath)) {
throw new Error("File '" + filePath + "' does not exists!");
Expand Down Expand Up @@ -664,7 +674,7 @@ function rewriteProperties(className: string, properties: [key: string, value: s

const importSize = importEnd - importStart - 1;
const newImports = properties
.filter(([key, value]) => key === value)
.filter(([key, value]) => key === value.className)
.map(([key]) => " " + key + ",");
lines.splice(importStart + 1, importSize, ...newImports); // remove current imports

Expand All @@ -676,12 +686,20 @@ function rewriteProperties(className: string, properties: [key: string, value: s
const amount = stopIndex - startIndex - 1;
const newContentLines = properties.map(([key, value]) => {
let line = "";
if (key !== value) {

let deprecatedNotice = value.deprecatedNotice;

if (key !== value.className) {
deprecatedNotice = "Please use {@link " + className + "." + value.className + "}." // prepend deprecated notice
+ (deprecatedNotice? " " + deprecatedNotice: "");
}
if (deprecatedNotice) {
line += " /**\n";
line += " * @deprecated Please use {@link " + className + "." + value + "}.\n";
line += " */ \n";
line += " * @deprecated " + deprecatedNotice + "\n";
line += " */\n";
}
line += " public static " + key + ": typeof " + value + ";";

line += " public static " + key + ": typeof " + value.className + ";";
return line;
});
lines.splice(startIndex + 1, amount, ...newContentLines); // insert new lines
Expand Down
15 changes: 13 additions & 2 deletions src/lib/definitions/generator-configuration.ts
Expand Up @@ -105,7 +105,7 @@ export const ServiceCharacteristicConfigurationOverrides: Map<string, Characteri
]);

export const ServiceManualAdditions: Map<string, GeneratedService> = new Map([
["og-speaker", { // same as Speaker service just a bit different
["og-speaker", { // the normal speaker is considered to be the "TelevisionSpeaker"
id: "og-speaker",
UUID: "00000113-0000-1000-8000-0026BB765291",
name: "Speaker",
Expand All @@ -114,7 +114,18 @@ export const ServiceManualAdditions: Map<string, GeneratedService> = new Map([

requiredCharacteristics: ["mute"],
optionalCharacteristics: ["active", "volume"],
}]
}],
["camera-control", {
id: "camera-control",
UUID: "00000111-0000-1000-8000-0026BB765291",
name: "Camera Control",
className: "CameraControl",
deprecatedNotice: "This service has no usage anymore and will be ignored by iOS",

requiredCharacteristics: ["on"],
optionalCharacteristics: ["horizontal-tilt.current", "vertical-tilt.current", "horizontal-tilt.target", "vertical-tilt.target", "night-vision", "optical-zoom", "digital-zoom", "image-rotation", "image-mirroring", "name"]
}
],
]);

export const CharacteristicSinceInformation: Map<string, string> = new Map([
Expand Down

0 comments on commit 75452d7

Please sign in to comment.