@pietrolubini/homebridge-ecoflow
Version:
Homebridge plugin for EcoFlow devices
29 lines • 1.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SwitchServiceBase = void 0;
const serviceBase_1 = require("@ecoflow/services/serviceBase");
class SwitchServiceBase extends serviceBase_1.ServiceBase {
state = false;
constructor(ecoFlowAccessory, serviceSubType) {
super(ecoFlowAccessory.platform.Service.Switch, ecoFlowAccessory, serviceSubType);
}
updateState(state) {
this.state = state;
this.updateCharacteristic(this.platform.Characteristic.On, 'State', state);
}
onDisabled() {
this.updateState(false);
}
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.service.setCharacteristic(this.platform.Characteristic.Name, this.serviceName);
return [onCharacteristic];
}
}
exports.SwitchServiceBase = SwitchServiceBase;
//# sourceMappingURL=switchServiceBase.js.map