UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

56 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TemperatureState = exports.TemperatureStateName = void 0; const device_state_1 = require("./device.state"); const states_types_1 = require("./states.types"); exports.TemperatureStateName = 'temperature'; class TemperatureState extends device_state_1.DeviceOpState { constructor(device, opType = undefined, parseOption = states_types_1.ParseOption.state, ...identifier) { super({ opType, identifier }, device, exports.TemperatureStateName, {}, parseOption); } parseState(data) { const previous = this.stateValue.getValue(); if (data?.state?.temperature !== undefined) { let calibration100 = data?.state?.temperature?.calibration; if (calibration100 !== undefined && calibration100 > 100) { calibration100 /= 100; } const calibration = calibration100 ?? previous.calibration; let current100 = data?.state?.temperature?.current; if (current100 !== undefined && current100 > 100) { current100 /= 100; } const current = current100 ?? previous.current; if (current === undefined) { return; } let raw; if (current !== undefined && calibration !== undefined) { raw = current - calibration; } else { raw = current; } const min = data?.state?.temperature?.min ?? previous.range?.min; const max = data?.state?.temperature?.max ?? previous.range?.max; const range = min !== undefined && max !== undefined ? { min, max, } : undefined; if ((min !== undefined && current < min) || (max !== undefined && current > max)) { return undefined; } this.stateValue.next({ calibration, range: range, current, raw, }); } } } exports.TemperatureState = TemperatureState; //# sourceMappingURL=temperature.state.js.map