@elshaer/homebridge-lg-thinq
Version:
A Homebridge plugin for controlling/monitoring LG ThinQ device via LG ThinQ platform.
77 lines • 3.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NOT_RUNNING_STATUS = void 0;
const baseDevice_1 = require("../baseDevice");
exports.NOT_RUNNING_STATUS = ['POWEROFF', 'INITIAL', 'PAUSE', 'COMPLETE', 'ERROR', 'DIAGNOSIS', 'RESERVED',
'SLEEP', 'FOTA'];
class Styler extends baseDevice_1.baseDevice {
constructor(platform, accessory) {
super(platform, accessory);
this.platform = platform;
this.accessory = accessory;
const device = this.accessory.context.device;
const { Service: { Valve, }, Characteristic, } = this.platform;
this.serviceStyter = accessory.getService(Valve) || accessory.addService(Valve, device.name);
this.serviceStyter.getCharacteristic(Characteristic.Active)
.onSet(this.setActive.bind(this))
.updateValue(Characteristic.Active.INACTIVE);
this.serviceStyter.setCharacteristic(Characteristic.Name, device.name);
this.serviceStyter.setCharacteristic(Characteristic.ValveType, Characteristic.ValveType.GENERIC_VALVE);
this.serviceStyter.setCharacteristic(Characteristic.InUse, Characteristic.InUse.NOT_IN_USE);
this.serviceStyter.getCharacteristic(Characteristic.RemainingDuration).setProps({
maxValue: 86400, // 1 day
});
}
updateAccessoryCharacteristic(device) {
super.updateAccessoryCharacteristic(device);
const { Characteristic, } = this.platform;
this.serviceStyter.updateCharacteristic(Characteristic.Active, this.Status.isPowerOn ? 1 : 0);
this.serviceStyter.updateCharacteristic(Characteristic.InUse, this.Status.isRunning ? 1 : 0);
const prevRemainDuration = this.serviceStyter.getCharacteristic(Characteristic.RemainingDuration).value;
if (this.Status.remainDuration !== prevRemainDuration) {
this.serviceStyter.updateCharacteristic(Characteristic.RemainingDuration, this.Status.remainDuration);
}
this.serviceStyter.updateCharacteristic(Characteristic.StatusFault, this.Status.isError ? Characteristic.StatusFault.GENERAL_FAULT : Characteristic.StatusFault.NO_FAULT);
}
async setActive(value) {
if (this.Status.isRemoteStartOn) {
// turn on styler
}
}
get Status() {
var _a;
return new StylerStatus((_a = this.accessory.context.device.snapshot) === null || _a === void 0 ? void 0 : _a.styler, this.accessory.context.device.deviceModel);
}
}
exports.default = Styler;
class StylerStatus {
constructor(data, deviceModel) {
this.data = data;
this.deviceModel = deviceModel;
}
get isPowerOn() {
var _a;
return !['POWEROFF', 'POWERFAIL'].includes((_a = this.data) === null || _a === void 0 ? void 0 : _a.state);
}
get isRemoteStartOn() {
return this.data.remoteStart === this.deviceModel.lookupMonitorName('remoteStart', '@CP_ON_EN_W');
}
get isRunning() {
var _a;
return this.isPowerOn && !exports.NOT_RUNNING_STATUS.includes((_a = this.data) === null || _a === void 0 ? void 0 : _a.state);
}
get isError() {
var _a;
return ((_a = this.data) === null || _a === void 0 ? void 0 : _a.state) === 'ERROR';
}
get remainDuration() {
var _a, _b;
const remainTimeHour = ((_a = this.data) === null || _a === void 0 ? void 0 : _a.remainTimeHour) || 0, remainTimeMinute = ((_b = this.data) === null || _b === void 0 ? void 0 : _b.remainTimeMinute) || 0;
let remainingDuration = 0;
if (this.isRunning) {
remainingDuration = remainTimeHour * 3600 + remainTimeMinute * 60;
}
return remainingDuration;
}
}
//# sourceMappingURL=Styler.js.map