@shadman-a/homebridge-my-ac
Version:
A Homebridge plugin for controlling/monitoring LG ThinQ devices via LG ThinQ platform.
91 lines • 4.01 kB
JavaScript
import { BaseDevice } from '../baseDevice.js';
import { ValueType } from '../lib/DeviceModel.js';
export default class RangeHood extends BaseDevice {
platform;
accessory;
serviceHood;
serviceLight;
constructor(platform, accessory, logger) {
super(platform, accessory, logger);
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?.type === 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?.type === 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) {
const device = this.accessory.context.device;
this.platform.ThinQ?.deviceControl(device, {
dataKey: null,
dataValue: null,
dataSetList: {
hoodState: {
ventLevel: value,
},
},
dataGetList: null,
});
}
async setLightActive(value) {
await this.setLightBrightness(value ? 1 : 0);
}
async setLightBrightness(value) {
const device = this.accessory.context.device;
this.platform.ThinQ?.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);
}
}
//# sourceMappingURL=RangeHood.js.map