@constructorfleet/ultimate-govee
Version:
Library for interacting with Govee devices written in Typescript.
62 lines • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColorTempState = exports.ColorTempStateName = void 0;
const _ultimate_govee_common_1 = require("../../../common");
const device_state_1 = require("./device.state");
const states_types_1 = require("./states.types");
exports.ColorTempStateName = 'colorTemperature';
class ColorTempState extends device_state_1.DeviceOpState {
constructor(device, opType = undefined, ...identifier) {
super({ opType, identifier }, device, exports.ColorTempStateName, {}, states_types_1.ParseOption.state);
this.stateToCommand = (nextState) => {
const { min, max } = nextState?.range ?? this.stateValue.getValue()?.range ?? {};
if ((0, _ultimate_govee_common_1.isTypeOf)(min, 'number') && (0, _ultimate_govee_common_1.isTypeOf)(max, 'number')) {
if (!(0, _ultimate_govee_common_1.isBetween)(nextState.current, min, max)) {
this.logger.warn('Invalid or missing color temperature, ignoring command');
return undefined;
}
}
else {
if (!(0, _ultimate_govee_common_1.isTypeOf)(nextState.current, 'number')) {
this.logger.warn('Invalid or missing color temperature, ignoring command');
return undefined;
}
}
return {
status: {
state: {
colorTemperature: {
current: nextState.current,
},
},
},
command: {
command: 'colorTem',
data: {
colorTemInKelvin: nextState.current,
},
},
};
};
}
parseState(data) {
const currentValue = this.stateValue.getValue();
const colorTemperature = data?.state?.colorTemperature;
const current = colorTemperature?.current ?? currentValue.current;
const min = colorTemperature?.min ?? currentValue.range?.min;
const max = colorTemperature?.max ?? currentValue.range?.max;
if (current !== undefined) {
if (min !== undefined && current < min) {
return;
}
if (max !== undefined && current > max) {
return;
}
}
if (data?.state?.colorTemperature !== undefined) {
this.stateValue.next(data.state.colorTemperature);
}
}
}
exports.ColorTempState = ColorTempState;
//# sourceMappingURL=color-temp.state.js.map