Skip to content

Commit

Permalink
Reworked characteristic and service definition generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Nov 11, 2020
1 parent 4d8039a commit 371aa9a
Show file tree
Hide file tree
Showing 42 changed files with 10,155 additions and 7,470 deletions.
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module.exports = {
coverageReporters: ["lcov"],
collectCoverageFrom: [
"src/**",
"!src/accessories/**"
"!src/accessories/**",
"!src/lib/definitions/generate-definitions.ts",
"!src/lib/definitions/generator-configuration.ts"
],
};
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.14",
"@types/node": "^10.17.20",
"commander": "^6.1.0",
"jest": "^26.5.2",
"rimraf": "^3.0.2",
"semver": "^7.3.2",
Expand Down
1 change: 0 additions & 1 deletion src/accessories/AirConditioner_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ ACTest.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback
});

// Add the actual Fan Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`

const FanService = ACTest.addService(Service.Fan, "Blower"); // services exposed to the user should have "names" like "Fake Light" for us
FanService.getCharacteristic(Characteristic.On)!
Expand Down
1 change: 0 additions & 1 deletion src/accessories/Fan_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ fan.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) =
});

// Add the actual Fan Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
fan
.addService(Service.Fan, "Fan") // services exposed to the user should have "names" like "Fake Light" for us
.getCharacteristic(Characteristic.On)!
Expand Down
1 change: 0 additions & 1 deletion src/accessories/Light_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ lightAccessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: Void
});

