@elshaer/homebridge-lg-thinq
Version:
A Homebridge plugin for controlling/monitoring LG ThinQ device via LG ThinQ platform.
95 lines • 4.89 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LightBrightness = void 0;
const AirPurifier_1 = __importDefault(require("./AirPurifier"));
var LightBrightness;
(function (LightBrightness) {
LightBrightness[LightBrightness["OFF"] = 0] = "OFF";
LightBrightness[LightBrightness["ON"] = 1] = "ON";
LightBrightness[LightBrightness["LEVEL_1"] = 8] = "LEVEL_1";
LightBrightness[LightBrightness["LEVEL_2"] = 9] = "LEVEL_2";
LightBrightness[LightBrightness["LEVEL_3"] = 10] = "LEVEL_3";
})(LightBrightness = exports.LightBrightness || (exports.LightBrightness = {}));
class AeroTower extends AirPurifier_1.default {
constructor(platform, accessory) {
super(platform, accessory);
this.platform = platform;
this.accessory = accessory;
const { Service: { TemperatureSensor, HumiditySensor, Switch, }, Characteristic, } = this.platform;
this.serviceTemperatureSensor = accessory.getService(TemperatureSensor)
|| accessory.addService(TemperatureSensor, 'Temperature Sensor');
this.serviceHumiditySensor = accessory.getService(HumiditySensor)
|| accessory.addService(HumiditySensor, 'Humidity Sensor');
this.serviceLight.getCharacteristic(Characteristic.Brightness)
.setProps({
maxValue: 3, // 3 level of light
})
.onSet(this.setLightBrightness.bind(this));
this.serviceUVNano = accessory.getService(Switch) || accessory.addService(Switch, 'UV Purifier');
this.serviceUVNano.getCharacteristic(Characteristic.On).onSet(this.setUVMode.bind(this));
}
async setLight(value) {
var _a;
if (!this.Status.isPowerOn) {
return;
}
const device = this.accessory.context.device;
const isLightOn = value ? 1 : 0;
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(device.id, {
dataKey: 'airState.lightingState.displayControl',
dataValue: isLightOn,
}).then(() => {
device.data.snapshot['airState.lightingState.displayControl'] = isLightOn;
this.updateAccessoryCharacteristic(device);
});
}
setUVMode(value) {
var _a;
const uvModeValue = value ? 1 : 0;
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(this.accessory.context.device, {
dataKey: 'airState.miscFuncState.Uvnano',
dataValue: uvModeValue,
}).then(() => {
this.accessory.context.device.data.snapshot['airState.miscFuncState.Uvnano'] = uvModeValue;
this.updateAccessoryCharacteristic(this.accessory.context.device);
});
}
setLightBrightness(value) {
var _a;
const brightnessValue = value - 1;
const values = [LightBrightness.LEVEL_1, LightBrightness.LEVEL_2, LightBrightness.LEVEL_3];
if (typeof values[brightnessValue] !== 'undefined') {
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(this.accessory.context.device, {
dataKey: 'airState.lightingState.displayControl',
dataValue: values[brightnessValue],
}).then(() => {
this.accessory.context.device.data.snapshot['airState.lightingState.displayControl'] = values[brightnessValue];
this.updateAccessoryCharacteristic(this.accessory.context.device);
});
}
}
updateAccessoryCharacteristic(device) {
super.updateAccessoryCharacteristic(device);
const { Characteristic, } = this.platform;
const snapshot = device.data.snapshot;
// light brightness
const values = [LightBrightness.LEVEL_1, LightBrightness.LEVEL_2, LightBrightness.LEVEL_3];
const brightnessValue = values.indexOf(snapshot['airState.lightingState.displayControl'] || 0);
if (brightnessValue !== -1) {
this.serviceLight.updateCharacteristic(Characteristic.Brightness, brightnessValue + 1);
}
if (typeof snapshot['airState.tempState.current'] !== 'undefined') {
this.serviceTemperatureSensor.updateCharacteristic(Characteristic.CurrentTemperature, snapshot['airState.tempState.current']);
}
if (typeof snapshot['airState.humidity.current'] !== 'undefined') {
this.serviceHumiditySensor.updateCharacteristic(Characteristic.CurrentRelativeHumidity, snapshot['airState.humidity.current']);
}
// uv mode
this.serviceUVNano.updateCharacteristic(Characteristic.On, !!(snapshot['airState.miscFuncState.Uvnano'] || 0));
}
}
exports.default = AeroTower;
//# sourceMappingURL=AeroTower.js.map