homebridge-connectlife-ac
Version:
Control your ConnectLife air conditioner with Homebridge
173 lines • 7.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemperatureAccessory = void 0;
const lib_1 = require("../lib");
const constants_1 = require("../constants");
const utils_1 = require("../utils");
class TemperatureAccessory {
platform;
accessory;
debugMode;
deviceNickName;
connectLifeApi;
service;
constructor(platform, accessory) {
this.platform = platform;
this.accessory = accessory;
const { loginID, password } = platform.config;
const deviceNickName = accessory.context.device?.displayName?.toLowerCase();
if (!deviceNickName || !loginID || !password) {
throw new Error('Missing required config');
}
this.debugMode = !!platform.config?.debugMode;
this.deviceNickName = deviceNickName;
this.connectLifeApi = new lib_1.ConnectLifeApi(loginID, password, {
debugMode: this.debugMode,
log: platform.log,
});
this.accessory
.getService(this.platform.Service.AccessoryInformation)
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'null')
.setCharacteristic(this.platform.Characteristic.Model, 'null')
.setCharacteristic(this.platform.Characteristic.SerialNumber, 'null');
this.service =
this.accessory.getService(this.platform.Service.HeaterCooler) ||
this.accessory.addService(this.platform.Service.HeaterCooler);
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.displayName);
this.service
.getCharacteristic(this.platform.Characteristic.Active)
.onSet(this.setActive.bind(this))
.onGet(this.getActive.bind(this));
this.service
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
.onSet(this.setCurrentTemperature.bind(this))
.onGet(this.getCurrentTemperature.bind(this));
this.service
.getCharacteristic(this.platform.Characteristic.SwingMode)
.onSet(this.setSwingMode.bind(this))
.onGet(this.getSwingMode.bind(this));
this.service
.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
.onSet(this.setCoolingThresholdTemperature.bind(this))
.onGet(this.getCoolingThresholdTemperature.bind(this));
this.service
.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
.onSet(this.setHeatingThresholdTemperature.bind(this))
.onGet(this.getHeatingThresholdTemperature.bind(this));
this.service
.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits)
.onSet(this.setTemperatureDisplayUnits.bind(this))
.onGet(this.getTemperatureDisplayUnits.bind(this));
}
async setActive(value) {
const { t_power } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_power: 'integer',
});
if (t_power === value) {
return;
}
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_power: value,
});
if (this.debugMode) {
this.platform.log.info('Set Active', value);
}
}
async getActive() {
const { t_power } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_power: 'integer',
});
return t_power;
}
setCurrentTemperature(_value) {
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_work_mode: constants_1.WorkModes.Auto,
});
if (this.debugMode) {
this.platform.log.info('Set CurrentTemperature', _value);
}
}
async getCurrentTemperature() {
const { t_temp, t_temp_type } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp: 'integer',
t_temp_type: 'integer',
});
return t_temp_type === 1 ? (0, utils_1.fahrenheitToCelsius)(t_temp) : t_temp;
}
setSwingMode(value) {
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_up_down: value,
});
if (this.debugMode) {
this.platform.log.info('Set SwingMode', value);
}
}
async getSwingMode() {
const { t_up_down } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_up_down: 'integer',
});
return t_up_down;
}
async setCoolingThresholdTemperature(value) {
const { t_temp_type } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp_type: 'integer',
});
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_temp: t_temp_type === 1 ? (0, utils_1.celsiusToFahrenheit)(value) : value,
t_work_mode: constants_1.WorkModes.Cool,
});
if (this.debugMode) {
this.platform.log.info('Set CoolingThresholdTemperature', value);
}
}
async getCoolingThresholdTemperature() {
const { t_temp, t_temp_type, t_work_mode } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp: 'integer',
t_temp_type: 'integer',
t_work_mode: 'integer',
});
if (t_work_mode !== constants_1.WorkModes.Cool) {
return 10;
}
return t_temp_type === 1 ? (0, utils_1.fahrenheitToCelsius)(t_temp) : t_temp;
}
async setHeatingThresholdTemperature(value) {
const { t_temp_type } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp_type: 'integer',
});
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_temp: t_temp_type === 1 ? (0, utils_1.celsiusToFahrenheit)(value) : value,
t_work_mode: constants_1.WorkModes.Heat,
});
if (this.debugMode) {
this.platform.log.info('Set HeatingThresholdTemperature', value);
}
}
async getHeatingThresholdTemperature() {
const { t_temp, t_temp_type, t_work_mode } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp: 'integer',
t_temp_type: 'integer',
t_work_mode: 'integer',
});
if (t_work_mode !== constants_1.WorkModes.Heat) {
return 0;
}
return t_temp_type === 1 ? (0, utils_1.fahrenheitToCelsius)(t_temp) : t_temp;
}
setTemperatureDisplayUnits(value) {
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_temp_type: value,
});
if (this.debugMode) {
this.platform.log.info('Set TemperatureDisplayUnits', value);
}
}
async getTemperatureDisplayUnits() {
const { t_temp_type } = await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp_type: 'integer',
});
return t_temp_type;
}
}
exports.TemperatureAccessory = TemperatureAccessory;
//# sourceMappingURL=TemperatureAccessory.js.map