UNPKG

homebridge-gsh

Version:
52 lines 2.28 kB
"use strict"; 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.Switch = void 0; const hap_types_1 = require("../hap-types"); const ghToHapTypes_1 = require("./ghToHapTypes"); class Switch extends ghToHapTypes_1.ghToHap { constructor(type) { super(); this.deviceType = type; } sync(service) { return this.createSyncData(service, { type: this.deviceType, traits: [ 'action.devices.traits.OnOff', ], }); } query(service) { return { on: !!service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.On).value, online: true, }; } 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.OnOff'): { yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.On).setValue(command.execution[0].params.on); return { ids: [service.uniqueId], status: 'SUCCESS' }; } default: { return { ids: [service.uniqueId], status: 'ERROR', debugString: `unknown command ${command.execution[0].command}` }; } } }); } } exports.Switch = Switch; //# sourceMappingURL=switch.js.map