UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

50 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PowerState = exports.PowerStateName = void 0; const _ultimate_govee_common_1 = require("../../../common"); const device_state_1 = require("./device.state"); const states_types_1 = require("./states.types"); exports.PowerStateName = 'power'; class PowerState extends device_state_1.DeviceOpState { constructor(device, opType = _ultimate_govee_common_1.OpType.REPORT, identifier = [0x01]) { super({ opType, identifier }, device, exports.PowerStateName, undefined, states_types_1.ParseOption.opCode.or(states_types_1.ParseOption.state)); this.stateToCommand = (nextState) => { if (nextState === undefined) { this.logger.warn('Power was not specified, ignoring command'); return; } return { command: [ { command: 'turn', data: { value: nextState === true ? 1 : 0, }, }, ], status: { state: { isOn: nextState, }, }, }; }; } parseState(data) { const { isOn, state } = data; if ((0, _ultimate_govee_common_1.isTypeOf)(isOn, 'boolean')) { this.stateValue.next(isOn); } else { const { onOff, isOn } = state ?? {}; if ((0, _ultimate_govee_common_1.isTypeOf)(onOff, 'boolean')) { this.stateValue.next(onOff); } else if ((0, _ultimate_govee_common_1.isTypeOf)(isOn, 'boolean')) { this.stateValue.next(isOn); } } } } exports.PowerState = PowerState; //# sourceMappingURL=power.state.js.map