External devices (remote control support) building blocks added.

This commit is contained in:
watsonb8
2019-06-16 21:12:57 -04:00
parent 06fb2009bc
commit e49af64a18
2 changed files with 66 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import HarmonyDataProvider from '../DataProviders/HarmonyDataProvider';
let Service: HAPNodeJS.Service;
let Characteristic: HAPNodeJS.Characteristic;
let Api: any;
let homebridge: any;
export interface IControlUnitProps {
dataProvider: HarmonyDataProvider,
@@ -14,6 +15,7 @@ export interface IControlUnitProps {
activities: Array<Activity>,
api: any,
log: any,
homebridge: any,
}
/**
@@ -37,6 +39,8 @@ export class ControlUnit implements IAccessory {
private activities: Array<Activity> = [];
private dataProvider: HarmonyDataProvider;
public platformAccessory: any;
/**
* Constructor
* @param props Input properties
@@ -53,12 +57,28 @@ export class ControlUnit implements IAccessory {
this.activities = props.activities;
this.dataProvider = props.dataProvider;
homebridge = props.homebridge;
this.platformAccessory = new homebridge.platformAccessory(this.name, this.generateUUID(), homebridge.hap.Accessory.Categories.TELEVISION);
//Configure services
this.configureTvService();
this.configureTvSpeakerService();
// this.configureAccessoryInformation();
this.configureInputSourceService();
//Configure external services
this.getServices().forEach(service => {
try {
this.platformAccessory.addService(service);
} catch (error) { }
//@ts-ignore
if (service.linked) {
//@ts-ignore
this.televisionService!.addLinkedService(service);
}
});
}
/*************
*
@@ -106,6 +126,7 @@ export class ControlUnit implements IAccessory {
this.log(`set active + ${value}`);
switch (value) {
case 0: this.dataProvider.powerOff(this.name); break;
//Turn on with first activity
case 1: this.dataProvider.powerOn(this.name, this.activities[0]); break;
}
}
@@ -162,9 +183,9 @@ export class ControlUnit implements IAccessory {
);
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.setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.ABSOLUTE);
this.televisionSpeakerService.subtype = this.displayName + "Volume";
if (this.televisionService) {
//@ts-ignore
@@ -232,6 +253,18 @@ export class ControlUnit implements IAccessory {
this.inputServices = inputs;
}
private generateUUID(): string { // Public Domain/MIT
var d = new Date().getTime();
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
d += performance.now(); //use high-precision timer if available
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}
/**