@constructorfleet/ultimate-govee
Version:
Library for interacting with Govee devices written in Typescript.
54 lines • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimerState = exports.TimerStateName = void 0;
const _ultimate_govee_common_1 = require("../../../common");
const device_state_1 = require("./device.state");
exports.TimerStateName = 'timer';
class TimerState extends device_state_1.DeviceOpState {
constructor(device, opType = _ultimate_govee_common_1.OpType.REPORT, ...identifier) {
super({ opType, identifier }, device, exports.TimerStateName, {
enabled: undefined,
duration: undefined,
});
this.stateToCommand = (state) => {
const enabled = state.enabled;
const duration = state.duration;
if (!(0, _ultimate_govee_common_1.isTypeOf)(enabled, 'boolean')) {
this.logger.warn('Enabled not included in state, ignoring command.');
return undefined;
}
if (!(0, _ultimate_govee_common_1.isTypeOf)(duration, 'number')) {
this.logger.warn('Duration not included in state, ignoring command.');
return undefined;
}
return {
command: {
data: {
command: [
(0, _ultimate_govee_common_1.asOpCode)(_ultimate_govee_common_1.OpType.COMMAND, ...this.identifier, enabled ? 0x01 : 0x00, duration >> 8, duration % 256),
],
},
},
status: (0, _ultimate_govee_common_1.ArrayRange)(15).map((x) => ({
op: {
command: [
[
state.enabled ? 0x01 : 0x00,
(state.duration - x) >> 8,
(state.duration - x) % 256,
],
],
},
})),
};
};
}
parseOpCommand(opCommand) {
this.stateValue.next({
enabled: opCommand[0] === 0x01,
duration: (0, _ultimate_govee_common_1.total)(opCommand.slice(1, 3)),
});
}
}
exports.TimerState = TimerState;
//# sourceMappingURL=timer.state.js.map