UNPKG

homebridge-touchwand-google

Version:
126 lines 6.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Thermostat = void 0; const hap_types_1 = require("../hap-types"); class Thermostat { constructor(hap) { this.hap = hap; } sync(service) { 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' : service.characteristics.find(x => x.type === hap_types_1.Characteristic.TemperatureDisplayUnits).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.TargetHeatingCoolingState).value; const thermostatMode = ['off', 'heat', 'cool', 'auto'][targetHeatingCoolingState]; const response = { online: true, thermostatMode, thermostatTemperatureSetpoint: service.characteristics.find(x => x.type === hap_types_1.Characteristic.TargetTemperature).value, thermostatTemperatureAmbient: service.characteristics.find(x => x.type === hap_types_1.Characteristic.CurrentTemperature).value, }; if (service.characteristics.find(x => x.type === hap_types_1.Characteristic.CurrentRelativeHumidity)) { response.thermostatHumidityAmbient = service.characteristics.find(x => x.type === hap_types_1.Characteristic.CurrentRelativeHumidity).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 === '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 = { off: 0, heat: 1, cool: 2, auto: 3, heatcool: 3, }; const payload = { characteristics: [{ aid: service.aid, iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.TargetHeatingCoolingState).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.TargetTemperature).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.Thermostat = Thermostat; //# sourceMappingURL=thermostat.js.map