Added information service
This commit is contained in:
parent
0b08302656
commit
b004e3a966
@ -40,24 +40,21 @@ export interface IControlUnitProps {
|
||||
* ControlUnit accessory
|
||||
*/
|
||||
export class ControlUnit implements IAccessory {
|
||||
//Required by homebridge
|
||||
name: string = "";
|
||||
|
||||
|
||||
//fields
|
||||
private log: any = {};
|
||||
private displayName: string = "";
|
||||
|
||||
//Service fields
|
||||
private televisionService: HAPNodeJS.Service | undefined;
|
||||
private televisionSpeakerService: HAPNodeJS.Service | undefined;
|
||||
private informationService: HAPNodeJS.Service | undefined;
|
||||
private inputServices: Array<HAPNodeJS.Service | undefined> = [];
|
||||
private _televisionService: HAPNodeJS.Service | undefined;
|
||||
private _televisionSpeakerService: HAPNodeJS.Service | undefined;
|
||||
private _infoService: HAPNodeJS.Service;
|
||||
private _inputServices: Array<HAPNodeJS.Service | undefined> = [];
|
||||
|
||||
//Harmony fields
|
||||
private activities: Array<Config.IActivity> = [];
|
||||
private dataProvider: HarmonyDataProvider;
|
||||
|
||||
public platformAccessory: any;
|
||||
private _activities: Array<Config.IActivity> = [];
|
||||
private _dataProvider: HarmonyDataProvider;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -72,13 +69,19 @@ export class ControlUnit implements IAccessory {
|
||||
this.name = props.displayName;
|
||||
this.displayName = props.displayName;
|
||||
|
||||
this.activities = props.activities;
|
||||
this._activities = props.activities;
|
||||
|
||||
this.dataProvider = props.dataProvider;
|
||||
this._dataProvider = props.dataProvider;
|
||||
homebridge = props.homebridge;
|
||||
|
||||
this.platformAccessory = new homebridge.platformAccessory(this.displayName, this.generateUUID(), homebridge.hap.Accessory.Categories.TELEVISION);
|
||||
|
||||
//@ts-ignore
|
||||
this._infoService = new Service.AccessoryInformation();
|
||||
this._infoService.setCharacteristic(Characteristic.Manufacturer, "Brandon Watson")
|
||||
this._infoService.setCharacteristic(Characteristic.Model, "Matrix Output Television")
|
||||
this._infoService.setCharacteristic(Characteristic.SerialNumber, "123-456-789");
|
||||
|
||||
//Configure services
|
||||
this.configureTvService();
|
||||
|
||||
@ -97,10 +100,15 @@ export class ControlUnit implements IAccessory {
|
||||
//@ts-ignore
|
||||
if (service.linked) {
|
||||
//@ts-ignore
|
||||
this.televisionService!.addLinkedService(service);
|
||||
this._televisionService!.addLinkedService(service);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//Required by homebridge
|
||||
name: string = "";
|
||||
public platformAccessory: any;
|
||||
|
||||
/*************
|
||||
*
|
||||
* Tv Service
|
||||
@ -111,31 +119,31 @@ export class ControlUnit implements IAccessory {
|
||||
* Configure television service
|
||||
*/
|
||||
private configureTvService(): void {
|
||||
this.televisionService = new Service.Television(
|
||||
this._televisionService = new Service.Television(
|
||||
this.displayName,
|
||||
'tvService'
|
||||
)
|
||||
|
||||
this.televisionService.setCharacteristic(Characteristic.ConfiguredName, this.displayName);
|
||||
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);
|
||||
this._televisionService.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
|
||||
this._televisionService.setCharacteristic(Characteristic.ActiveIdentifier, 1);
|
||||
this._televisionService.setCharacteristic(Characteristic.Active, false);
|
||||
|
||||
//setup listeners
|
||||
this.televisionService.getCharacteristic(Characteristic.Active)
|
||||
this._televisionService.getCharacteristic(Characteristic.Active)
|
||||
//@ts-ignore
|
||||
.on("set", callbackify(this.onSetAccessoryActive))
|
||||
//@ts-ignore
|
||||
.on("get", callbackify(this.onGetAccessoryActive));
|
||||
|
||||
//Set remote characteristics if is external
|
||||
this.televisionService.getCharacteristic(Characteristic.RemoteKey)
|
||||
this._televisionService.getCharacteristic(Characteristic.RemoteKey)
|
||||
//@ts-ignore
|
||||
.on("set", callbackify(this.onSetRemoteKey));
|
||||
|
||||
|
||||
this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
|
||||
this._televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
|
||||
//@ts-ignore
|
||||
.on("set", callbackify(this.onSetActiveIdentifier))
|
||||
//@ts-ignore
|
||||
@ -147,9 +155,9 @@ export class ControlUnit implements IAccessory {
|
||||
*/
|
||||
private onSetAccessoryActive = async (value: any) => {
|
||||
switch (value) {
|
||||
case 0: this.dataProvider.powerOff(this.name); break;
|
||||
case 0: this._dataProvider.powerOff(this.name); break;
|
||||
//Turn on with first activity
|
||||
case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break;
|
||||
case 1: this._dataProvider.powerOn(this.name, this._activities[0]); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,31 +166,31 @@ export class ControlUnit implements IAccessory {
|
||||
*/
|
||||
private onGetAccessoryActive = async () => {
|
||||
//@ts-ignore
|
||||
return this.dataProvider.getIsActive(this.name) ? Characteristic.Active.Active : Characteristic.Active.Inactive
|
||||
return this._dataProvider.getIsActive(this.name) ? Characteristic.Active.Active : Characteristic.Active.Inactive
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for SET remote key
|
||||
*/
|
||||
private onSetRemoteKey = async (key: any) => {
|
||||
this.dataProvider.sendKeyPress(this.name, key);
|
||||
this._dataProvider.sendKeyPress(this.name, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for SET active identifier characteristic
|
||||
*/
|
||||
private onSetActiveIdentifier = async (identifier: any) => {
|
||||
this.dataProvider.startActivity(this.name, this.activities[identifier]);
|
||||
this._dataProvider.startActivity(this.name, this._activities[identifier]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for GET active identifier characteristic
|
||||
*/
|
||||
private onGetActiveIdentifier = async () => {
|
||||
let currentActivity: Config.IActivity = this.dataProvider.getIsActive(this.name)!;
|
||||
let currentActivity: Config.IActivity = this._dataProvider.getIsActive(this.name)!;
|
||||
let identifier: number = 0;
|
||||
if (currentActivity) {
|
||||
identifier = this.activities.findIndex(e => e.DisplayName === currentActivity.DisplayName);
|
||||
identifier = this._activities.findIndex(e => e.DisplayName === currentActivity.DisplayName);
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
@ -197,23 +205,23 @@ export class ControlUnit implements IAccessory {
|
||||
* Configure Speaker Service
|
||||
*/
|
||||
private configureTvSpeakerService(): void {
|
||||
this.televisionSpeakerService = new Service.TelevisionSpeaker(
|
||||
this._televisionSpeakerService = new Service.TelevisionSpeaker(
|
||||
this.displayName,
|
||||
'tvSpeakerService'
|
||||
);
|
||||
this.televisionSpeakerService.setCharacteristic(Characteristic.Name, this.displayName);
|
||||
this._televisionSpeakerService.setCharacteristic(Characteristic.Name, this.displayName);
|
||||
//@ts-ignore
|
||||
this.televisionSpeakerService.setCharacteristic(Characteristic.Active, Characteristic.Active.ACTIVE);
|
||||
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) {
|
||||
this._televisionSpeakerService.setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.ABSOLUTE);
|
||||
this._televisionSpeakerService.subtype = this.displayName + "Volume";
|
||||
if (this._televisionService) {
|
||||
//@ts-ignore
|
||||
this.televisionService.addLinkedService(this.televisionSpeakerService);
|
||||
this._televisionService.addLinkedService(this._televisionSpeakerService);
|
||||
}
|
||||
|
||||
//Setup listeners
|
||||
this.televisionSpeakerService.getCharacteristic(Characteristic.VolumeSelector)
|
||||
this._televisionSpeakerService.getCharacteristic(Characteristic.VolumeSelector)
|
||||
//@ts-ignore
|
||||
.on("set", callbackify(this.onSetVolumeSelector));
|
||||
}
|
||||
@ -223,8 +231,8 @@ export class ControlUnit implements IAccessory {
|
||||
*/
|
||||
private onSetVolumeSelector = async (value: any) => {
|
||||
switch (value) {
|
||||
case 0: this.dataProvider.volumeUp(this.name); break;
|
||||
case 1: this.dataProvider.volumeDown(this.name); break;
|
||||
case 0: this._dataProvider.volumeUp(this.name); break;
|
||||
case 1: this._dataProvider.volumeDown(this.name); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,7 +247,7 @@ export class ControlUnit implements IAccessory {
|
||||
*/
|
||||
private configureInputSourceService(): void {
|
||||
let inputs: Array<HAPNodeJS.Service> = [];
|
||||
this.activities.forEach((activity: Config.IActivity, index: number) => {
|
||||
this._activities.forEach((activity: Config.IActivity, index: number) => {
|
||||
let inputService = new Service.InputSource(activity.DisplayName, 'activity' + activity.DisplayName);
|
||||
inputService
|
||||
.setCharacteristic(Characteristic.Identifier, index)
|
||||
@ -255,10 +263,10 @@ export class ControlUnit implements IAccessory {
|
||||
.setCharacteristic(Characteristic.InputSourceType, Characteristic.InputSourceType.HDMI);
|
||||
|
||||
//@ts-ignore
|
||||
this.televisionService!.addLinkedService(inputService);
|
||||
this._televisionService!.addLinkedService(inputService);
|
||||
inputs.push(inputService);
|
||||
});
|
||||
this.inputServices = inputs;
|
||||
this._inputServices = inputs;
|
||||
}
|
||||
|
||||
private generateUUID(): string { // Public Domain/MIT
|
||||
@ -277,8 +285,8 @@ export class ControlUnit implements IAccessory {
|
||||
* Called by homebridge to gather services for this accessory.
|
||||
*/
|
||||
getServices(): Array<HAPNodeJS.Service> {
|
||||
let services: Array<HAPNodeJS.Service> = [this.televisionService!, this.televisionSpeakerService!];
|
||||
this.inputServices.forEach((service: HAPNodeJS.Service | undefined) => {
|
||||
let services: Array<HAPNodeJS.Service> = [this._infoService, this._televisionService!, this._televisionSpeakerService!];
|
||||
this._inputServices.forEach((service: HAPNodeJS.Service | undefined) => {
|
||||
services.push(service!);
|
||||
});
|
||||
return (services);
|
||||
|
@ -33,16 +33,12 @@ export class DeviceButton implements IAccessory {
|
||||
|
||||
private _buttonState: boolean;
|
||||
|
||||
private _buttonName: string;
|
||||
|
||||
|
||||
constructor(props: IDeviceButtonProps) {
|
||||
//Assign class variables
|
||||
this._log = props.log;
|
||||
this._api = props.api;
|
||||
Service = props.api.hap.Service;
|
||||
Characteristic = props.api.hap.Characteristic;
|
||||
this._buttonName = props.buttonName;
|
||||
this.name = props.displayName;
|
||||
this._homebridge = props.homebridge;
|
||||
|
||||
@ -56,7 +52,7 @@ export class DeviceButton implements IAccessory {
|
||||
|
||||
//@ts-ignore
|
||||
this._infoService = new Service.AccessoryInformation();
|
||||
this._infoService.setCharacteristic(Characteristic.Manufacturer, "The Watson Project")
|
||||
this._infoService.setCharacteristic(Characteristic.Manufacturer, "Brandon Watson")
|
||||
this._infoService.setCharacteristic(Characteristic.Model, "Device Button")
|
||||
this._infoService.setCharacteristic(Characteristic.SerialNumber, "123-456-789");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user