Fixed device buttons
This commit is contained in:
@ -2,6 +2,7 @@ import HarmonyDataProvider from "../DataProviders/HarmonyDataProvider";
|
||||
import { IDeviceButton } from "../Models/Config";
|
||||
import { IAccessory } from "./IAccessory";
|
||||
import { ICommand } from "../Models";
|
||||
import { HarmonyDevice } from "../Models/HarmonyDevice";
|
||||
|
||||
let Service: HAPNodeJS.Service;
|
||||
let Characteristic: HAPNodeJS.Characteristic;
|
||||
@ -29,7 +30,7 @@ export class DeviceButton implements IAccessory {
|
||||
|
||||
private _dataProvider: HarmonyDataProvider;
|
||||
|
||||
private _deviceCommand?: ICommand;
|
||||
private _device!: HarmonyDevice;
|
||||
|
||||
private _buttonState: boolean;
|
||||
|
||||
@ -101,23 +102,20 @@ export class DeviceButton implements IAccessory {
|
||||
}
|
||||
|
||||
//Get device command if we don't have it
|
||||
if (!this._deviceCommand) {
|
||||
let cmd = this._dataProvider.getCommand(this._buttonInfo.ButtonName, this._buttonInfo.DeviceName);
|
||||
if (cmd) {
|
||||
this._deviceCommand = cmd;
|
||||
}
|
||||
if (!this._device) {
|
||||
this._device = this._dataProvider.getDeviceFromName(this._buttonInfo.DeviceName);
|
||||
}
|
||||
|
||||
//Execute command
|
||||
if (this._deviceCommand) {
|
||||
if (this._device) {
|
||||
//change state if stateful
|
||||
if (this._buttonInfo.IsStateful && this._buttonState != newState) {
|
||||
this._buttonState = newState
|
||||
//TODO await this._dataProvider.sendCommand(this._deviceCommand);
|
||||
await this._device.sendCommand(this._buttonInfo.ButtonName);
|
||||
} else if (!this._buttonInfo.IsStateful) {
|
||||
//Send the number of configured key presses
|
||||
for (let i = 0; i < this._buttonInfo.NumberOfKeyPresses; i++) {
|
||||
//TODO await this._dataProvider.sendCommand(this._deviceCommand);
|
||||
await this._device.sendCommand(this._buttonInfo.ButtonName);
|
||||
}
|
||||
this._switchService.getCharacteristic(Characteristic.On).updateValue(false);
|
||||
return callback(new Error("Normal Response"));
|
||||
|
Reference in New Issue
Block a user