nubli
Version:
Nuki Bluetooth Library
52 lines (51 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const SmartLockCommand_1 = require("./SmartLockCommand");
const states_1 = require("../states");
const smartLock_1 = require("../smartLock");
const KeyTurnerStatesCommand_1 = require("./KeyTurnerStatesCommand");
class LockActionCommand extends SmartLockCommand_1.SmartLockCommand {
constructor(action, updateCallback) {
super();
this.requiresChallenge = true;
this.action = action;
this.updateCallback = updateCallback;
}
requestData(config) {
let payload = new Buffer(6);
payload.writeUInt8(this.action, 0);
payload.writeUInt32LE(config.appId, 1);
payload.writeUInt8(0, 5);
payload = Buffer.concat([payload, this.challenge]);
return smartLock_1.SmartLock.prepareCommand(states_1.Command.LOCK_ACTION, payload);
}
handleData(command, payload) {
if (command == states_1.Command.STATUS) {
let status = payload.readUInt8(0);
if (status == states_1.Status.ACCEPTED) {
// Nothing to do
}
else if (status == states_1.Status.COMPLETE) {
this._complete = true;
}
else {
// Should not happen
this._complete = true;
this._response.success = false;
}
}
else if (command == states_1.Command.KEYTURNER_STATES) {
let keyTurnerCommand = new KeyTurnerStatesCommand_1.KeyTurnerStatesCommand();
keyTurnerCommand.handleData(command, payload);
this._response.data = keyTurnerCommand.response.data;
if (!keyTurnerCommand.complete) {
this._complete = true;
this._response.success = false;
}
else if (this.updateCallback) {
this.updateCallback(this._response);
}
}
}
}
exports.LockActionCommand = LockActionCommand;