UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

62 lines 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BrightnessState = exports.BrightnessStateName = void 0; const _ultimate_govee_common_1 = require("../../../common"); const device_state_1 = require("./device.state"); const op_code_1 = require("../../../common/op-code"); const states_types_1 = require("./states.types"); exports.BrightnessStateName = 'brightness'; class BrightnessState extends device_state_1.DeviceOpState { constructor(device, opType = op_code_1.OpType.REPORT, identifier = [0x04], parseOption = states_types_1.ParseOption.opCode.or(states_types_1.ParseOption.state)) { super({ opType, identifier }, device, exports.BrightnessStateName, undefined, parseOption); this.stateToCommand = (nextState) => { if (!(0, _ultimate_govee_common_1.isBetween)(nextState, 0, 100)) { this.logger.warn('Invalid or missing state, ignoring command.'); return; } return { status: [ { state: { brightness: nextState, }, }, { op: { command: [[nextState]], }, }, ], command: [ { command: 'brightness', data: { val: nextState, }, }, { data: { command: [(0, _ultimate_govee_common_1.asOpCode)(op_code_1.OpType.COMMAND, this.identifier, nextState)], }, }, ], }; }; } parseState(data) { const brightness = data?.state?.brightness; if (!(0, _ultimate_govee_common_1.isBetween)(brightness, 0, 100)) { return; } this.stateValue.next(brightness); } parseOpCommand(opCommand) { const [brightness] = opCommand.slice(0, 1); if (!(0, _ultimate_govee_common_1.isBetween)(brightness, 0, 100)) { return; } this.stateValue.next(brightness); } } exports.BrightnessState = BrightnessState; //# sourceMappingURL=brightness.state.js.map