homebridge-gsh
Version:
Google Smart Home
52 lines • 2.41 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.WindowCovering = void 0;
const hap_types_1 = require("../hap-types");
const ghToHapTypes_1 = require("./ghToHapTypes");
class WindowCovering extends ghToHapTypes_1.ghToHap {
sync(service) {
return this.createSyncData(service, {
type: 'action.devices.types.BLINDS',
traits: [
'action.devices.traits.OpenClose',
],
attributes: {
openDirection: ['UP', 'DOWN'],
},
});
}
query(service) {
return {
on: true,
online: true,
openPercent: service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CurrentPosition).value,
};
}
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.TargetPosition).setValue(command.execution[0].params.openPercent);
return { ids: [service.uniqueId], status: 'SUCCESS' };
}
default: {
return { ids: [service.uniqueId], status: 'ERROR', debugString: `unknown command ${command.execution[0].command}` };
}
}
});
}
}
exports.WindowCovering = WindowCovering;
//# sourceMappingURL=window-covering.js.map