UNPKG

homebridge-rituals-genie

Version:
103 lines 5.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FanAccessory = void 0; class FanAccessory { constructor(platform, accessory) { var _a, _b, _c, _d, _e; this.platform = platform; this.accessory = accessory; // set accessory information this.accessory.getService(this.platform.Service.AccessoryInformation) .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Rituals') .setCharacteristic(this.platform.Characteristic.Model, 'Perfume Genie') .setCharacteristic(this.platform.Characteristic.SerialNumber, (_b = (_a = this.platform.hub) === null || _a === void 0 ? void 0 : _a.hublot) !== null && _b !== void 0 ? _b : '') .setCharacteristic(this.platform.Characteristic.FirmwareRevision, (_e = (_d = (_c = this.platform.hub) === null || _c === void 0 ? void 0 : _c.sensors) === null || _d === void 0 ? void 0 : _d.versionc) !== null && _e !== void 0 ? _e : ''); // set filter maintenance // this.accessory.getService(this.platform.Service.FilterMaintenance)! // .setCharacteristic(this.platform.Characteristic.FilterChangeIndication, this.platform.Characteristic.FilterChangeIndication.FILTER_OK) // .setCharacteristic(this.platform.Characteristic.Name, this.platform.hub?.sensors?.rfidc?.title ?? ''); this.service = this.accessory.getService(this.platform.Service.Fan) || this.accessory.addService(this.platform.Service.Fan); this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.displayName); this.service.getCharacteristic(this.platform.Characteristic.On) .onSet(this.setOn.bind(this)) .onGet(this.getOn.bind(this)); this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed) .setProps({ minStep: 100 / 3, minValue: 0, maxValue: 100, validValues: [0, 100 / 3, (100 / 3) * 2, 100], }) .onSet(this.setFanSpeed.bind(this)) .onGet(this.getFanSpeed.bind(this)); } async setOn(value) { this.platform.log.info('Set Characteristic On ->', value); await this.platform.updateOnState(value); } async getOn() { var _a, _b; await this.platform.getStateForHub(); // if (this.platform.lastHubState && new Date().getTime() - this.platform.lastHubState.getTime() > 60000) { // await this.platform.getStateForHub(); // } const isOn = (_b = ((_a = this.platform.hub) === null || _a === void 0 ? void 0 : _a.attributes.fanc) == '1') !== null && _b !== void 0 ? _b : false; this.platform.log.info('Get Characteristic On ->', isOn); return isOn; } async setFanSpeed(value) { var _a, _b, _c; this.platform.log.info('Fan Speed Value Start ->', value); if (((_a = this.platform.hub) === null || _a === void 0 ? void 0 : _a.attributes.fanc) == '1') { let apiFanSpeed = (_c = (_b = this.platform.hub) === null || _b === void 0 ? void 0 : _b.attributes.speedc) !== null && _c !== void 0 ? _c : '1'; if (value <= 100 / 3) { this.platform.log.info('Fan Speed value <= 33'); apiFanSpeed = '1'; } else if (value > 100 / 3 && value <= (100 / 3) * 2) { this.platform.log.info('Fan Speed value <= 66'); apiFanSpeed = '2'; } else if (value > (100 / 3) * 2) { this.platform.log.info('Fan Speed value > 66'); apiFanSpeed = '3'; } this.platform.log.info('Fan Speed Value ->', value); this.platform.log.info('Set FanSpeed ->', apiFanSpeed); await this.platform.updateFanSpeed(apiFanSpeed); } } async getFanSpeed() { var _a, _b; // If fan is off then return 0 if (((_a = this.platform.hub) === null || _a === void 0 ? void 0 : _a.attributes.fanc) == '0') { return 0; } else { await this.platform.getStateForHub(); // if (this.platform.lastHubState && new Date().getTime() - this.platform.lastHubState.getTime() > 60000) { // await this.platform.getStateForHub(); // } const apiFanSpeed = (_b = this.platform.hub) === null || _b === void 0 ? void 0 : _b.attributes.speedc; let fanSpeed; switch (apiFanSpeed) { case '1': fanSpeed = 100 / 3; break; case '2': fanSpeed = (100 / 3) * 2; break; case '3': fanSpeed = 100; break; default: fanSpeed = 0; break; } this.platform.log.info('Get FanSpeed ->', fanSpeed); return fanSpeed; } } } exports.FanAccessory = FanAccessory; //# sourceMappingURL=FanAccessory.js.map