UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

83 lines 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PurifierFanSpeedState = exports.FanSpeedStateName = void 0; const _ultimate_govee_common_1 = require("../../../../../common"); const states_1 = require("../../../states"); const purifier_modes_1 = require("./purifier.modes"); exports.FanSpeedStateName = 'fanSpeed'; class PurifierFanSpeedState extends states_1.DeviceOpState { constructor(device, active = undefined, opType = _ultimate_govee_common_1.OpType.REPORT, identifier = [0x05]) { super({ opType, identifier }, device, exports.FanSpeedStateName, undefined); this.active = active; this.stateToCommand = (nextState) => { return { command: { data: { command: [ (0, _ultimate_govee_common_1.asOpCode)(0x33, this.identifier, nextState === 0 || nextState === undefined ? 16 : nextState - 1), ], }, }, status: { op: { command: [ [nextState === 0 || nextState === undefined ? 16 : nextState - 1], ], }, }, }; }; if (active !== undefined) { active?.subscribe((event) => { if (this.subscription !== undefined) { this.subscription.unsubscribe(); } switch (event?.name) { case purifier_modes_1.CustomModeStateName: this.subscription = event?.subscribe((event) => { const speed = event?.fanSpeed; this.stateValue.next(speed ? speed * 25 : speed); }); break; case purifier_modes_1.ManualModeStateName: this.subscription = event?.subscribe((event) => { const speed = event; this.stateValue.next(speed ? speed * 25 : speed); }); break; default: this.stateValue.next(undefined); break; } }); } } parseOpCommand(opCommand) { if (this.active !== undefined) { return; } const speed = opCommand[0] !== 16 ? opCommand[0] + 1 : 1; this.stateValue.next(speed * 25); } setState(nextState) { if (this.active === undefined) { return super.setState(nextState); } if (this.active.value === undefined) { this.logger.log('Unable to determine current mode, ignoring command'); return []; } switch (this.active.value.name) { case purifier_modes_1.ManualModeStateName: return this.active.value.setState(nextState); case purifier_modes_1.CustomModeStateName: return this.active.value.setState({ fanSpeed: nextState, }); default: return []; } } } exports.PurifierFanSpeedState = PurifierFanSpeedState; //# sourceMappingURL=purifier.fan-speed.js.map