Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};
[r, g, b] = [r, g, b].map(c => Math.round(math_1.clamp(c, 0, 1) * 255));
return { r, g, b };
setBrightness(value, transitionTime) {
this.ensureLink();
value = math_1.clamp(value, 0, 100);
return this.operateLight({
dimmer: value,
}, transitionTime);
}
/**
setBrightness(value, transitionTime) {
this.ensureLink();
value = math_1.clamp(value, 0, 100);
return this.operateGroup({
dimmer: value,
}, transitionTime);
}
/**
public setPosition(value: number): Promise {
this.ensureLink();
value = clamp(value, 0, 100);
return this.operateGroup({
position: value,
});
}
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);
}
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);
}
public setPosition(value: number): Promise {
value = clamp(value, 0, 100);
return this.operateBlind({ position: value });
}
const brightness_in: PropertyTransformKernel = (value) => {
value = clamp(value, 0, 254);
if (value === 0) return 0;
value = value / 254 * 100;
return roundTo(value, 1);
};
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 */