Correctly working activities :)
This commit is contained in:
parent
a7ae259567
commit
06fb2009bc
120
config.json
120
config.json
@ -53,6 +53,27 @@
|
|||||||
{
|
{
|
||||||
"DisplayName": "Living Room",
|
"DisplayName": "Living Room",
|
||||||
"Activities": [
|
"Activities": [
|
||||||
|
{
|
||||||
|
"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": "Play Xbox One",
|
"DisplayName": "Play Xbox One",
|
||||||
"DeviceSetupList": [
|
"DeviceSetupList": [
|
||||||
@ -81,23 +102,6 @@
|
|||||||
"DeviceName": "Sony PS4",
|
"DeviceName": "Sony PS4",
|
||||||
"Input": []
|
"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",
|
"DeviceName": "LG TV",
|
||||||
"Input": "HDMI1"
|
"Input": "HDMI1"
|
||||||
@ -105,14 +109,10 @@
|
|||||||
{
|
{
|
||||||
"DeviceName": "JVC AV Receiver",
|
"DeviceName": "JVC AV Receiver",
|
||||||
"Input": "DVD"
|
"Input": "DVD"
|
||||||
},
|
|
||||||
{
|
|
||||||
"DeviceName": "Chromecast",
|
|
||||||
"Input": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"VolumeDevice": "JVC AV Receiver",
|
"VolumeDevice": "JVC AV Receiver",
|
||||||
"ControlDevice": "Chromecast",
|
"ControlDevice": "Sony PS4",
|
||||||
"OutputDevice": "LG TV",
|
"OutputDevice": "LG TV",
|
||||||
"UseMatrix": "true"
|
"UseMatrix": "true"
|
||||||
},
|
},
|
||||||
@ -155,6 +155,27 @@
|
|||||||
{
|
{
|
||||||
"DisplayName": "Bedroom",
|
"DisplayName": "Bedroom",
|
||||||
"Activities": [
|
"Activities": [
|
||||||
|
{
|
||||||
|
"DisplayName": "Chromecast",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "Vizio TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "Harman Kardon AV Receiver",
|
||||||
|
"Input": "Game"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "Chromecast",
|
||||||
|
"Input": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Harman Kardon AV Receiver",
|
||||||
|
"ControlDevice": "Chromecast",
|
||||||
|
"OutputDevice": "Vizio TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"DisplayName": "Play Xbox One",
|
"DisplayName": "Play Xbox One",
|
||||||
"DeviceSetupList": [
|
"DeviceSetupList": [
|
||||||
@ -197,27 +218,6 @@
|
|||||||
"OutputDevice": "LG TV",
|
"OutputDevice": "LG TV",
|
||||||
"UseMatrix": "true"
|
"UseMatrix": "true"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"DisplayName": "Chromecast",
|
|
||||||
"DeviceSetupList": [
|
|
||||||
{
|
|
||||||
"DeviceName": "Vizio TV",
|
|
||||||
"Input": "HDMI1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"DeviceName": "Harman Kardon AV Receiver",
|
|
||||||
"Input": "Game"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"DeviceName": "Chromecast",
|
|
||||||
"Input": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"VolumeDevice": "Harman Kardon AV Receiver",
|
|
||||||
"ControlDevice": "Chromecast",
|
|
||||||
"OutputDevice": "Vizio TV",
|
|
||||||
"UseMatrix": "true"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"DisplayName": "Apple TV",
|
"DisplayName": "Apple TV",
|
||||||
"DeviceSetupList": [
|
"DeviceSetupList": [
|
||||||
@ -244,6 +244,23 @@
|
|||||||
{
|
{
|
||||||
"DisplayName": "Kitchen",
|
"DisplayName": "Kitchen",
|
||||||
"Activities": [
|
"Activities": [
|
||||||
|
{
|
||||||
|
"DisplayName": "Chromecast",
|
||||||
|
"DeviceSetupList": [
|
||||||
|
{
|
||||||
|
"DeviceName": "Chromecast",
|
||||||
|
"Input": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeviceName": "Westinghouse TV",
|
||||||
|
"Input": "HDMI1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VolumeDevice": "Westinghouse TV",
|
||||||
|
"ControlDevice": "Chromecast",
|
||||||
|
"OutputDevice": "Westinghouse TV",
|
||||||
|
"UseMatrix": "true"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"DisplayName": "Watch Apple Tv",
|
"DisplayName": "Watch Apple Tv",
|
||||||
"DeviceSetupList": [
|
"DeviceSetupList": [
|
||||||
@ -277,23 +294,6 @@
|
|||||||
"ControlDevice": "Microsoft Xbox One",
|
"ControlDevice": "Microsoft Xbox One",
|
||||||
"OutputDevice": "Westinghouse TV",
|
"OutputDevice": "Westinghouse TV",
|
||||||
"UseMatrix": "true"
|
"UseMatrix": "true"
|
||||||
},
|
|
||||||
{
|
|
||||||
"DisplayName": "Chromecast",
|
|
||||||
"DeviceSetupList": [
|
|
||||||
{
|
|
||||||
"DeviceName": "Chromecast",
|
|
||||||
"Input": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"DeviceName": "Westinghouse TV",
|
|
||||||
"Input": "HDMI1"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"VolumeDevice": "Westinghouse TV",
|
|
||||||
"ControlDevice": "Chromecast",
|
|
||||||
"OutputDevice": "Westinghouse TV",
|
|
||||||
"UseMatrix": "true"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,9 @@ export class ControlUnit implements IAccessory {
|
|||||||
.on("get", callbackify(this.onGetActiveIdentifier));
|
.on("get", callbackify(this.onGetActiveIdentifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
/**
|
||||||
|
* Event handler for SET active characteristic
|
||||||
|
*/
|
||||||
private onSetAccessoryActive = async (value: any) => {
|
private onSetAccessoryActive = async (value: any) => {
|
||||||
this.log(`set active + ${value}`);
|
this.log(`set active + ${value}`);
|
||||||
switch (value) {
|
switch (value) {
|
||||||
@ -108,13 +110,14 @@ export class ControlUnit implements IAccessory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
/**
|
||||||
|
* Event handler for GET active characteristic
|
||||||
|
*/
|
||||||
private onGetAccessoryActive = async () => {
|
private onGetAccessoryActive = async () => {
|
||||||
this.log(`get active`)
|
this.log(`get active`)
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
return this.dataProvider.getIsActive ? Characteristic.Active.Active : Characteristic.Active.Inactive
|
return this.dataProvider.getIsActive ? Characteristic.Active.Active : Characteristic.Active.Inactive
|
||||||
// return Characteristic.Active.Active;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
@ -122,13 +125,25 @@ export class ControlUnit implements IAccessory {
|
|||||||
this.log(`set remote key + ${key}`);
|
this.log(`set remote key + ${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event handler for SET active identifier characteristic
|
||||||
|
*/
|
||||||
private onSetActiveIdentifier = async (identifier: any) => {
|
private onSetActiveIdentifier = async (identifier: any) => {
|
||||||
this.log(`set active identifier + ${identifier}`);
|
this.log(`set active identifier + ${identifier}`);
|
||||||
|
this.dataProvider.startActivity(this.name, this.activities[identifier]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event handler for GET active identifier characteristic
|
||||||
|
*/
|
||||||
private onGetActiveIdentifier = async () => {
|
private onGetActiveIdentifier = async () => {
|
||||||
this.log(`get active identifier`);
|
this.log(`get active identifier`);
|
||||||
return 1;
|
let currentActivity: Activity = this.dataProvider.getIsActive(this.name)!;
|
||||||
|
let identifier: number = 0;
|
||||||
|
if (currentActivity) {
|
||||||
|
identifier = this.activities.findIndex(e => e.displayName === currentActivity.displayName);
|
||||||
|
}
|
||||||
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
|
@ -43,11 +43,9 @@ class HarmonyDataProvider {
|
|||||||
|
|
||||||
//Listeners
|
//Listeners
|
||||||
this.harmony.on('open', () => {
|
this.harmony.on('open', () => {
|
||||||
this.log('Hub open');
|
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
});
|
});
|
||||||
this.harmony.on('close', () => {
|
this.harmony.on('close', () => {
|
||||||
this.log('Hub closed');
|
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -85,22 +83,22 @@ class HarmonyDataProvider {
|
|||||||
lastActivity = this.states[controlUnitName]!.currentActivity;
|
lastActivity = this.states[controlUnitName]!.currentActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.log(`asdf: ${JSON.stringify(this.devices)}`);
|
|
||||||
//Build potential list of devices to to turn on
|
//Build potential list of devices to to turn on
|
||||||
let devicesToTurnOn: Array<IDevice> = activity.deviceSetupItems.map((value: DeviceSetupItem): IDevice => {
|
let devicesToTurnOn: Array<IDevice> = activity.deviceSetupItems.map((value: DeviceSetupItem): IDevice => {
|
||||||
return this.getDeviceFromName(value.deviceName);
|
return this.getDeviceFromName(value.deviceName);
|
||||||
});
|
});
|
||||||
|
|
||||||
// this.log(`Devices to turn on: ${JSON.stringify(devicesToTurnOn)}`);
|
|
||||||
|
|
||||||
//Resolve device conflicts with other controlUnits
|
//Resolve device conflicts with other controlUnits
|
||||||
devicesToTurnOn = this.sanitizeDeviceList(devicesToTurnOn, controlUnitName);
|
devicesToTurnOn = this.sanitizeDeviceList(devicesToTurnOn, controlUnitName);
|
||||||
// this.log(`Sanatized devices to turn on: ${JSON.stringify(devicesToTurnOn)}`)
|
|
||||||
|
|
||||||
//Turn on devices
|
//Turn on devices
|
||||||
await Promise.all(devicesToTurnOn.map(async (device: IDevice) => {
|
await Promise.all(devicesToTurnOn.map(async (device: IDevice) => {
|
||||||
this.log(`Turning on device ${device.name}`)
|
if (device && device.name && this.devices[device.name]) {
|
||||||
await this.powerOnDevice(device);
|
if (!device.on) {
|
||||||
|
this.log(`Turning on device ${device.name}`)
|
||||||
|
await this.powerOnDevice(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
//Assign correct input
|
//Assign correct input
|
||||||
@ -108,14 +106,13 @@ class HarmonyDataProvider {
|
|||||||
activity.deviceSetupItems.map(async (value: DeviceSetupItem) => {
|
activity.deviceSetupItems.map(async (value: DeviceSetupItem) => {
|
||||||
let device: IDevice = this.getDeviceFromName(value.deviceName);
|
let device: IDevice = this.getDeviceFromName(value.deviceName);
|
||||||
|
|
||||||
if (device.supportsCommand(`Input ${value.input}`)) {
|
if (device && device.supportsCommand(`Input${value.input}`)) {
|
||||||
let command: string = device.getCommand(`Input ${value.input}`);
|
let command: string = device.getCommand(`Input${value.input}`);
|
||||||
await this.sendCommand(command);
|
await this.sendCommand(command);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if (activity.useMatrix) {
|
if (activity.useMatrix) {
|
||||||
//get input and output
|
//get input and output
|
||||||
let input: Input = this.matrix.inputs.filter(e => e.inputDevice === activity.controlDeviceId)[0];
|
let input: Input = this.matrix.inputs.filter(e => e.inputDevice === activity.controlDeviceId)[0];
|
||||||
@ -124,11 +121,9 @@ class HarmonyDataProvider {
|
|||||||
let inputCommandName: string = `In ${input.inputNumber}`;
|
let inputCommandName: string = `In ${input.inputNumber}`;
|
||||||
let outputCommandName: string = `Out ${output.outputLetter}`;
|
let outputCommandName: string = `Out ${output.outputLetter}`;
|
||||||
|
|
||||||
// this.log(`Matrix input command: ${inputCommandName} Matrix output command: ${outputCommandName}`);
|
|
||||||
|
|
||||||
let matrixDevice: IDevice = this.getDeviceFromName(this.matrix.deviceName);
|
let matrixDevice: IDevice = this.getDeviceFromName(this.matrix.deviceName);
|
||||||
|
|
||||||
//Rout hdmi
|
//Route hdmi
|
||||||
if (matrixDevice.supportsCommand(inputCommandName) && matrixDevice.supportsCommand(outputCommandName)) {
|
if (matrixDevice.supportsCommand(inputCommandName) && matrixDevice.supportsCommand(outputCommandName)) {
|
||||||
await this.sendCommand(matrixDevice.getCommand(inputCommandName));
|
await this.sendCommand(matrixDevice.getCommand(inputCommandName));
|
||||||
await this.sendCommand(matrixDevice.getCommand(outputCommandName));
|
await this.sendCommand(matrixDevice.getCommand(outputCommandName));
|
||||||
@ -141,17 +136,30 @@ class HarmonyDataProvider {
|
|||||||
return this.getDeviceFromName(value.deviceName);
|
return this.getDeviceFromName(value.deviceName);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.log(`Devices to turn off: ${JSON.stringify(devicesToTurnOff)}`);
|
//remove devices that will be used for next activity from list
|
||||||
|
//delete array[index] is stupid because it just nulls out the index. But now i have to deal with nulls
|
||||||
|
devicesToTurnOff.forEach((device: IDevice, index: number) => {
|
||||||
|
if (device && device.name && activity.deviceSetupItems.some(e => {
|
||||||
|
return (e && e.deviceName === device.name)
|
||||||
|
})) {
|
||||||
|
delete devicesToTurnOff[index];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
//Resolve device conflicts with other controlUnits
|
//Resolve device conflicts with other controlUnits
|
||||||
devicesToTurnOff = this.sanitizeDeviceList(devicesToTurnOff, controlUnitName);
|
devicesToTurnOff = this.sanitizeDeviceList(devicesToTurnOff, controlUnitName);
|
||||||
|
|
||||||
this.log(`Sanatized devices to turn off: ${JSON.stringify(devicesToTurnOff)}`);
|
this.log(`Sanatized devices to turn off: ${JSON.stringify(devicesToTurnOff.map(e => e ? e.name : ""))}`);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
//Turn off devices
|
//Turn off devices
|
||||||
devicesToTurnOff.map(async (device: IDevice) => {
|
devicesToTurnOff.map(async (device: IDevice) => {
|
||||||
await this.powerOffDevice(device);
|
if (device) {
|
||||||
|
if (device.on) {
|
||||||
|
this.log(`Turning off device ${device.name}`)
|
||||||
|
await this.powerOffDevice(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -173,8 +181,8 @@ class HarmonyDataProvider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getIsActive(controlUnitName: string): boolean {
|
public getIsActive(controlUnitName: string): Activity | undefined {
|
||||||
return this.states[controlUnitName] ? true : false
|
return this.states[controlUnitName] ? this.states[controlUnitName]!.currentActivity : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -213,6 +221,7 @@ class HarmonyDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
self.log(`Harmony data provider ready`);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
self.log(`ERROR - error connecting to harmony: ${err}`);
|
self.log(`ERROR - error connecting to harmony: ${err}`);
|
||||||
@ -223,15 +232,17 @@ class HarmonyDataProvider {
|
|||||||
|
|
||||||
private powerOffDevice = async (device: IDevice) => {
|
private powerOffDevice = async (device: IDevice) => {
|
||||||
let powerOffCommand: string = "Power Off";
|
let powerOffCommand: string = "Power Off";
|
||||||
if (device.supportsCommand(powerOffCommand)) {
|
if (device && device.supportsCommand(powerOffCommand)) {
|
||||||
await this.sendCommand(device.getCommand(powerOffCommand));
|
await this.sendCommand(device.getCommand(powerOffCommand));
|
||||||
|
device.on = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private powerOnDevice = async (device: IDevice) => {
|
private powerOnDevice = async (device: IDevice) => {
|
||||||
let powerOnCommand: string = "Power On";
|
let powerOnCommand: string = "Power On";
|
||||||
if (device.supportsCommand(powerOnCommand)) {
|
if (device && device.supportsCommand(powerOnCommand)) {
|
||||||
await this.sendCommand(device.getCommand(powerOnCommand));
|
await this.sendCommand(device.getCommand(powerOnCommand));
|
||||||
|
device.on = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +261,7 @@ class HarmonyDataProvider {
|
|||||||
if (currentOtherState) {
|
if (currentOtherState) {
|
||||||
currentOtherState.currentActivity.deviceSetupItems.forEach((value: DeviceSetupItem) => {
|
currentOtherState.currentActivity.deviceSetupItems.forEach((value: DeviceSetupItem) => {
|
||||||
//there are devices to remove
|
//there are devices to remove
|
||||||
if (devicesToTurnOn.some(e => e.name === value.deviceName)) {
|
if (devicesToTurnOn.some(e => e && e.name === value.deviceName)) {
|
||||||
let deviceToRemove: IDevice = devicesToTurnOn.filter(i => i.name === value.deviceName)[0];
|
let deviceToRemove: IDevice = devicesToTurnOn.filter(i => i.name === value.deviceName)[0];
|
||||||
delete devicesToTurnOn[devicesToTurnOn.indexOf(deviceToRemove)];
|
delete devicesToTurnOn[devicesToTurnOn.indexOf(deviceToRemove)];
|
||||||
}
|
}
|
||||||
@ -264,7 +275,7 @@ class HarmonyDataProvider {
|
|||||||
private sendCommand = async (command: string) => {
|
private sendCommand = async (command: string) => {
|
||||||
try {
|
try {
|
||||||
let response = await this.harmony.sendCommand(JSON.stringify(command));
|
let response = await this.harmony.sendCommand(JSON.stringify(command));
|
||||||
this.log(`Sent command: ${JSON.stringify(command)} response: ${JSON.stringify(response)}`);
|
// this.log(`Sent command: ${JSON.stringify(command)} response: ${JSON.stringify(response)}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.log(`ERROR - error sending command to harmony: ${err}`);
|
this.log(`ERROR - error sending command to harmony: ${err}`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user