homebridge-gsh
Version:
Google Smart Home
92 lines • 3.55 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LockMechanism = void 0;
const hap_types_1 = require("../hap-types");
const ghToHapTypes_1 = require("./ghToHapTypes");
class LockMechanism extends ghToHapTypes_1.ghToHap {
constructor() {
super(...arguments);
this.twoFactorRequired = true;
}
sync(service) {
return this.createSyncData(service, {
type: 'action.devices.types.LOCK',
traits: [
'action.devices.traits.LockUnlock',
],
});
}
query(service) {
const response = {
online: true,
};
const currentLockState = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.LockCurrentState).value;
switch (currentLockState) {
case (0): {
response.isLocked = false;
response.isJammed = false;
break;
}
case (1): {
response.isLocked = true;
response.isJammed = false;
break;
}
case (2): {
response.isLocked = false;
response.isJammed = true;
break;
}
case (3): {
response.isLocked = false;
response.isJammed = false;
break;
}
}
return response;
}
execute(service, command) {
return __awaiter(this, void 0, void 0, function* () {
if (!command.execution.length) {
return { ids: [service.uniqueId], status: 'ERROR', debugString: 'missing command' };
}
switch (command.execution[0].command) {
case ('action.devices.commands.LockUnlock'): {
yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.LockTargetState).setValue(command.execution[0].params.lock ? 1 : 0);
return { ids: [service.uniqueId], status: 'SUCCESS' };
}
default: {
return { ids: [service.uniqueId], status: 'ERROR', debugString: `unknown command ${command.execution[0].command}` };
}
}
});
}
is2faRequired(command) {
if (!command.execution.length) {
return false;
}
switch (command.execution[0].command) {
case ('action.devices.commands.LockUnlock'): {
if (command.execution[0].params.lock === false) {
return true;
}
return false;
}
default: {
return false;
}
}
return false;
}
}
exports.LockMechanism = LockMechanism;
//# sourceMappingURL=lock-mechanism.js.map