homebridge-gsh
Version:
Google Smart Home
98 lines • 5.89 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.Thermostat = void 0;
const hap_types_1 = require("../hap-types");
const ghToHapTypes_1 = require("./ghToHapTypes");
class Thermostat extends ghToHapTypes_1.ghToHap {
constructor(hap) {
super();
this.hap = hap;
}
sync(service) {
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');
}
return this.createSyncData(service, {
type: 'action.devices.types.THERMOSTAT',
traits: [
'action.devices.traits.TemperatureSetting',
],
attributes: {
availableThermostatModes: availableThermostatModes.join(','),
thermostatTemperatureUnit: this.hap.config.forceFahrenheit
? 'F'
: service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.TemperatureDisplayUnits).value ? 'F' : 'C',
},
});
}
query(service) {
const targetHeatingCoolingState = Number(service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.TargetHeatingCoolingState).value);
const thermostatMode = ['off', 'heat', 'cool', 'auto'][targetHeatingCoolingState];
const response = {
online: true,
thermostatMode,
thermostatTemperatureSetpoint: service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.TargetTemperature).value,
thermostatTemperatureAmbient: service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CurrentTemperature).value,
};
if (service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CurrentRelativeHumidity)) {
response.thermostatHumidityAmbient = service.serviceCharacteristics.find(x => x.uuid === hap_types_1.Characteristic.CurrentRelativeHumidity).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 === '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;
}
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 = {
off: 0,
heat: 1,
cool: 2,
auto: 3,
heatcool: 3,
};
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.TargetTemperature).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' };
}
default: {
return { ids: [service.uniqueId], status: 'ERROR', debugString: `unknown command ${command.execution[0].command}` };
}
}
});
}
}
exports.Thermostat = Thermostat;
//# sourceMappingURL=thermostat.js.map