UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

47 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ActiveState = exports.ActiveStateName = void 0; const _ultimate_govee_common_1 = require("../../../common"); const device_state_1 = require("./device.state"); const states_types_1 = require("./states.types"); exports.ActiveStateName = 'isActive'; class ActiveState extends device_state_1.DeviceOpState { constructor(device, opType = _ultimate_govee_common_1.OpType.REPORT, identifier = [0x01]) { super({ opType, identifier }, device, exports.ActiveStateName, undefined); this.parseOption = states_types_1.ParseOption.opCode.or(states_types_1.ParseOption.state); this.stateToCommand = (state) => { if (!(0, _ultimate_govee_common_1.isTypeOf)(state, 'boolean')) { this.logger.warn('state not provided, skipping command.'); return undefined; } return { command: { data: { command: [ (0, _ultimate_govee_common_1.asOpCode)(_ultimate_govee_common_1.OpType.COMMAND, this.identifier, state ? 0x01 : 0x00), ], }, }, status: { op: { command: [[state ? 0x01 : 0x00]], }, }, }; }; } parseState(data) { if (!(0, _ultimate_govee_common_1.isTypeOf)(data.state?.isOn, 'boolean')) { return; } this.stateValue.next(data.state.isOn); } parseOpCommand(opCommand) { if (![0x00, 0x01].includes(opCommand[0])) { return; } this.stateValue.next(opCommand[0] === 0x01); } } exports.ActiveState = ActiveState; //# sourceMappingURL=active.state.js.map