@elshaer/homebridge-lg-thinq
Version:
A Homebridge plugin for controlling/monitoring LG ThinQ device via LG ThinQ platform.
92 lines • 4.33 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const baseDevice_1 = require("../baseDevice");
const DeviceModel_1 = require("../lib/DeviceModel");
class RangeHood extends baseDevice_1.baseDevice {
constructor(platform, accessory) {
super(platform, accessory);
this.platform = platform;
this.accessory = accessory;
const device = this.accessory.context.device;
const { Service: { Fan, Lightbulb, }, Characteristic, } = this.platform;
this.serviceHood = accessory.getService(Fan) || accessory.addService(Fan, device.name);
this.serviceHood.updateCharacteristic(Characteristic.Name, device.name);
this.serviceHood.getCharacteristic(Characteristic.On)
.onSet(this.setHoodActive.bind(this));
this.serviceHood.getCharacteristic(Characteristic.RotationSpeed)
.onSet(this.setHoodRotationSpeed.bind(this));
const ventLevelSpec = device.deviceModel.value('VentLevel');
if ((ventLevelSpec === null || ventLevelSpec === void 0 ? void 0 : ventLevelSpec.type) === DeviceModel_1.ValueType.Range) {
this.serviceHood.getCharacteristic(Characteristic.RotationSpeed)
.setProps({
minValue: ventLevelSpec.min,
maxValue: ventLevelSpec.max,
minStep: ventLevelSpec.step,
});
}
// vent lamp
this.serviceLight = accessory.getService(Lightbulb) || accessory.addService(Lightbulb, device.name + ' - Light');
this.serviceLight.updateCharacteristic(Characteristic.Name, device.name + ' - Light');
this.serviceLight.getCharacteristic(Characteristic.On)
.onSet(this.setLightActive.bind(this));
this.serviceLight.getCharacteristic(Characteristic.Brightness)
.onSet(this.setLightBrightness.bind(this));
const ventLightSpec = device.deviceModel.value('LampLevel');
if ((ventLightSpec === null || ventLightSpec === void 0 ? void 0 : ventLightSpec.type) === DeviceModel_1.ValueType.Range) {
this.serviceLight.getCharacteristic(Characteristic.Brightness)
.setProps({
minValue: ventLightSpec.min,
maxValue: ventLightSpec.max,
minStep: ventLightSpec.step,
});
}
this.updateAccessoryCharacteristic(device);
}
async setHoodActive(value) {
await this.setHoodRotationSpeed(value ? 1 : 0);
}
async setHoodRotationSpeed(value) {
var _a;
const device = this.accessory.context.device;
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(device, {
dataKey: null,
dataValue: null,
dataSetList: {
hoodState: {
ventLevel: value,
},
},
dataGetList: null,
});
}
async setLightActive(value) {
await this.setLightBrightness(value ? 1 : 0);
}
async setLightBrightness(value) {
var _a;
const device = this.accessory.context.device;
(_a = this.platform.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(device, {
dataKey: null,
dataValue: null,
dataSetList: {
hoodState: {
lampLevel: value,
},
},
dataGetList: null,
});
}
updateAccessoryCharacteristic(device) {
super.updateAccessoryCharacteristic(device);
const hoodState = device.snapshot.hoodState;
const isVentOn = hoodState['ventSet'] === device.deviceModel.lookupMonitorName('VentSet', '@CP_ENABLE_W');
const isLampOn = hoodState['lampSet'] === device.deviceModel.lookupMonitorName('LampSet', '@CP_ENABLE_W');
const { Characteristic, } = this.platform;
this.serviceHood.updateCharacteristic(Characteristic.On, isVentOn);
this.serviceHood.updateCharacteristic(Characteristic.RotationSpeed, hoodState['ventLevel']);
this.serviceLight.updateCharacteristic(Characteristic.On, isLampOn);
this.serviceLight.updateCharacteristic(Characteristic.Brightness, hoodState['lampLevel']);
}
}
exports.default = RangeHood;
//# sourceMappingURL=RangeHood.js.map