UNPKG

homebridge-gsh

Version:
134 lines 8.47 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.HeaterCooler = void 0; const hap_types_1 = require("../hap-types"); const ghToHapTypes_1 = require("./ghToHapTypes"); class HeaterCooler extends ghToHapTypes_1.ghToHap { constructor(hap) { super(); this.hap = hap; } sync(service) { var _a; const availableThermostatModes = ['off', 'heat', 'cool']; if (service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CoolingThresholdTemperature) && service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.HeatingThresholdTemperature)) { availableThermostatModes.push('heatcool'); } else { availableThermostatModes.push('auto'); } const traits = [ 'action.devices.traits.TemperatureSetting', 'action.devices.traits.OnOff', ]; const attributes = { availableThermostatModes: availableThermostatModes.join(','), thermostatTemperatureUnit: this.hap.config.forceFahrenheit ? 'F' : ((_a = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.TemperatureDisplayUnits)) === null || _a === void 0 ? void 0 : _a.value) ? 'F' : 'C', commandOnlyOnOff: false, queryOnlyOnOff: false, }; const type = this.hap.config.showHeaterCoolerAsACUnit ? 'action.devices.types.AC_UNIT' : 'action.devices.types.THERMOSTAT'; if (service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.RotationSpeed)) { traits.push('action.devices.traits.FanSpeed'); attributes.supportsFanSpeedPercent = true; } return this.createSyncData(service, { type, traits, attributes, }); } query(service) { const targetHeatingCoolingState = Number(service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.TargetHeaterCoolerState).value); const activeState = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.Active).value; const thermostatMode = activeState ? ['auto', 'heat', 'cool'][targetHeatingCoolingState] : 'off'; const response = { online: true, on: !!activeState, thermostatMode, activeThermostatMode: thermostatMode, thermostatTemperatureAmbient: service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CurrentTemperature).value, }; if (service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CoolingThresholdTemperature) && service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.HeatingThresholdTemperature)) { if (response.thermostatMode === 'heat') { response.thermostatTemperatureSetpoint = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.HeatingThresholdTemperature).value; } else if (response.thermostatMode === 'cool') { response.thermostatTemperatureSetpoint = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CoolingThresholdTemperature).value; } else if (response.thermostatMode === 'auto') { response.thermostatMode = 'heatcool'; response.thermostatTemperatureSetpointLow = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.HeatingThresholdTemperature).value; response.thermostatTemperatureSetpointHigh = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CoolingThresholdTemperature).value; } } if (service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.RotationSpeed)) { response.currentFanSpeedPercent = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.RotationSpeed).value; } 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.ThermostatSetMode'): { const mode = { auto: 0, heat: 1, cool: 2, heatcool: 0, }; if (command.execution[0].params.thermostatMode === 'off') { yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.Active).setValue(0); } else { yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.Active).setValue(1); yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.TargetHeaterCoolerState).setValue(mode[command.execution[0].params.thermostatMode]); } return { ids: [service.uniqueId], status: 'SUCCESS' }; } case ('action.devices.commands.ThermostatTemperatureSetpoint'): { yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CoolingThresholdTemperature).setValue(command.execution[0].params.thermostatTemperatureSetpoint); yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.HeatingThresholdTemperature).setValue(command.execution[0].params.thermostatTemperatureSetpoint); return { ids: [service.uniqueId], status: 'SUCCESS' }; } case ('action.devices.commands.ThermostatTemperatureSetRange'): { yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CoolingThresholdTemperature).setValue(command.execution[0].params.thermostatTemperatureSetpointHigh); yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.HeatingThresholdTemperature).setValue(command.execution[0].params.thermostatTemperatureSetpointLow); return { ids: [service.uniqueId], status: 'SUCCESS' }; } case ('action.devices.commands.SetFanSpeed'): { if (!service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.RotationSpeed)) { return { ids: [service.uniqueId], status: 'ERROR', debugString: 'fan speed not supported' }; } yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.RotationSpeed).setValue(command.execution[0].params.fanSpeedPercent); return { ids: [service.uniqueId], status: 'SUCCESS' }; } case ('action.devices.commands.OnOff'): { yield service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.Active).setValue(command.execution[0].params.on ? 1 : 0); return { ids: [service.uniqueId], status: 'SUCCESS' }; } default: { return { ids: [service.uniqueId], status: 'ERROR', debugString: `unknown command ${command.execution[0].command}` }; } } }); } } exports.HeaterCooler = HeaterCooler; //# sourceMappingURL=heater-cooler.js.map