@elshaer/homebridge-lg-thinq
Version:
A Homebridge plugin for controlling/monitoring LG ThinQ device via LG ThinQ platform.
147 lines • 6.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DehumidifierStatus = void 0;
const baseDevice_1 = require("../baseDevice");
var RotateSpeed;
(function (RotateSpeed) {
RotateSpeed[RotateSpeed["LOW"] = 2] = "LOW";
RotateSpeed[RotateSpeed["HIGH"] = 6] = "HIGH";
})(RotateSpeed || (RotateSpeed = {}));
class Dehumidifier extends baseDevice_1.baseDevice {
constructor(platform, accessory) {
super(platform, accessory);
this.platform = platform;
this.accessory = accessory;
const { Service: { HumidifierDehumidifier, HumiditySensor, }, Characteristic, Characteristic: { CurrentHumidifierDehumidifierState, }, } = this.platform;
const device = accessory.context.device;
this.serviceDehumidifier = accessory.getService(HumidifierDehumidifier) || accessory.addService(HumidifierDehumidifier);
this.serviceDehumidifier.setCharacteristic(Characteristic.Name, device.name);
this.serviceDehumidifier.getCharacteristic(Characteristic.Active)
.onSet(this.setActive.bind(this))
.updateValue(Characteristic.Active.INACTIVE);
this.serviceDehumidifier.getCharacteristic(Characteristic.CurrentHumidifierDehumidifierState)
.setProps({
validValues: [
CurrentHumidifierDehumidifierState.INACTIVE,
CurrentHumidifierDehumidifierState.IDLE,
CurrentHumidifierDehumidifierState.DEHUMIDIFYING,
],
})
.updateValue(Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
this.serviceDehumidifier.getCharacteristic(Characteristic.TargetHumidifierDehumidifierState)
.setProps({
validValues: [2],
})
.updateValue(Characteristic.TargetHumidifierDehumidifierState.DEHUMIDIFIER);
this.serviceDehumidifier.getCharacteristic(Characteristic.RelativeHumidityDehumidifierThreshold)
.onSet(this.setHumidityThreshold.bind(this))
.setProps({
minValue: 0,
maxValue: 100,
minStep: 1,
});
this.serviceDehumidifier.getCharacteristic(Characteristic.RotationSpeed)
.onSet(this.setSpeed.bind(this))
.setProps({
minValue: 1,
maxValue: Object.keys(RotateSpeed).length / 2,
minStep: 1,
});
this.serviceHumiditySensor = accessory.getService(HumiditySensor) || accessory.addService(HumiditySensor);
this.serviceHumiditySensor.addLinkedService(this.serviceDehumidifier);
}
async setActive(value) {
var _a;
this.platform.log.debug('Set Dehumidifier Active State ->', value);
const device = this.accessory.context.device;
const isOn = value;
if (this.Status.isPowerOn && isOn) {
return; // don't send same status
}
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(device.id, {
dataKey: 'airState.operation',
dataValue: isOn,
}).then(() => {
device.data.snapshot['airState.operation'] = isOn ? 1 : 0;
this.updateAccessoryCharacteristic(device);
});
}
async setHumidityThreshold(value) {
var _a;
if (!this.Status.isPowerOn) {
return;
}
const device = this.accessory.context.device;
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(device.id, {
dataKey: 'airState.humidity.desired',
dataValue: value,
}).then(() => {
device.data.snapshot['airState.humidity.desired'] = value;
this.updateAccessoryCharacteristic(device);
});
}
async setSpeed(value) {
var _a;
if (!this.Status.isPowerOn) {
return;
}
const device = this.accessory.context.device;
const values = Object.keys(RotateSpeed);
const windStrength = parseInt(values[Math.round(value) - 1]) || RotateSpeed.HIGH;
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(device.id, {
dataKey: 'airState.windStrength',
dataValue: windStrength,
});
device.data.snapshot['airState.windStrength'] = windStrength;
this.updateAccessoryCharacteristic(device);
}
updateAccessoryCharacteristic(device) {
super.updateAccessoryCharacteristic(device);
const { Characteristic, Characteristic: { CurrentHumidifierDehumidifierState: { INACTIVE, IDLE, DEHUMIDIFYING, }, }, } = this.platform;
this.serviceDehumidifier.updateCharacteristic(Characteristic.Active, this.Status.isPowerOn ? 1 : 0);
this.serviceDehumidifier.updateCharacteristic(Characteristic.CurrentRelativeHumidity, this.Status.humidityCurrent);
this.serviceDehumidifier.updateCharacteristic(Characteristic.RelativeHumidityDehumidifierThreshold, this.Status.humidityTarget);
const currentState = this.Status.isPowerOn ? (this.Status.isDehumidifying ? DEHUMIDIFYING : IDLE) : INACTIVE;
this.serviceDehumidifier.updateCharacteristic(Characteristic.CurrentHumidifierDehumidifierState, currentState);
this.serviceDehumidifier.updateCharacteristic(Characteristic.RotationSpeed, this.Status.rotationSpeed);
this.serviceDehumidifier.updateCharacteristic(Characteristic.WaterLevel, this.Status.isWaterTankFull ? 100 : 0);
this.serviceHumiditySensor.updateCharacteristic(Characteristic.CurrentRelativeHumidity, this.Status.humidityCurrent);
this.serviceHumiditySensor.updateCharacteristic(Characteristic.StatusActive, this.Status.isPowerOn);
}
get Status() {
return new DehumidifierStatus(this.accessory.context.device.snapshot);
}
}
exports.default = Dehumidifier;
class DehumidifierStatus {
constructor(data) {
this.data = data;
}
get isPowerOn() {
return this.data['airState.operation'];
}
get opMode() {
return this.data['airState.opMode'];
}
get windStrength() {
return this.data['airState.windStrength'];
}
get isDehumidifying() {
return [17, 18, 19, 21].includes(this.opMode) && this.humidityCurrent >= this.humidityTarget;
}
get humidityCurrent() {
return this.data['airState.humidity.current'] || 0;
}
get humidityTarget() {
return this.data['airState.humidity.desired'] || 0;
}
get rotationSpeed() {
const index = Object.keys(RotateSpeed).indexOf(parseInt(this.data['airState.windStrength']).toString());
return index !== -1 ? index + 1 : Object.keys(RotateSpeed).length / 2;
}
get isWaterTankFull() {
return !!this.data['airState.notificationExt'];
}
}
exports.DehumidifierStatus = DehumidifierStatus;
//# sourceMappingURL=Dehumidifier.js.map