Compiles and runs. Devices appearing in home kit.

This commit is contained in:
watsonb8
2019-06-14 23:41:13 -04:00
parent 356589b1fe
commit 39bf619b3a
12 changed files with 2030 additions and 28 deletions

View 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!]);
}
}

View File

@@ -0,0 +1,10 @@
export interface IAccessory {
/**
* Required by homebridge.
*/
name: string,
/**
* Called by homebridge to gather services.
*/
getServices(): Array<HAPNodeJS.Service>,
}