homebridge-gsh
Version:
Google Smart Home
71 lines • 3.02 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.GarageDoorOpener = void 0;
const hap_types_1 = require("../hap-types");
const ghToHapTypes_1 = require("./ghToHapTypes");
class GarageDoorOpener extends ghToHapTypes_1.ghToHap {
constructor() {
super(...arguments);
this.twoFactorRequired = true;
}
sync(service) {
return this.createSyncData(service, {
type: 'action.devices.types.GARAGE',
traits: [
'action.devices.traits.OpenClose',
],
attributes: {
openDirection: ['UP', 'DOWN'],
},
});
}
query(service) {
const currentDoorState = Number(service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CurrentDoorState).value);
const openPercent = [100, 0, 50, 50, 50, 50][currentDoorState];
return {
on: true,
online: true,
openPercent,
};
}
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.OpenClose'): {
yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.TargetDoorState).setValue(command.execution[0].params.openPercent ? 0 : 1);
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.OpenClose'): {
if (command.execution[0].params.openPercent > 0) {
return true;
}
}
}
return false;
}
}
exports.GarageDoorOpener = GarageDoorOpener;
//# sourceMappingURL=garage-door-opener.js.map