// Add the actual Lightbulb Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
lightAccessory
.addService(Service.Lightbulb, LightController.name) // services exposed to the user should have "names" like "Light" for this case
.getCharacteristic(Characteristic.On)!
Expand Down
1 change: 0 additions & 1 deletion src/accessories/Lock_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ lock.on(AccessoryEventTypes.IDENTIFY, (paired, callback) => {
const service = new Service.LockMechanism("Fake Lock");

// Add the actual Door Lock Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
service.getCharacteristic(Characteristic.LockTargetState)
.on(CharacteristicEventTypes.SET, (value, callback) => {

Expand Down
1 change: 0 additions & 1 deletion src/accessories/Outlet_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ outlet.on(AccessoryEventTypes.IDENTIFY, function(paired: boolean, callback: Void
});

// Add the actual outlet Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
outlet
.addService(Service.Outlet, "Fake Outlet") // services exposed to the user should have "names" like "Fake Light" for us
.getCharacteristic(Characteristic.On)!
Expand Down
9 changes: 5 additions & 4 deletions src/accessories/SmartSpeaker_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {
Categories,
Characteristic,
CharacteristicEventTypes,
CharacteristicGetCallback, CharacteristicSetCallback, CharacteristicValue,
CharacteristicGetCallback,
CharacteristicSetCallback,
CharacteristicValue,
Service,
uuid
} from "..";
import {CurrentMediaState, TargetMediaState} from "../lib/gen/HomeKit-TV";

const speakerUUID = uuid.generate('hap-nodejs:accessories:smart-speaker');
const speaker = exports.accessory = new Accessory('SmartSpeaker', speakerUUID);
Expand All @@ -20,8 +21,8 @@ speaker.category = Categories.SPEAKER;

const service = new Service.SmartSpeaker('Smart Speaker', '');

let currentMediaState: number = CurrentMediaState.PAUSE;
let targetMediaState: number = TargetMediaState.PAUSE;
let currentMediaState: number = Characteristic.CurrentMediaState.PAUSE;
let targetMediaState: number = Characteristic.TargetMediaState.PAUSE;

// ConfigureName is used to listen for Name changes inside the Home App.
// A device manufacturer would probably need to adjust the name of the device in the AirPlay 2 protocol (or something)
Expand Down
1 change: 0 additions & 1 deletion src/accessories/Sprinkler_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ sprinkler.pincode = "123-44-567";
sprinkler.category = Categories.SPRINKLER;

// Add the actual Valve Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
const sprinklerService = sprinkler.addService(Service.Valve, "💦 Sprinkler");


Expand Down
1 change: 0 additions & 1 deletion src/accessories/TV_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ tv.pincode = "031-45-154";
tv.category = Categories.TELEVISION;

// Add the actual TV Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
const televisionService = tv.addService(Service.Television, "Television", "Television");

televisionService
Expand Down
1 change: 0 additions & 1 deletion src/accessories/TemperatureSensor_accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ sensor.pincode = "031-45-154";
sensor.category = Categories.SENSOR;

// Add the actual TemperatureSensor Service.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
sensor
.addService(Service.TemperatureSensor)!
.getCharacteristic(Characteristic.CurrentTemperature)!
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "source-map-support/register"; // registering node-source-map-support for typescript stack traces
import './lib/gen';
import './lib/definitions'; // must be loaded before Characteristic and Service class
import * as accessoryLoader from './lib/AccessoryLoader';
import * as uuidFunctions from './lib/util/uuid';
import * as legacyTypes from './accessories/types';
Expand All @@ -17,7 +17,6 @@ export * from './lib/AccessoryLoader';
export * from './lib/camera';
export * from './lib/tv/AccessControlManagement';
export * from './lib/HAPServer';
export * from './lib/gen';
export * from './lib/datastream';
export * from './lib/controller';

Expand Down
1 change: 0 additions & 1 deletion src/lib/Accessory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './gen';
import {
Accessory,
Categories,
Expand Down
20 changes: 5 additions & 15 deletions src/lib/Accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ import {
ControllerType,
isSerializableController,
} from "./controller";
import * as HomeKitTypes from "./gen";
import {
CameraEventRecordingManagement,
CameraOperatingMode,
CameraRTPStreamManagement,
ContactSensorState,
MotionDetected,
ProgrammableSwitchEvent,
} from "./gen/HomeKit";
import { ButtonEvent } from "./gen/HomeKit-Remote";
import {
AccessoriesCallback,
AddPairingCallback,
Expand Down Expand Up @@ -659,8 +649,8 @@ export class Accessory extends EventEmitter {

// we try here to be as good as possibly of keeping current behaviour
cameraSource.services.forEach(service => {
if (service.UUID === CameraRTPStreamManagement.UUID || service.UUID === CameraOperatingMode.UUID
|| service.UUID === CameraEventRecordingManagement.UUID) {
if (service.UUID === Service.CameraRTPStreamManagement.UUID || service.UUID === Service.CameraOperatingMode.UUID
|| service.UUID === Service.CameraRecordingManagement.UUID) {
return; // ignore those services, as they get replaced by the RTPStreamManagement
}

Expand Down Expand Up @@ -1414,7 +1404,7 @@ export class Accessory extends EventEmitter {
data.perms = characteristic.props.perms;
}
if (request.includeType) {
data.type = toShortForm(this.UUID, HomeKitTypes.BASE_UUID);
data.type = toShortForm(this.UUID);
}
if (request.includeEvent) {
data.ev = connection.hasEventNotifications(id.aid, id.iid);
Expand Down Expand Up @@ -1730,8 +1720,8 @@ export class Accessory extends EventEmitter {
}

const uuid = change.characteristic.UUID;
const immediateDelivery = uuid === ButtonEvent.UUID || uuid === ProgrammableSwitchEvent.UUID
|| uuid === MotionDetected.UUID || uuid === ContactSensorState.UUID;
const immediateDelivery = uuid === Characteristic.ButtonEvent.UUID || uuid === Characteristic.ProgrammableSwitchEvent.UUID
|| uuid === Characteristic.MotionDetected.UUID || uuid === Characteristic.ContactSensorState.UUID;

this._server.sendEventNotifications(accessory.aid, change.characteristic.iid, change.newValue, change.originator, immediateDelivery);
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/Characteristic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Units,
uuid
} from '..';
import './gen';

function createCharacteristic(type: Formats, customUUID?: string): Characteristic {
return new Characteristic('Test', customUUID || uuid.generate('Foo'), { format: type, perms: [Perms.PAIRED_READ, Perms.PAIRED_WRITE] });
Expand Down
Loading

0 comments on commit 371aa9a

Please sign in to comment.