@pietrolubini/homebridge-ecoflow
Version:
Homebridge plugin for EcoFlow devices
48 lines • 2.37 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FanServiceBase = void 0;
const serviceBase_1 = require("@ecoflow/services/serviceBase");
class FanServiceBase extends serviceBase_1.ServiceBase {
ecoFlowAccessory;
maxRotationSpeed;
state = false;
rotationSpeedPercents = 0;
rotationSpeed = 0;
rotationSpeedCharacteristic = null;
constructor(ecoFlowAccessory, maxRotationSpeed, serviceSubType) {
super(ecoFlowAccessory.platform.Service.Fan, ecoFlowAccessory, serviceSubType);
this.ecoFlowAccessory = ecoFlowAccessory;
this.maxRotationSpeed = maxRotationSpeed;
}
addCharacteristics() {
const onCharacteristic = this.addCharacteristic(this.platform.Characteristic.On)
.onGet(() => this.processOnGet(this.state))
.onSet(value => this.processOnSet(this.platform.Characteristic.On.name, () => {
this.state = value;
this.processOnSetOn(this.state, () => this.updateState(!this.state));
}));
this.rotationSpeedCharacteristic = this.addCharacteristic(this.platform.Characteristic.RotationSpeed)
.onGet(() => this.processOnGet(this.rotationSpeedPercents))
.onSet(percents => this.processOnSet(this.platform.Characteristic.RotationSpeed.name, () => {
this.rotationSpeedPercents = percents;
const prevRotationSpeed = this.rotationSpeed;
this.rotationSpeed = this.covertPercentsToValue(this.rotationSpeedPercents, this.maxRotationSpeed);
this.processOnSetRotationSpeed(this.rotationSpeed, () => this.updateRotationSpeed(prevRotationSpeed));
}));
return [onCharacteristic, this.rotationSpeedCharacteristic];
}
updateState(state) {
this.state = state;
this.updateCharacteristic(this.platform.Characteristic.On, 'State', state);
}
updateRotationSpeed(value) {
this.rotationSpeedPercents = this.covertValueToPercents(value, this.maxRotationSpeed);
this.updateCharacteristic(this.platform.Characteristic.RotationSpeed, 'RotationSpeed', this.rotationSpeedPercents);
this.rotationSpeed = value;
}
setRotationSpeed(value) {
this.rotationSpeedCharacteristic?.setValue(value);
}
}
exports.FanServiceBase = FanServiceBase;
//# sourceMappingURL=fanServiceBase.js.map