UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

99 lines 4.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.IceMakerScheduledStart = exports.ScheduledStartStateName = void 0; const states_1 = require("../../../states"); const types_1 = require("./types"); const _ultimate_govee_common_1 = require("../../../../../common"); const moment_1 = __importDefault(require("moment")); exports.ScheduledStartStateName = 'scheduledStart'; const getStartTimeUTC = (startHour, startMinute) => { const startTime = (0, moment_1.default)().hour(startHour).minute(startMinute).second(0); if (startTime.isBefore((0, moment_1.default)())) { startTime.add(1, 'day'); } return startTime.utc(); }; class IceMakerScheduledStart extends states_1.DeviceOpState { constructor(device) { super({ opType: _ultimate_govee_common_1.OpType.REPORT, identifier: [35] }, device, exports.ScheduledStartStateName, {}); this.stateToCommand = (state) => { if (state.enabled === undefined) { this.logger.warn('Enabled is not included in the state, ignoring command'); return; } if (state.enabled !== true) { if (!state.enabled) { return { command: { data: { command: [(0, _ultimate_govee_common_1.asOpCode)(_ultimate_govee_common_1.OpType.COMMAND, this.identifier, 0x00)], }, }, status: { op: { command: [[0x00]], }, }, }; } } if (state.hourStart === undefined) { this.logger.warn('hourStart not included in the state, ignoring command'); return; } if (state.minuteStart === undefined) { this.logger.warn('minuteStart not included in the state, ignoring command'); return; } if (state.nuggetSize === undefined) { this.logger.warn('Nugget size not included in the state, igrnoging command'); return; } const startTime = getStartTimeUTC(state.hourStart, state.minuteStart); const timestampSec = Math.round(startTime.valueOf() / 1000); const minutes = moment_1.default.duration(startTime.diff((0, moment_1.default)().utc())).asMinutes(); const opCodes = [ 0x01, ...[0x00, ...(0, _ultimate_govee_common_1.hexStringToArray)(Math.round(minutes).toString(16))].slice(-2), ...((0, _ultimate_govee_common_1.unpaddedHexToArray)(timestampSec.toString(16)) ?? []), types_1.nuggetSizeMap[state.nuggetSize.toString()], ]; return { command: { data: { command: [(0, _ultimate_govee_common_1.asOpCode)(_ultimate_govee_common_1.OpType.COMMAND, this.identifier, opCodes)], }, }, status: { op: { command: [opCodes], }, }, }; }; } parseOpCommand(opCommand) { if (opCommand[0] === 0x00) { this.stateValue.next({ enabled: false, hourStart: undefined, minuteStart: undefined, nuggetSize: undefined, }); return; } const timestamp = (0, _ultimate_govee_common_1.total)(opCommand.slice(3, 7)); const startDate = new Date(timestamp); this.stateValue.next({ enabled: opCommand[0] === 0x01, hourStart: startDate.getHours(), minuteStart: startDate.getMinutes(), nuggetSize: types_1.NuggetSize[Object.entries(types_1.nuggetSizeMap).find(([_, num]) => num === opCommand[7])?.[0] ?? 'SMALL'], }); } } exports.IceMakerScheduledStart = IceMakerScheduledStart; //# sourceMappingURL=ice-maker.scheduled-start.js.map