Worked around bug where receiver was not turning off

This commit is contained in:
watsonb8 2020-01-24 23:17:33 -05:00
parent 6f7fc4c2af
commit 3ac6ffb8a3
4 changed files with 22 additions and 12 deletions

View File

@ -82,7 +82,9 @@ class HarmonyDataProvider extends EventEmitter {
//Turn off devices
devicesToTurnOff.forEach(async (device: HarmonyDevice) => {
await device.powerOff();
if (device) {
await device.powerOff();
}
});
this._states[controlUnitName] = undefined;
@ -299,16 +301,17 @@ class HarmonyDataProvider extends EventEmitter {
// }
private connect = async (hubs: Array<IHub>) => {
// for (let i = 0; i < hubs.length; i++) {
// const hub = hubs[i];
// const newHarmonyHub = new HarmonyHub(hub.Ip, this._log);
// this._hubs[hub.Name] = newHarmonyHub;
// await newHarmonyHub.initialize();
// }
let readyCount = 0;
await Promise.all(
hubs.map(async (hub: IHub): Promise<void> => {
const newHarmonyHub = new HarmonyHub(hub.Name, hub.Ip, this._log);
this._hubs[hub.Name] = newHarmonyHub;
newHarmonyHub.on("Ready", () => {
readyCount++;
if (readyCount === Object.keys(this._hubs).length) {
this.emit("Ready");
}
})
await newHarmonyHub.initialize();
})
)

View File

@ -76,6 +76,13 @@ export class HarmonyDevice {
try {
//Execute command
//HACK to fix Harmon Kardon receiver not turning off
if (command.command === "PowerOff") {
for (let i = 0; i < 2; i++) {
await this._harmony.sendCommand(JSON.stringify(command));
}
}
await this._harmony.sendCommand(JSON.stringify(command));
//Sleep

View File

@ -55,7 +55,6 @@ export class HarmonyHub extends EventEmitter {
harmony: this._harmony
});
}));
this._log(`Harmony data provider ready`);
this.emit("Ready");
} catch (err) {

View File

@ -49,9 +49,10 @@ class HarmonyMatrixPlatform {
});
//Emit devices if requested
if (this.config.EmitDevicesOnStartup) {
this.dataProvider.on("Ready", () => {
this.dataProvider.on("Ready", () => {
this.log("All hubs connected");
if (this.config.EmitDevicesOnStartup) {
const hubs = this.dataProvider!.hubs;
Object.values(hubs).forEach((hub: HarmonyHub) => {
const deviceDictionary = hub.devices;
@ -64,9 +65,9 @@ class HarmonyMatrixPlatform {
});
});
});
}
});
});
}
}
}