Added information service

This commit is contained in:
watsonb8 2020-01-03 16:26:55 -05:00
parent 0b08302656
commit b004e3a966
2 changed files with 52 additions and 48 deletions

View File

@ -40,24 +40,21 @@ export interface IControlUnitProps {
* ControlUnit accessory * ControlUnit accessory
*/ */
export class ControlUnit implements IAccessory { export class ControlUnit implements IAccessory {
//Required by homebridge
name: string = "";
//fields //fields
private log: any = {}; private log: any = {};
private displayName: string = ""; private displayName: string = "";
//Service fields //Service fields
private televisionService: HAPNodeJS.Service | undefined; private _televisionService: HAPNodeJS.Service | undefined;
private televisionSpeakerService: HAPNodeJS.Service | undefined; private _televisionSpeakerService: HAPNodeJS.Service | undefined;
private informationService: HAPNodeJS.Service | undefined; private _infoService: HAPNodeJS.Service;
private inputServices: Array<HAPNodeJS.Service | undefined> = []; private _inputServices: Array<HAPNodeJS.Service | undefined> = [];
//Harmony fields //Harmony fields
private activities: Array<Config.IActivity> = []; private _activities: Array<Config.IActivity> = [];
private dataProvider: HarmonyDataProvider; private _dataProvider: HarmonyDataProvider;
public platformAccessory: any;
/** /**
* Constructor * Constructor
@ -72,13 +69,19 @@ export class ControlUnit implements IAccessory {
this.name = props.displayName; this.name = props.displayName;
this.displayName = 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; homebridge = props.homebridge;
this.platformAccessory = new homebridge.platformAccessory(this.displayName, this.generateUUID(), homebridge.hap.Accessory.Categories.TELEVISION); 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 //Configure services
this.configureTvService(); this.configureTvService();
@ -97,10 +100,15 @@ export class ControlUnit implements IAccessory {
//@ts-ignore //@ts-ignore
if (service.linked) { if (service.linked) {
//@ts-ignore //@ts-ignore
this.televisionService!.addLinkedService(service); this._televisionService!.addLinkedService(service);
} }
}); });
} }
//Required by homebridge
name: string = "";
public platformAccessory: any;
/************* /*************
* *
* Tv Service * Tv Service
@ -111,31 +119,31 @@ export class ControlUnit implements IAccessory {
* Configure television service * Configure television service
*/ */
private configureTvService(): void { private configureTvService(): void {
this.televisionService = new Service.Television( this._televisionService = new Service.Television(
this.displayName, this.displayName,
'tvService' 'tvService'
) )
this.televisionService.setCharacteristic(Characteristic.ConfiguredName, this.displayName); this._televisionService.setCharacteristic(Characteristic.ConfiguredName, this.displayName);
//@ts-ignore //@ts-ignore
this.televisionService.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE); this._televisionService.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
this.televisionService.setCharacteristic(Characteristic.ActiveIdentifier, 1); this._televisionService.setCharacteristic(Characteristic.ActiveIdentifier, 1);
this.televisionService.setCharacteristic(Characteristic.Active, false); this._televisionService.setCharacteristic(Characteristic.Active, false);
//setup listeners //setup listeners
this.televisionService.getCharacteristic(Characteristic.Active) this._televisionService.getCharacteristic(Characteristic.Active)
//@ts-ignore //@ts-ignore
.on("set", callbackify(this.onSetAccessoryActive)) .on("set", callbackify(this.onSetAccessoryActive))
//@ts-ignore //@ts-ignore
.on("get", callbackify(this.onGetAccessoryActive)); .on("get", callbackify(this.onGetAccessoryActive));
//Set remote characteristics if is external //Set remote characteristics if is external
this.televisionService.getCharacteristic(Characteristic.RemoteKey) this._televisionService.getCharacteristic(Characteristic.RemoteKey)
//@ts-ignore //@ts-ignore
.on("set", callbackify(this.onSetRemoteKey)); .on("set", callbackify(this.onSetRemoteKey));
this.televisionService.getCharacteristic(Characteristic.ActiveIdentifier) this._televisionService.getCharacteristic(Characteristic.ActiveIdentifier)
//@ts-ignore //@ts-ignore
.on("set", callbackify(this.onSetActiveIdentifier)) .on("set", callbackify(this.onSetActiveIdentifier))
//@ts-ignore //@ts-ignore
@ -147,9 +155,9 @@ export class ControlUnit implements IAccessory {
*/ */
private onSetAccessoryActive = async (value: any) => { private onSetAccessoryActive = async (value: any) => {
switch (value) { switch (value) {
case 0: this.dataProvider.powerOff(this.name); break; case 0: this._dataProvider.powerOff(this.name); break;
//Turn on with first activity //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 () => { private onGetAccessoryActive = async () => {
//@ts-ignore //@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 * Event handler for SET remote key
*/ */
private onSetRemoteKey = async (key: any) => { private onSetRemoteKey = async (key: any) => {
this.dataProvider.sendKeyPress(this.name, key); this._dataProvider.sendKeyPress(this.name, key);
} }
/** /**
* Event handler for SET active identifier characteristic * Event handler for SET active identifier characteristic
*/ */
private onSetActiveIdentifier = async (identifier: any) => { 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 * Event handler for GET active identifier characteristic
*/ */
private onGetActiveIdentifier = async () => { 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; let identifier: number = 0;
if (currentActivity) { if (currentActivity) {
identifier = this.activities.findIndex(e => e.DisplayName === currentActivity.DisplayName); identifier = this._activities.findIndex(e => e.DisplayName === currentActivity.DisplayName);
} }
return identifier; return identifier;
} }
@ -197,23 +205,23 @@ export class ControlUnit implements IAccessory {
* Configure Speaker Service * Configure Speaker Service
*/ */
private configureTvSpeakerService(): void { private configureTvSpeakerService(): void {
this.televisionSpeakerService = new Service.TelevisionSpeaker( this._televisionSpeakerService = new Service.TelevisionSpeaker(
this.displayName, this.displayName,
'tvSpeakerService' 'tvSpeakerService'
); );
this.televisionSpeakerService.setCharacteristic(Characteristic.Name, this.displayName); this._televisionSpeakerService.setCharacteristic(Characteristic.Name, this.displayName);
//@ts-ignore //@ts-ignore
this.televisionSpeakerService.setCharacteristic(Characteristic.Active, Characteristic.Active.ACTIVE); this._televisionSpeakerService.setCharacteristic(Characteristic.Active, Characteristic.Active.ACTIVE);
//@ts-ignore //@ts-ignore
this.televisionSpeakerService.setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.ABSOLUTE); this._televisionSpeakerService.setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.ABSOLUTE);
this.televisionSpeakerService.subtype = this.displayName + "Volume"; this._televisionSpeakerService.subtype = this.displayName + "Volume";
if (this.televisionService) { if (this._televisionService) {
//@ts-ignore //@ts-ignore
this.televisionService.addLinkedService(this.televisionSpeakerService); this._televisionService.addLinkedService(this._televisionSpeakerService);
} }
//Setup listeners //Setup listeners
this.televisionSpeakerService.getCharacteristic(Characteristic.VolumeSelector) this._televisionSpeakerService.getCharacteristic(Characteristic.VolumeSelector)
//@ts-ignore //@ts-ignore
.on("set", callbackify(this.onSetVolumeSelector)); .on("set", callbackify(this.onSetVolumeSelector));
} }
@ -223,8 +231,8 @@ export class ControlUnit implements IAccessory {
*/ */
private onSetVolumeSelector = async (value: any) => { private onSetVolumeSelector = async (value: any) => {
switch (value) { switch (value) {
case 0: this.dataProvider.volumeUp(this.name); break; case 0: this._dataProvider.volumeUp(this.name); break;
case 1: this.dataProvider.volumeDown(this.name); break; case 1: this._dataProvider.volumeDown(this.name); break;
} }
} }
@ -239,7 +247,7 @@ export class ControlUnit implements IAccessory {
*/ */
private configureInputSourceService(): void { private configureInputSourceService(): void {
let inputs: Array<HAPNodeJS.Service> = []; 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); let inputService = new Service.InputSource(activity.DisplayName, 'activity' + activity.DisplayName);
inputService inputService
.setCharacteristic(Characteristic.Identifier, index) .setCharacteristic(Characteristic.Identifier, index)
@ -255,10 +263,10 @@ export class ControlUnit implements IAccessory {
.setCharacteristic(Characteristic.InputSourceType, Characteristic.InputSourceType.HDMI); .setCharacteristic(Characteristic.InputSourceType, Characteristic.InputSourceType.HDMI);
//@ts-ignore //@ts-ignore
this.televisionService!.addLinkedService(inputService); this._televisionService!.addLinkedService(inputService);
inputs.push(inputService); inputs.push(inputService);
}); });
this.inputServices = inputs; this._inputServices = inputs;
} }
private generateUUID(): string { // Public Domain/MIT private generateUUID(): string { // Public Domain/MIT
@ -277,8 +285,8 @@ export class ControlUnit implements IAccessory {
* Called by homebridge to gather services for this accessory. * Called by homebridge to gather services for this accessory.
*/ */
getServices(): Array<HAPNodeJS.Service> { getServices(): Array<HAPNodeJS.Service> {
let services: Array<HAPNodeJS.Service> = [this.televisionService!, this.televisionSpeakerService!]; let services: Array<HAPNodeJS.Service> = [this._infoService, this._televisionService!, this._televisionSpeakerService!];
this.inputServices.forEach((service: HAPNodeJS.Service | undefined) => { this._inputServices.forEach((service: HAPNodeJS.Service | undefined) => {
services.push(service!); services.push(service!);
}); });
return (services); return (services);

View File

@ -33,16 +33,12 @@ export class DeviceButton implements IAccessory {
private _buttonState: boolean; private _buttonState: boolean;
private _buttonName: string;
constructor(props: IDeviceButtonProps) { constructor(props: IDeviceButtonProps) {
//Assign class variables //Assign class variables
this._log = props.log; this._log = props.log;
this._api = props.api; this._api = props.api;
Service = props.api.hap.Service; Service = props.api.hap.Service;
Characteristic = props.api.hap.Characteristic; Characteristic = props.api.hap.Characteristic;
this._buttonName = props.buttonName;
this.name = props.displayName; this.name = props.displayName;
this._homebridge = props.homebridge; this._homebridge = props.homebridge;
@ -56,7 +52,7 @@ export class DeviceButton implements IAccessory {
//@ts-ignore //@ts-ignore
this._infoService = new Service.AccessoryInformation(); 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.Model, "Device Button")
this._infoService.setCharacteristic(Characteristic.SerialNumber, "123-456-789"); this._infoService.setCharacteristic(Characteristic.SerialNumber, "123-456-789");