UNPKG

homebridge-touchwand-google

Version:
154 lines 7.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeaterCooler = void 0; const hap_types_1 = require("../hap-types"); class HeaterCooler { constructor(hap) { this.hap = hap; } sync(service) { var _a; const availableThermostatModes = ['off', 'heat', 'cool']; if (service.characteristics.find(x => x.type === hap_types_1.Characteristic.CoolingThresholdTemperature) && service.characteristics.find(x => x.type === hap_types_1.Characteristic.HeatingThresholdTemperature)) { availableThermostatModes.push('heatcool'); } else { availableThermostatModes.push('auto'); } return { id: service.uniqueId, type: 'action.devices.types.THERMOSTAT', traits: [ 'action.devices.traits.TemperatureSetting', ], attributes: { availableThermostatModes: availableThermostatModes.join(','), thermostatTemperatureUnit: this.hap.config.forceFahrenheit ? 'F' : ((_a = service.characteristics.find(x => x.type === hap_types_1.Characteristic.TemperatureDisplayUnits)) === null || _a === void 0 ? void 0 : _a.value) ? 'F' : 'C', }, name: { defaultNames: [ service.serviceName, service.accessoryInformation.Name, ], name: service.serviceName, nicknames: [], }, willReportState: true, deviceInfo: { manufacturer: service.accessoryInformation.Manufacturer, model: service.accessoryInformation.Model, }, customData: { aid: service.aid, iid: service.iid, instanceUsername: service.instance.username, instanceIpAddress: service.instance.ipAddress, instancePort: service.instance.port, }, }; } query(service) { const targetHeatingCoolingState = service.characteristics.find(x => x.type === hap_types_1.Characteristic.TargetHeaterCoolerState).value; const activeState = service.characteristics.find(x => x.type === hap_types_1.Characteristic.Active).value; const thermostatMode = activeState ? ['auto', 'heat', 'cool'][targetHeatingCoolingState] : 'off'; const response = { online: true, thermostatMode, thermostatTemperatureAmbient: service.characteristics.find(x => x.type === hap_types_1.Characteristic.CurrentTemperature).value, }; if (service.characteristics.find(x => x.type === hap_types_1.Characteristic.CoolingThresholdTemperature) && service.characteristics.find(x => x.type === hap_types_1.Characteristic.HeatingThresholdTemperature)) { if (response.thermostatMode === 'heat') { response.thermostatTemperatureSetpoint = service.characteristics.find(x => x.type === hap_types_1.Characteristic.HeatingThresholdTemperature).value; } else if (response.thermostatMode === 'cool') { response.thermostatTemperatureSetpoint = service.characteristics.find(x => x.type === hap_types_1.Characteristic.CoolingThresholdTemperature).value; } else if (response.thermostatMode === 'auto') { response.thermostatMode = 'heatcool'; response.thermostatTemperatureSetpointLow = service.characteristics.find(x => x.type === hap_types_1.Characteristic.HeatingThresholdTemperature).value; response.thermostatTemperatureSetpointHigh = service.characteristics.find(x => x.type === hap_types_1.Characteristic.CoolingThresholdTemperature).value; } } return response; } execute(service, command) { if (!command.execution.length) { return { payload: { characteristics: [] } }; } switch (command.execution[0].command) { case ('action.devices.commands.ThermostatSetMode'): { const mode = { auto: 0, heat: 1, cool: 2, heatcool: 0, }; let payload; if (command.execution[0].params.thermostatMode === 'off') { payload = { characteristics: [{ aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.Active).iid, value: 0, }], }; } else { payload = { characteristics: [ { aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.Active).iid, value: 1, }, { aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.TargetHeaterCoolerState).iid, value: mode[command.execution[0].params.thermostatMode], }, ], }; } return { payload }; } case ('action.devices.commands.ThermostatTemperatureSetpoint'): { const payload = { characteristics: [ { aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.CoolingThresholdTemperature).iid, value: command.execution[0].params.thermostatTemperatureSetpoint, }, { aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.HeatingThresholdTemperature).iid, value: command.execution[0].params.thermostatTemperatureSetpoint, }, ], }; return { payload }; } case ('action.devices.commands.ThermostatTemperatureSetRange'): { const payload = { characteristics: [ { aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.CoolingThresholdTemperature).iid, value: command.execution[0].params.thermostatTemperatureSetpointHigh, }, { aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.HeatingThresholdTemperature).iid, value: command.execution[0].params.thermostatTemperatureSetpointLow, } ], }; return { payload }; } } } } exports.HeaterCooler = HeaterCooler; //# sourceMappingURL=heater-cooler.js.map