UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

70 lines 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HumidityState = exports.HumidityStateName = void 0; const _ultimate_govee_common_1 = require("../../../common"); const device_state_1 = require("./device.state"); const states_types_1 = require("./states.types"); exports.HumidityStateName = 'humidity'; class HumidityState extends device_state_1.DeviceOpState { constructor(device, opType = undefined, parseOption = states_types_1.ParseOption.state, ...identifier) { super({ opType, identifier }, device, exports.HumidityStateName, {}, parseOption); } parseState(data) { if (data?.state?.humidity !== undefined) { let calibration100 = data?.state?.humidity?.calibration; if (calibration100 !== undefined && calibration100 > 100) { calibration100 /= 100; } const calibration = calibration100 ?? this.stateValue.getValue().calibration; let current100 = data?.state?.humidity?.current; if (current100 !== undefined && current100 > 100) { current100 /= 100; } const current = current100 ?? this.stateValue.getValue().current; let raw; if (current !== undefined && calibration !== undefined) { raw = current - calibration; } else { raw = current; } const min = data?.state?.humidity?.min ?? this.stateValue.getValue().range?.min ?? 0; const max = data?.state?.humidity?.max ?? this.stateValue.getValue().range?.max ?? 0; if (current === undefined) { return; } if (current < min || current > max) { return; } this.stateValue.next({ calibration, range: { min, max, }, current, raw, }); } if (data?.state?.status?.code) { const { code } = data.state.status; const codes = (0, _ultimate_govee_common_1.unpaddedHexToArray)(code); if (codes !== undefined) { const calibration = this.stateValue.getValue().calibration ?? 0; const [humdidity] = codes.slice(2, 3); this.stateValue.next({ ...this.stateValue.getValue(), current: humdidity + calibration, raw: humdidity, calibration, }); } } } } exports.HumidityState = HumidityState; //# sourceMappingURL=humidity.state.js.map