How to use the alcalzone-shared/math.clamp function in alcalzone-shared

To help you get started, we’ve selected a few alcalzone-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AlCalzone / node-tradfri-client / src / lib / conversions.ts View on Github external
const colorTemperature_in: PropertyTransformKernel = (value) => {
	const [min, max] = colorTemperatureRange;
	// interpolate "color percentage" from the colorTemperature range of a lightbulb
	value = (value - min) / (max - min);
	value = clamp(value, 0, 1);
	return roundTo(value * 100, 1);
};
github AlCalzone / node-tradfri-client / build / lib / conversions.js View on Github external
    [r, g, b] = [r, g, b].map(c => Math.round(math_1.clamp(c, 0, 1) * 255));
    return { r, g, b };
github AlCalzone / node-tradfri-client / build / lib / light.js View on Github external
setBrightness(value, transitionTime) {
        this.ensureLink();
        value = math_1.clamp(value, 0, 100);
        return this.operateLight({
            dimmer: value,
        }, transitionTime);
    }
    /**
github AlCalzone / node-tradfri-client / build / lib / group.js View on Github external
setBrightness(value, transitionTime) {
        this.ensureLink();
        value = math_1.clamp(value, 0, 100);
        return this.operateGroup({
            dimmer: value,
        }, transitionTime);
    }
    /**
github AlCalzone / node-tradfri-client / src / lib / group.ts View on Github external
public setPosition(value: number): Promise {
		this.ensureLink();

		value = clamp(value, 0, 100);
		return this.operateGroup({
			position: value,
		});
	}
github AlCalzone / node-tradfri-client / src / lib / light.ts View on Github external
public setHue(value: number, transitionTime?: number): Promise {
		this.ensureLink();
		if (this.spectrum !== "rgb") throw new Error("setHue is only available for RGB lightbulbs");

		value = clamp(value, 0, 360);
		return this.operateLight({
			hue: value,
		}, transitionTime);
	}
github AlCalzone / node-tradfri-client / src / lib / light.ts View on Github external
public setColorTemperature(value: number, transitionTime?: number): Promise {
		this.ensureLink();
		if (this.spectrum !== "white") throw new Error("setColorTemperature is only available for white spectrum lightbulbs");

		value = clamp(value, 0, 100);
		return this.operateLight({
			colorTemperature: value,
		}, transitionTime);
	}
github AlCalzone / node-tradfri-client / src / lib / blind.ts View on Github external
public setPosition(value: number): Promise {
		value = clamp(value, 0, 100);
		return this.operateBlind({ position: value });
	}
github AlCalzone / node-tradfri-client / src / lib / conversions.ts View on Github external
const brightness_in: PropertyTransformKernel = (value) => {
	value = clamp(value, 0, 254);
	if (value === 0) return 0;
	value = value / 254 * 100;
	return roundTo(value, 1);
};
github AlCalzone / node-tradfri-client / build / lib / blind.js View on Github external
setPosition(value) {
        value = math_1.clamp(value, 0, 100);
        return this.operateBlind({ position: value });
    }
    /** Turns this object into JSON while leaving out the potential circular reference */