UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

60 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DisplayScheduleState = exports.DisplayScheduleStateName = void 0; const _ultimate_govee_common_1 = require("../../../common"); const device_state_1 = require("./device.state"); exports.DisplayScheduleStateName = 'displaySchedule'; class DisplayScheduleState extends device_state_1.DeviceOpState { constructor(device, opType = _ultimate_govee_common_1.OpType.REPORT, ...identifier) { super({ opType, identifier }, device, exports.DisplayScheduleStateName, {}); this.stateToCommand = (state) => { if (!(0, _ultimate_govee_common_1.isTypeOf)(state?.on, 'boolean') || !(0, _ultimate_govee_common_1.isTypeOf)(state?.from?.hour, 'number') || !(0, _ultimate_govee_common_1.isTypeOf)(state?.from?.minute, 'number') || !(0, _ultimate_govee_common_1.isTypeOf)(state?.to?.hour, 'number') || !(0, _ultimate_govee_common_1.isTypeOf)(state?.to?.minute, 'number')) { this.logger.warn('Missing or invalide state, ignoring command'); return; } const isOn = state.on === true; const values = isOn ? [ state.from.hour ?? 0x00, state.from.minute ?? 0x00, state.to.hour ?? 0x00, state.to.minute ?? 0x00, ] : []; return { status: { op: { command: [[state.on ? 0x01 : 0x00]], }, }, command: { data: { command: [ (0, _ultimate_govee_common_1.asOpCode)(_ultimate_govee_common_1.OpType.COMMAND, ...this.identifier, state.on ? 0x01 : 0x00, ...values), ], }, }, }; }; } parseOpCommand(opCommand) { const [on, fromHour, fromMinute, toHour, toMinute] = opCommand.slice(0, 7); this.stateValue.next({ on: on === 0x01, from: { hour: fromHour, minute: fromMinute, }, to: { hour: toHour, minute: toMinute, }, }); } } exports.DisplayScheduleState = DisplayScheduleState; //# sourceMappingURL=display-schedule.state.js.map