Compiles and runs. Devices appearing in home kit.
This commit is contained in:
parent
356589b1fe
commit
39bf619b3a
1
.bash_profile
Normal file
1
.bash_profile
Normal file
@ -0,0 +1 @@
|
|||||||
|
source /nvm.sh
|
273
config.json
Normal file
273
config.json
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
{
|
||||||
|
"platform": "HarmonyHubMatrix",
|
||||||
|
"ControlUnits": [
|
||||||
|
{
|
||||||
|
"DisplayName": "Living Room",
|
||||||
|
"Activities": [
|
||||||
|
{
|
||||||
|
"DisplayName": "Play Xbox One",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "Microsoft Xbox One",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "LG TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "JVC AV Receiver",
|
||||||
|
"Input": "DVD"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "JVC AV Receiver",
|
||||||
|
"ControlDevice": "Microsoft Xbox One",
|
||||||
|
"OutputDevice": "LG TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Play Xbox One",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "Microsoft Xbox One",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "LG TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "JVC AV Receiver",
|
||||||
|
"Input": "DVD"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "JVC AV Receiver",
|
||||||
|
"ControlDevice": "Microsoft Xbox One",
|
||||||
|
"OutputDevice": "LG TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Play PS4",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "Sony PS4",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": [],
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": [],
|
||||||
|
"Input": "DVD"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "JVC AV Receiver",
|
||||||
|
"ControlDevice": "Sony PS4",
|
||||||
|
"OutputDevice": "LG TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Chromecast",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "LG TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "JVC AV Receiver",
|
||||||
|
"Input": "DVD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "Chromecast",
|
||||||
|
"Input": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "JVC AV Receiver",
|
||||||
|
"ControlDevice": "Chromecast",
|
||||||
|
"OutputDevice": "LG TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Apple TV",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "Apple TV Gen 4",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "LG TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "JVC AV Receiver",
|
||||||
|
"Input": "DVD"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "JVC AV Receiver",
|
||||||
|
"ControlDevice": "Apple TV Gen 4",
|
||||||
|
"OutputDevice": "LG TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Listen to Music",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "JVC AV Receiver",
|
||||||
|
"Input": "DVD"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "JVC AV Receiver",
|
||||||
|
"ControlDevice": [],
|
||||||
|
"OutputDevice": [],
|
||||||
|
"UseMatrix": "false"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Bedroom",
|
||||||
|
"Activities": [
|
||||||
|
{
|
||||||
|
"DisplayName": "Play Xbox One",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"Device": "Microsoft Xbox One",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Vizio TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Harman Kardon AV Receiver",
|
||||||
|
"Input": "Game"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Harman Kardon AV Receiver",
|
||||||
|
"ControlDevice": "Microsoft Xbox One",
|
||||||
|
"OutputDevice": "Vizio TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Play PS4",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"Device": "Sony PS4",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Vizio TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Harman Kardon AV Receiver",
|
||||||
|
"Input": "DVD"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Harman Kardon AV Receiver",
|
||||||
|
"ControlDevice": "Sony PS4",
|
||||||
|
"OutputDevice": "LG TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Chromecast",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"Device": "Vizio TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Harman Kardon AV Receiver",
|
||||||
|
"Input": "Game"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Chromecast",
|
||||||
|
"Input": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Harman Kardon AV Receiver",
|
||||||
|
"ControlDevice": "Chromecast",
|
||||||
|
"OutputDevice": "Vizio TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Apple TV",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"Device": "Apple TV Gen 4",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Vizio TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Harman Kardon AV Receiver",
|
||||||
|
"Input": "Game"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Harman Kardon AV Receiver",
|
||||||
|
"ControlDevice": "Apple TV Gen 4",
|
||||||
|
"OutputDevice": "Vizio TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Kitchen",
|
||||||
|
"Activities": [
|
||||||
|
{
|
||||||
|
"DisplayName": "Watch Apple Tv",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"Device": "Apple TV Gen 4",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Westinghouse TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Westinghouse TV",
|
||||||
|
"ControlDevice": "Apple TV Gen 4",
|
||||||
|
"OutputDevice": "Westinghouse TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Play Xbox One",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"Device": "Westinghouse TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Microsoft Xbox One",
|
||||||
|
"Input": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Westinghouse TV",
|
||||||
|
"ControlDevice": "Microsoft Xbox One",
|
||||||
|
"OutputDevice": "Westinghouse TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DisplayName": "Chromecast",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"Device": "Chromecast",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Device": "Westinghouse TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Westinghouse TV",
|
||||||
|
"ControlDevice": "Chromecast",
|
||||||
|
"OutputDevice": "Westinghouse TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
978
package-lock.json
generated
978
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -2,10 +2,10 @@
|
|||||||
"name": "homebridge-harmony-control",
|
"name": "homebridge-harmony-control",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Homebridge platform to control smart home equipment by room.",
|
"description": "Homebridge platform to control smart home equipment by room.",
|
||||||
"main": "index.js",
|
"main": "bin/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -13,11 +13,27 @@
|
|||||||
},
|
},
|
||||||
"author": "Brandon Watson",
|
"author": "Brandon Watson",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
"keywords": [
|
||||||
|
"homebridge-plugin",
|
||||||
|
"harmony",
|
||||||
|
"websocket",
|
||||||
|
"harmonyhub",
|
||||||
|
"homekit"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"homebridge": ">=0.4.21",
|
||||||
|
"node": ">=7.6.0"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"rollup-plugin-typescript": "^1.0.1",
|
||||||
|
"tslib": "^1.10.0",
|
||||||
"tslint": "^5.17.0",
|
"tslint": "^5.17.0",
|
||||||
"typescript": "^3.5.1"
|
"typescript": "^3.5.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@babel/core": "^7.4.5",
|
||||||
|
"@babel/preset-env": "^7.4.5",
|
||||||
|
"@babel/preset-typescript": "^7.3.3",
|
||||||
"@types/node": "^12.0.7",
|
"@types/node": "^12.0.7",
|
||||||
"harmony-websocket": "^1.1.0",
|
"harmony-websocket": "^1.1.0",
|
||||||
"homebridge": "^0.4.50",
|
"homebridge": "^0.4.50",
|
||||||
|
82
src/Accessories/ControlUnit.ts
Normal file
82
src/Accessories/ControlUnit.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import { Activity } from '../Models/Activity';
|
||||||
|
import { Matrix } from '../Models/Matrix';
|
||||||
|
import { IAccessory } from './IAccessory';
|
||||||
|
|
||||||
|
let Service: HAPNodeJS.Service;
|
||||||
|
let Characteristic: HAPNodeJS.Characteristic;
|
||||||
|
let Api: any;
|
||||||
|
|
||||||
|
export interface IControlUnitProps {
|
||||||
|
displayName: string,
|
||||||
|
activities: Array<Activity>,
|
||||||
|
matrix: Matrix,
|
||||||
|
api: any,
|
||||||
|
log: any,
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ControlUnit implements IAccessory {
|
||||||
|
name: string = "";
|
||||||
|
private log: any = {};
|
||||||
|
private displayName: string = "";
|
||||||
|
private televisionService: HAPNodeJS.Service | undefined;
|
||||||
|
private televisionSpeakerService: HAPNodeJS.Service | undefined;
|
||||||
|
private informationService: HAPNodeJS.Service | undefined;
|
||||||
|
|
||||||
|
constructor(props: IControlUnitProps) {
|
||||||
|
this.log = props.log;
|
||||||
|
Api = props.api;
|
||||||
|
Service = props.api.hap.Service;
|
||||||
|
Characteristic = props.api.hap.Characteristic;
|
||||||
|
this.displayName = props.displayName;
|
||||||
|
this.name = this.displayName;
|
||||||
|
|
||||||
|
this.configureTvService();
|
||||||
|
this.configureTvSpeakerService();
|
||||||
|
// this.configureAccessoryInformation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private configureTvService(): void {
|
||||||
|
this.televisionService = new Service.Television(
|
||||||
|
this.displayName,
|
||||||
|
'tvService'
|
||||||
|
)
|
||||||
|
|
||||||
|
this.televisionService.setCharacteristic(Characteristic.ConfiguredName, this.displayName);
|
||||||
|
//@ts-ignore
|
||||||
|
this.televisionService.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
|
||||||
|
this.televisionService.setCharacteristic(Characteristic.ActiveIdentifier, 1);
|
||||||
|
this.televisionService.setCharacteristic(Characteristic.Active, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private configureTvSpeakerService(): void {
|
||||||
|
this.televisionSpeakerService = new Service.TelevisionSpeaker(
|
||||||
|
this.displayName,
|
||||||
|
'tvSpeakerService'
|
||||||
|
);
|
||||||
|
this.televisionSpeakerService.setCharacteristic(Characteristic.Name, this.displayName);
|
||||||
|
//@ts-ignore
|
||||||
|
this.televisionSpeakerService.setCharacteristic(Characteristic.Active, Characteristic.Active.Active);
|
||||||
|
//@ts-ignore
|
||||||
|
this.televisionSpeakerService.setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.Absolute);
|
||||||
|
this.televisionSpeakerService.subtype = this.displayName + "Volume";
|
||||||
|
if (this.televisionService) {
|
||||||
|
//@ts-ignore
|
||||||
|
this.televisionService.addLinkedService(this.televisionSpeakerService);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private configureAccessoryInformation(): void {
|
||||||
|
this.informationService = new Service.AccessoryInformation(this.displayName, 'information');
|
||||||
|
this.informationService
|
||||||
|
.setCharacteristic(Characteristic.Manufacturer, 'Loftux Carwings')
|
||||||
|
.setCharacteristic(Characteristic.Model, 'Heater-Cooler')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by homebridge to gather services for this accessory.
|
||||||
|
*/
|
||||||
|
getServices(): Array<HAPNodeJS.Service> {
|
||||||
|
this.log(`${this.displayName}`)
|
||||||
|
return ([this.televisionService!, this.televisionSpeakerService!]);
|
||||||
|
}
|
||||||
|
}
|
10
src/Accessories/IAccessory.ts
Normal file
10
src/Accessories/IAccessory.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export interface IAccessory {
|
||||||
|
/**
|
||||||
|
* Required by homebridge.
|
||||||
|
*/
|
||||||
|
name: string,
|
||||||
|
/**
|
||||||
|
* Called by homebridge to gather services.
|
||||||
|
*/
|
||||||
|
getServices(): Array<HAPNodeJS.Service>,
|
||||||
|
}
|
69
src/Models/Activity.ts
Normal file
69
src/Models/Activity.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { DeviceSetupItem } from './DeviceSetupItem';
|
||||||
|
/**
|
||||||
|
* Input properties.
|
||||||
|
*/
|
||||||
|
export interface IActivityProps {
|
||||||
|
deviceList: Array<DeviceSetupItem>,
|
||||||
|
controlDeviceId: string,
|
||||||
|
volumeDeviceId: string,
|
||||||
|
outputDeviceId: string,
|
||||||
|
displayName: string
|
||||||
|
useMatrix: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data model class to hold activity related information.
|
||||||
|
*/
|
||||||
|
export class Activity {
|
||||||
|
private _volumeDeviceId: string = "";
|
||||||
|
private _outputDeviceId: string = "";
|
||||||
|
private _controlDeviceId: string = "";
|
||||||
|
private _displayName: string = "";
|
||||||
|
private _deviceSetupItems: Array<DeviceSetupItem>;
|
||||||
|
private _useMatrix: boolean = false;
|
||||||
|
|
||||||
|
constructor(props: IActivityProps) {
|
||||||
|
this._controlDeviceId = props.controlDeviceId;
|
||||||
|
this._outputDeviceId = props.outputDeviceId;
|
||||||
|
this._volumeDeviceId = props.volumeDeviceId;
|
||||||
|
this._displayName = props.displayName;
|
||||||
|
this._deviceSetupItems = props.deviceList;
|
||||||
|
this._useMatrix = props.useMatrix
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The device associated with main control.
|
||||||
|
*/
|
||||||
|
public get controlDeviceId(): string {
|
||||||
|
return this._controlDeviceId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The device associated with the volume control.
|
||||||
|
*/
|
||||||
|
public get volumeDeviceId(): string {
|
||||||
|
return this._volumeDeviceId
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The device associated with output.
|
||||||
|
*/
|
||||||
|
public outputDeviceId(): string {
|
||||||
|
return this._outputDeviceId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The display name of the activity.
|
||||||
|
*/
|
||||||
|
public get displayName(): string {
|
||||||
|
return this._displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get deviceSetupItem(): Array<DeviceSetupItem> {
|
||||||
|
return this._deviceSetupItems
|
||||||
|
}
|
||||||
|
|
||||||
|
public get useMatrix(): boolean {
|
||||||
|
return this._useMatrix;
|
||||||
|
}
|
||||||
|
}
|
22
src/Models/DeviceSetupItem.ts
Normal file
22
src/Models/DeviceSetupItem.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
export interface IDeviceSetupItemProps {
|
||||||
|
deviceId: string,
|
||||||
|
input: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DeviceSetupItem {
|
||||||
|
private _deviceId: string = "";
|
||||||
|
private _input: string = "";
|
||||||
|
constructor(props: IDeviceSetupItemProps) {
|
||||||
|
this._deviceId = props.deviceId;
|
||||||
|
this._input = props.input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get deviceId() {
|
||||||
|
return this._deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get input() {
|
||||||
|
return this._input;
|
||||||
|
}
|
||||||
|
}
|
32
src/Models/Matrix.ts
Normal file
32
src/Models/Matrix.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
export interface IMatrixProps {
|
||||||
|
inputs: Array<Input>,
|
||||||
|
outputs: Array<Output>,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Input {
|
||||||
|
inputNumber: string,
|
||||||
|
inputDevice: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Output {
|
||||||
|
outputLetter: string,
|
||||||
|
outputDevice: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Matrix {
|
||||||
|
private _inputs: Array<Input> = [];
|
||||||
|
private _outputs: Array<Output> = [];
|
||||||
|
|
||||||
|
constructor(props: IMatrixProps) {
|
||||||
|
this._inputs = props.inputs;
|
||||||
|
this._outputs = props.outputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get inputs(): Array<Input> {
|
||||||
|
return this._inputs
|
||||||
|
}
|
||||||
|
|
||||||
|
public get outputs(): Array<Output> {
|
||||||
|
return this._outputs;
|
||||||
|
}
|
||||||
|
}
|
456
src/Types/HAPNodeJS.d.ts
vendored
Normal file
456
src/Types/HAPNodeJS.d.ts
vendored
Normal file
@ -0,0 +1,456 @@
|
|||||||
|
declare namespace HAPNodeJS {
|
||||||
|
|
||||||
|
export interface uuid {
|
||||||
|
generate(data: string): string;
|
||||||
|
isValid(UUID: string): boolean;
|
||||||
|
unparse(bug: string, offset: number): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventService = "characteristic-change" | "service-configurationChange"
|
||||||
|
|
||||||
|
export interface IEventEmitterAccessory {
|
||||||
|
addListener(event: EventService, listener: Function): this;
|
||||||
|
on(event: EventService, listener: Function): this;
|
||||||
|
once(event: EventService, listener: Function): this;
|
||||||
|
removeListener(event: EventService, listener: Function): this;
|
||||||
|
removeAllListeners(event?: EventService): this;
|
||||||
|
setMaxListeners(n: number): this;
|
||||||
|
getMaxListeners(): number;
|
||||||
|
listeners(event: EventService): Function[];
|
||||||
|
emit(event: EventService, ...args: any[]): boolean;
|
||||||
|
listenerCount(type: string): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Service extends IEventEmitterAccessory {
|
||||||
|
new(displayName: string, UUID: string, subtype: string): Service;
|
||||||
|
|
||||||
|
displayName: string;
|
||||||
|
UUID: string;
|
||||||
|
subtype: string;
|
||||||
|
iid: string;
|
||||||
|
characteristics: Characteristic[];
|
||||||
|
optionalCharacteristics: Characteristic[];
|
||||||
|
|
||||||
|
addCharacteristic(characteristic: Characteristic | Function): Characteristic;
|
||||||
|
removeCharacteristic(characteristic: Characteristic): void;
|
||||||
|
getCharacteristic(name: string | Function): Characteristic;
|
||||||
|
testCharacteristic(name: string | Function): boolean;
|
||||||
|
setCharacteristic(name: string | Function, value: CharacteristicValue): Service;
|
||||||
|
updateCharacteristic(name: string | Function, value: CharacteristicValue): Service;
|
||||||
|
addOptionalCharacteristic(characteristic: Characteristic | Function): void;
|
||||||
|
getCharacteristicByIID(iid: string): Characteristic;
|
||||||
|
|
||||||
|
toHAP(opt: any): JSON;
|
||||||
|
|
||||||
|
AccessoryInformation: PredefinedService;
|
||||||
|
AirPurifier: PredefinedService;
|
||||||
|
AirQualitySensor: PredefinedService;
|
||||||
|
BatteryService: PredefinedService;
|
||||||
|
BridgeConfiguration: PredefinedService;
|
||||||
|
BridgingState: PredefinedService;
|
||||||
|
CameraControl: PredefinedService;
|
||||||
|
CameraRTPStreamManagement: PredefinedService;
|
||||||
|
CarbonDioxideSensor: PredefinedService;
|
||||||
|
CarbonMonoxideSensor: PredefinedService;
|
||||||
|
ContactSensor: PredefinedService;
|
||||||
|
Door: PredefinedService;
|
||||||
|
Doorbell: PredefinedService;
|
||||||
|
Fan: PredefinedService;
|
||||||
|
Fanv2: PredefinedService;
|
||||||
|
Faucet: PredefinedService;
|
||||||
|
FilterMaintenance: PredefinedService;
|
||||||
|
GarageDoorOpener: PredefinedService;
|
||||||
|
HeaterCooler: PredefinedService;
|
||||||
|
HumidifierDehumidifier: PredefinedService;
|
||||||
|
HumiditySensor: PredefinedService;
|
||||||
|
InputSource: PredefinedService;
|
||||||
|
IrrigationSystem: PredefinedService;
|
||||||
|
LeakSensor: PredefinedService;
|
||||||
|
LightSensor: PredefinedService;
|
||||||
|
Lightbulb: PredefinedService;
|
||||||
|
LockManagement: PredefinedService;
|
||||||
|
LockMechanism: PredefinedService;
|
||||||
|
Microphone: PredefinedService;
|
||||||
|
MotionSensor: PredefinedService;
|
||||||
|
OccupancySensor: PredefinedService;
|
||||||
|
Outlet: PredefinedService;
|
||||||
|
Pairing: PredefinedService;
|
||||||
|
ProtocolInformation: PredefinedService;
|
||||||
|
Relay: PredefinedService;
|
||||||
|
SecuritySystem: PredefinedService;
|
||||||
|
ServiceLabel: PredefinedService;
|
||||||
|
Slat: PredefinedService;
|
||||||
|
SmokeSensor: PredefinedService;
|
||||||
|
Speaker: PredefinedService;
|
||||||
|
StatefulProgrammableSwitch: PredefinedService;
|
||||||
|
StatelessProgrammableSwitch: PredefinedService;
|
||||||
|
Switch: PredefinedService;
|
||||||
|
Television: PredefinedService;
|
||||||
|
TelevisionSpeaker: PredefinedService;
|
||||||
|
TemperatureSensor: PredefinedService;
|
||||||
|
Thermostat: PredefinedService;
|
||||||
|
TimeInformation: PredefinedService;
|
||||||
|
TunneledBTLEAccessoryService: PredefinedService;
|
||||||
|
Valve: PredefinedService;
|
||||||
|
Window: PredefinedService;
|
||||||
|
WindowCovering: PredefinedService;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PredefinedService {
|
||||||
|
new(displayName: string, subtype: string): Service;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CameraSource {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventAccessory = "service-configurationChange" | "service-characteristic-change" | "identify"
|
||||||
|
|
||||||
|
export interface IEventEmitterAccessory {
|
||||||
|
addListener(event: EventAccessory, listener: Function): this;
|
||||||
|
on(event: EventAccessory, listener: Function): this;
|
||||||
|
once(event: EventAccessory, listener: Function): this;
|
||||||
|
removeListener(event: EventAccessory, listener: Function): this;
|
||||||
|
removeAllListeners(event?: EventAccessory): this;
|
||||||
|
setMaxListeners(n: number): this;
|
||||||
|
getMaxListeners(): number;
|
||||||
|
listeners(event: EventAccessory): Function[];
|
||||||
|
emit(event: EventAccessory, ...args: any[]): boolean;
|
||||||
|
listenerCount(type: string): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CharacteristicProps {
|
||||||
|
format: Characteristic.Formats;
|
||||||
|
unit: Characteristic.Units,
|
||||||
|
minValue: number,
|
||||||
|
maxValue: number,
|
||||||
|
minStep: number,
|
||||||
|
perms: Characteristic.Perms[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventCharacteristic = "get" | "set"
|
||||||
|
type CharacteristicValue = boolean | string | number
|
||||||
|
|
||||||
|
export type CharacteristicGetCallback<T = CharacteristicValue> = (error: Error | null, value: T) => void
|
||||||
|
export type CharacteristicSetCallback = (error?: Error | null) => void
|
||||||
|
export type CharacteristicCallback = CharacteristicGetCallback | CharacteristicSetCallback
|
||||||
|
|
||||||
|
export interface IEventEmitterCharacteristic {
|
||||||
|
addListener(event: EventCharacteristic, listener: CharacteristicCallback): this;
|
||||||
|
on(event: EventCharacteristic, listener: CharacteristicCallback): this;
|
||||||
|
once(event: EventCharacteristic, listener: CharacteristicCallback): this;
|
||||||
|
removeListener(event: EventCharacteristic, listener: CharacteristicCallback): this;
|
||||||
|
removeAllListeners(event?: EventCharacteristic): this;
|
||||||
|
setMaxListeners(n: number): this;
|
||||||
|
getMaxListeners(): number;
|
||||||
|
listeners(event: EventCharacteristic): CharacteristicCallback[];
|
||||||
|
emit(event: EventCharacteristic, ...args: any[]): boolean;
|
||||||
|
listenerCount(type: string): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Characteristic extends IEventEmitterCharacteristic {
|
||||||
|
new(displayName: string, UUID: string, props?: CharacteristicProps): Characteristic;
|
||||||
|
|
||||||
|
Formats: typeof Characteristic.Formats;
|
||||||
|
Units: typeof Characteristic.Units;
|
||||||
|
Perms: typeof Characteristic.Perms;
|
||||||
|
|
||||||
|
setProps(props: CharacteristicProps): Characteristic
|
||||||
|
getValue(callback?: CharacteristicGetCallback, context?: any, connectionID?: string): void;
|
||||||
|
setValue(newValue: CharacteristicValue, callback?: CharacteristicSetCallback, context?: any, connectionID?: string): Characteristic;
|
||||||
|
updateValue(newValue: CharacteristicValue, callback?: () => void, context?: any): Characteristic;
|
||||||
|
getDefaultValue(): CharacteristicValue;
|
||||||
|
toHAP(opt: any): JSON;
|
||||||
|
|
||||||
|
AccessoryFlags: Characteristic;
|
||||||
|
AccessoryIdentifier: Characteristic;
|
||||||
|
Active: Characteristic;
|
||||||
|
ActiveIdentifier: Characteristic;
|
||||||
|
AdministratorOnlyAccess: Characteristic;
|
||||||
|
AirParticulateDensity: Characteristic;
|
||||||
|
AirParticulateSize: Characteristic;
|
||||||
|
AirQuality: Characteristic;
|
||||||
|
AppMatchingIdentifier: Characteristic;
|
||||||
|
AudioFeedback: Characteristic;
|
||||||
|
BatteryLevel: Characteristic;
|
||||||
|
Brightness: Characteristic;
|
||||||
|
CarbonDioxideDetected: Characteristic;
|
||||||
|
CarbonDioxideLevel: Characteristic;
|
||||||
|
CarbonDioxidePeakLevel: Characteristic;
|
||||||
|
CarbonMonoxideDetected: Characteristic;
|
||||||
|
CarbonMonoxideLevel: Characteristic;
|
||||||
|
CarbonMonoxidePeakLevel: Characteristic;
|
||||||
|
Category: Characteristic;
|
||||||
|
ChargingState: Characteristic;
|
||||||
|
ClosedCaptions: Characteristic;
|
||||||
|
ColorTemperature: Characteristic;
|
||||||
|
ConfigureBridgedAccessory: Characteristic;
|
||||||
|
ConfigureBridgedAccessoryStatus: Characteristic;
|
||||||
|
ConfiguredName: Characteristic;
|
||||||
|
ContactSensorState: Characteristic;
|
||||||
|
CoolingThresholdTemperature: Characteristic;
|
||||||
|
CurrentAirPurifierState: Characteristic;
|
||||||
|
CurrentAmbientLightLevel: Characteristic;
|
||||||
|
CurrentDoorState: Characteristic;
|
||||||
|
CurrentFanState: Characteristic;
|
||||||
|
CurrentHeaterCoolerState: Characteristic;
|
||||||
|
CurrentHeatingCoolingState: Characteristic;
|
||||||
|
CurrentHorizontalTiltAngle: Characteristic;
|
||||||
|
CurrentHumidifierDehumidifierState: Characteristic;
|
||||||
|
CurrentMediaState: Characteristic;
|
||||||
|
CurrentPosition: Characteristic;
|
||||||
|
CurrentRelativeHumidity: Characteristic;
|
||||||
|
CurrentSlatState: Characteristic;
|
||||||
|
CurrentTemperature: Characteristic;
|
||||||
|
CurrentTiltAngle: Characteristic;
|
||||||
|
CurrentTime: Characteristic;
|
||||||
|
CurrentVerticalTiltAngle: Characteristic;
|
||||||
|
CurrentVisibilityState: Characteristic;
|
||||||
|
DayoftheWeek: Characteristic;
|
||||||
|
DigitalZoom: Characteristic;
|
||||||
|
DiscoverBridgedAccessories: Characteristic;
|
||||||
|
DiscoveredBridgedAccessories: Characteristic;
|
||||||
|
DisplayOrder: Characteristic;
|
||||||
|
FilterChangeIndication: Characteristic;
|
||||||
|
FilterLifeLevel: Characteristic;
|
||||||
|
FirmwareRevision: Characteristic;
|
||||||
|
HardwareRevision: Characteristic;
|
||||||
|
HeatingThresholdTemperature: Characteristic;
|
||||||
|
HoldPosition: Characteristic;
|
||||||
|
Hue: Characteristic;
|
||||||
|
Identifier: Characteristic;
|
||||||
|
Identify: Characteristic;
|
||||||
|
ImageMirroring: Characteristic;
|
||||||
|
ImageRotation: Characteristic;
|
||||||
|
InUse: Characteristic;
|
||||||
|
InputDeviceType: Characteristic;
|
||||||
|
InputSourceType: Characteristic;
|
||||||
|
IsConfigured: Characteristic;
|
||||||
|
LeakDetected: Characteristic;
|
||||||
|
LinkQuality: Characteristic;
|
||||||
|
LockControlPoint: Characteristic;
|
||||||
|
LockCurrentState: Characteristic;
|
||||||
|
LockLastKnownAction: Characteristic;
|
||||||
|
LockManagementAutoSecurityTimeout: Characteristic;
|
||||||
|
LockPhysicalControls: Characteristic;
|
||||||
|
LockTargetState: Characteristic;
|
||||||
|
Logs: Characteristic;
|
||||||
|
Manufacturer: Characteristic;
|
||||||
|
Model: Characteristic;
|
||||||
|
MotionDetected: Characteristic;
|
||||||
|
Mute: Characteristic;
|
||||||
|
Name: Characteristic;
|
||||||
|
NightVision: Characteristic;
|
||||||
|
NitrogenDioxideDensity: Characteristic;
|
||||||
|
ObstructionDetected: Characteristic;
|
||||||
|
OccupancyDetected: Characteristic;
|
||||||
|
On: Characteristic;
|
||||||
|
OpticalZoom: Characteristic;
|
||||||
|
OutletInUse: Characteristic;
|
||||||
|
OzoneDensity: Characteristic;
|
||||||
|
PM10Density: Characteristic;
|
||||||
|
PM2_5Density: Characteristic;
|
||||||
|
PairSetup: Characteristic;
|
||||||
|
PairVerify: Characteristic;
|
||||||
|
PairingFeatures: Characteristic;
|
||||||
|
PairingPairings: Characteristic;
|
||||||
|
PictureMode: Characteristic;
|
||||||
|
PositionState: Characteristic;
|
||||||
|
PowerModeSelection: Characteristic;
|
||||||
|
ProgramMode: Characteristic;
|
||||||
|
ProgrammableSwitchEvent: Characteristic;
|
||||||
|
ProgrammableSwitchOutputState: Characteristic;
|
||||||
|
Reachable: Characteristic;
|
||||||
|
RelativeHumidityDehumidifierThreshold: Characteristic;
|
||||||
|
RelativeHumidityHumidifierThreshold: Characteristic;
|
||||||
|
RelayControlPoint: Characteristic;
|
||||||
|
RelayEnabled: Characteristic;
|
||||||
|
RelayState: Characteristic;
|
||||||
|
RemainingDuration: Characteristic;
|
||||||
|
RemoteKey: Characteristic;
|
||||||
|
ResetFilterIndication: Characteristic;
|
||||||
|
RotationDirection: Characteristic;
|
||||||
|
RotationSpeed: Characteristic;
|
||||||
|
Saturation: Characteristic;
|
||||||
|
SecuritySystemAlarmType: Characteristic;
|
||||||
|
SecuritySystemCurrentState: Characteristic;
|
||||||
|
SecuritySystemTargetState: Characteristic;
|
||||||
|
SelectedRTPStreamConfiguration: Characteristic;
|
||||||
|
SerialNumber: Characteristic;
|
||||||
|
ServiceLabelIndex: Characteristic;
|
||||||
|
ServiceLabelNamespace: Characteristic;
|
||||||
|
SetDuration: Characteristic;
|
||||||
|
SetupEndpoints: Characteristic;
|
||||||
|
SlatType: Characteristic;
|
||||||
|
SleepDiscoveryMode: Characteristic;
|
||||||
|
SmokeDetected: Characteristic;
|
||||||
|
SoftwareRevision: Characteristic;
|
||||||
|
StatusActive: Characteristic;
|
||||||
|
StatusFault: Characteristic;
|
||||||
|
StatusJammed: Characteristic;
|
||||||
|
StatusLowBattery: Characteristic;
|
||||||
|
StatusTampered: Characteristic;
|
||||||
|
StreamingStatus: Characteristic;
|
||||||
|
SulphurDioxideDensity: Characteristic;
|
||||||
|
SupportedAudioStreamConfiguration: Characteristic;
|
||||||
|
SupportedRTPConfiguration: Characteristic;
|
||||||
|
SupportedVideoStreamConfiguration: Characteristic;
|
||||||
|
SwingMode: Characteristic;
|
||||||
|
TargetAirPurifierState: Characteristic;
|
||||||
|
TargetAirQuality: Characteristic;
|
||||||
|
TargetDoorState: Characteristic;
|
||||||
|
TargetFanState: Characteristic;
|
||||||
|
TargetHeaterCoolerState: Characteristic;
|
||||||
|
TargetHeatingCoolingState: Characteristic;
|
||||||
|
TargetHorizontalTiltAngle: Characteristic;
|
||||||
|
TargetHumidifierDehumidifierState: Characteristic;
|
||||||
|
TargetMediaState: Characteristic;
|
||||||
|
TargetPosition: Characteristic;
|
||||||
|
TargetRelativeHumidity: Characteristic;
|
||||||
|
TargetSlatState: Characteristic;
|
||||||
|
TargetTemperature: Characteristic;
|
||||||
|
TargetTiltAngle: Characteristic;
|
||||||
|
TargetVerticalTiltAngle: Characteristic;
|
||||||
|
TargetVisibilityState: Characteristic;
|
||||||
|
TemperatureDisplayUnits: Characteristic;
|
||||||
|
TimeUpdate: Characteristic;
|
||||||
|
TunnelConnectionTimeout: Characteristic;
|
||||||
|
TunneledAccessoryAdvertising: Characteristic;
|
||||||
|
TunneledAccessoryConnected: Characteristic;
|
||||||
|
TunneledAccessoryStateNumber: Characteristic;
|
||||||
|
VOCDensity: Characteristic;
|
||||||
|
ValveType: Characteristic;
|
||||||
|
Version: Characteristic;
|
||||||
|
Volume: Characteristic;
|
||||||
|
VolumeControlType: Characteristic;
|
||||||
|
VolumeSelector: Characteristic;
|
||||||
|
WaterLevel: Characteristic;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module Characteristic {
|
||||||
|
export enum Formats {
|
||||||
|
BOOL,
|
||||||
|
INT,
|
||||||
|
FLOAT,
|
||||||
|
STRING,
|
||||||
|
ARRAY, // unconfirmed
|
||||||
|
DICTIONARY, // unconfirmed
|
||||||
|
UINT8,
|
||||||
|
UINT16,
|
||||||
|
UINT32,
|
||||||
|
UINT64,
|
||||||
|
DATA, // unconfirmed
|
||||||
|
TLV8
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Units {
|
||||||
|
// HomeKit only defines Celsius, for Fahrenheit, it requires iOS app to do the conversion.
|
||||||
|
CELSIUS,
|
||||||
|
PERCENTAGE,
|
||||||
|
ARC_DEGREE,
|
||||||
|
LUX,
|
||||||
|
SECONDS
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Perms {
|
||||||
|
READ,
|
||||||
|
WRITE,
|
||||||
|
NOTIFY,
|
||||||
|
HIDDEN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PublishInfo {
|
||||||
|
port: number;
|
||||||
|
username: string;
|
||||||
|
pincode: string;
|
||||||
|
category: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Accessory extends IEventEmitterAccessory {
|
||||||
|
new(displayName: string, UUID: string): Accessory;
|
||||||
|
displayName: string;
|
||||||
|
username: string;
|
||||||
|
pincode: string;
|
||||||
|
UUID: string;
|
||||||
|
aid: string;
|
||||||
|
bridged: boolean;
|
||||||
|
bridgedAccessories: Accessory[];
|
||||||
|
reachable: boolean;
|
||||||
|
category: Accessory.Categories;
|
||||||
|
services: Service[];
|
||||||
|
cameraSource: CameraSource;
|
||||||
|
Categories: typeof Accessory.Categories
|
||||||
|
addService(service: Service | Function): Service;
|
||||||
|
removeService(service: Service): void;
|
||||||
|
getService(name: string | Function): Service;
|
||||||
|
updateReachability(reachable: boolean): void;
|
||||||
|
addBridgedAccessory(accessory: Accessory, deferUpdate: boolean): Accessory;
|
||||||
|
addBridgedAccessories(accessories: Accessory[]): void
|
||||||
|
removeBridgedAccessory(accessory: Accessory, deferUpdate: boolean): void;
|
||||||
|
removeBridgedAccessories(accessories: Accessory[]): void;
|
||||||
|
getCharacteristicByIID(iid: string): Characteristic;
|
||||||
|
getBridgedAccessoryByAID(aid: string): Accessory;
|
||||||
|
findCharacteristic(aid: string, iid: string): Accessory;
|
||||||
|
configureCameraSource(cameraSource: CameraSource): void;
|
||||||
|
toHAP(opt: any): JSON;
|
||||||
|
publish(info: PublishInfo, allowInsecureRequest: boolean): void;
|
||||||
|
destroy(): void;
|
||||||
|
setupURI(): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
module Accessory {
|
||||||
|
export enum Categories {
|
||||||
|
OTHER = 1,
|
||||||
|
BRIDGE = 2,
|
||||||
|
FAN = 3,
|
||||||
|
GARAGE_DOOR_OPENER = 4,
|
||||||
|
LIGHTBULB = 5,
|
||||||
|
DOOR_LOCK = 6,
|
||||||
|
OUTLET = 7,
|
||||||
|
SWITCH = 8,
|
||||||
|
THERMOSTAT = 9,
|
||||||
|
SENSOR = 10,
|
||||||
|
ALARM_SYSTEM = 11,
|
||||||
|
SECURITY_SYSTEM = 11,
|
||||||
|
DOOR = 12,
|
||||||
|
WINDOW = 13,
|
||||||
|
WINDOW_COVERING = 14,
|
||||||
|
PROGRAMMABLE_SWITCH = 15,
|
||||||
|
RANGE_EXTENDER = 16,
|
||||||
|
CAMERA = 17,
|
||||||
|
IP_CAMERA = 17,
|
||||||
|
VIDEO_DOORBELL = 18,
|
||||||
|
AIR_PURIFIER = 19,
|
||||||
|
AIR_HEATER = 20,
|
||||||
|
AIR_CONDITIONER = 21,
|
||||||
|
AIR_HUMIDIFIER = 22,
|
||||||
|
AIR_DEHUMIDIFIER = 23,
|
||||||
|
APPLE_TV = 24,
|
||||||
|
SPEAKER = 26,
|
||||||
|
AIRPORT = 27,
|
||||||
|
SPRINKLER = 28,
|
||||||
|
FAUCET = 29,
|
||||||
|
SHOWER_HEAD = 30,
|
||||||
|
TELEVISION = 31,
|
||||||
|
TARGET_CONTROLLER = 32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HAPNodeJS {
|
||||||
|
init(storagePath?: string): void,
|
||||||
|
uuid: uuid,
|
||||||
|
Accessory: Accessory,
|
||||||
|
Service: Service,
|
||||||
|
Characteristic: Characteristic
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
declare var hapNodeJS: HAPNodeJS.HAPNodeJS;
|
||||||
|
|
||||||
|
declare module "hap-nodejs" {
|
||||||
|
export = hapNodeJS;
|
||||||
|
}
|
103
src/index.ts
103
src/index.ts
@ -1,22 +1,111 @@
|
|||||||
|
import { ControlUnit } from "./Accessories/ControlUnit";
|
||||||
let Service: any, Characteristic: any;
|
import { Activity } from "./Models/Activity";
|
||||||
|
import { DeviceSetupItem } from "./Models/DeviceSetupItem";
|
||||||
|
import { Input, Output, Matrix } from "./Models/Matrix";
|
||||||
|
|
||||||
export default function (homebridge: any) {
|
export default function (homebridge: any) {
|
||||||
Service = homebridge.hap.Service;
|
|
||||||
Characteristic = homebridge.hap.Characteristic;
|
|
||||||
|
|
||||||
homebridge.registerPlatform(
|
homebridge.registerPlatform(
|
||||||
'homebridge-harmony-watson',
|
'homebridge-harmony-watson',
|
||||||
'HarmonyHubMatrix',
|
'HarmonyHubMatrix',
|
||||||
HarmonyMatrixPlatform
|
HarmonyMatrixPlatform,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
class HarmonyMatrixPlatform {
|
class HarmonyMatrixPlatform {
|
||||||
log: any = {};
|
log: any = {};
|
||||||
|
config: any = {};
|
||||||
|
api: any;
|
||||||
|
|
||||||
constructor(log: any, config: any) {
|
constructor(log: any, config: any, api: any) {
|
||||||
|
this.log = log;
|
||||||
|
this.config = config;
|
||||||
|
this.api = api;
|
||||||
this.log('INFO - Registering Harmony Matrix Platform');
|
this.log('INFO - Registering Harmony Matrix Platform');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by homebridge to gather accessories.
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
accessories(callback: (accessories: Array<ControlUnit>) => void) {
|
||||||
|
//Parse matrix
|
||||||
|
let configInputs: any = this.config["Matrix"]["Inputs"];
|
||||||
|
let configOutputs: any = this.config["Matrix"]["Outputs"];
|
||||||
|
let inputs: Array<Input> = [];
|
||||||
|
let outputs: Array<Output> = [];
|
||||||
|
|
||||||
|
configInputs.forEach((configInput: any) => {
|
||||||
|
let inputDevice: string = configInput["InputDevice"];
|
||||||
|
let inputNumber: string = configInput["InputNumber"];
|
||||||
|
|
||||||
|
this.log(`INFO - Added input to matrix '${inputDevice}'`);
|
||||||
|
|
||||||
|
inputs.push({
|
||||||
|
inputDevice: inputDevice,
|
||||||
|
inputNumber: inputNumber
|
||||||
|
});
|
||||||
|
});
|
||||||
|
configOutputs.forEach((configOutput: any) => {
|
||||||
|
let outputDevice: string = configOutput["OutputDevice"];
|
||||||
|
let outputLetter: string = configOutput["OutputLetter"];
|
||||||
|
|
||||||
|
this.log(`INFO - Added output to matrix '${outputDevice}'`);
|
||||||
|
|
||||||
|
outputs.push({
|
||||||
|
outputDevice: outputDevice,
|
||||||
|
outputLetter: outputLetter
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
let matrix = new Matrix({
|
||||||
|
inputs: inputs,
|
||||||
|
outputs: outputs,
|
||||||
|
});
|
||||||
|
|
||||||
|
//Parse control units
|
||||||
|
let configControlUnits: any = this.config["ControlUnits"];
|
||||||
|
let controlUnits: Array<ControlUnit> = [];
|
||||||
|
configControlUnits.forEach((configControlUnit: any) => {
|
||||||
|
//Parse activities list
|
||||||
|
let configActivities: any = configControlUnit["Activities"];
|
||||||
|
let activities: Array<Activity> = [];
|
||||||
|
configActivities.forEach((configActivity: any) => {
|
||||||
|
//parse devices
|
||||||
|
let configDevices: any = configActivity["DeviceSetupList"];
|
||||||
|
let devices: Array<DeviceSetupItem> = [];
|
||||||
|
configDevices.forEach((configDevice: any) => {
|
||||||
|
//Add device
|
||||||
|
devices.push(new DeviceSetupItem({
|
||||||
|
deviceId: configDevice["DeviceName"],
|
||||||
|
input: configDevice["Input"]
|
||||||
|
}));
|
||||||
|
this.log(`INFO - Added device '${configDevice["DeviceName"]}' for activity '${configActivity["DisplayName"]}'`);
|
||||||
|
});
|
||||||
|
|
||||||
|
//Add activity
|
||||||
|
activities.push(new Activity({
|
||||||
|
volumeDeviceId: configActivity["VolumeDevice"],
|
||||||
|
controlDeviceId: configActivity["ControlDevice"],
|
||||||
|
outputDeviceId: configActivity["OutputDevice"],
|
||||||
|
displayName: configActivity["DisplayName"],
|
||||||
|
useMatrix: configActivity["UseMatrix"],
|
||||||
|
deviceList: devices
|
||||||
|
}));
|
||||||
|
this.log(`INFO - Added activity '${configActivity["DisplayName"]}'`);
|
||||||
|
});
|
||||||
|
|
||||||
|
//Add control unit
|
||||||
|
controlUnits.push(new ControlUnit({
|
||||||
|
displayName: configControlUnit["DisplayName"],
|
||||||
|
api: this.api,
|
||||||
|
log: this.log,
|
||||||
|
activities: activities,
|
||||||
|
matrix: matrix,
|
||||||
|
}));
|
||||||
|
this.log(`INFO - Added ControlUnit`);
|
||||||
|
});
|
||||||
|
callback(controlUnits);
|
||||||
}
|
}
|
||||||
}
|
}
|
12
tslint.json
Normal file
12
tslint.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"defaultSeverity": "error",
|
||||||
|
"extends": [
|
||||||
|
"tslint:recommended"
|
||||||
|
],
|
||||||
|
"jsRules": {
|
||||||
|
"ordered-imports": false,
|
||||||
|
"semicolon": true,
|
||||||
|
},
|
||||||
|
"rules": {},
|
||||||
|
"rulesDirectory": []
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user