Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const commandLineArgs = require('command-line-args')
const withLogging = require("../lib/with-logging");
const applyLightState = require("../lib/apply-light-state");
const applyLightStateToAll = require("../lib/apply-light-state-to-all");
const applyStateToAll = withLogging("turn all lights on")(applyLightStateToAll);
const optionDefinitions = [
{ name: 'id', type: Number, multiple: true },
{ name: 'all', alias: 'A', type: Boolean, defaultOption: false }
]
const options = commandLineArgs(optionDefinitions)
const state = lightState.create().on();
if (options.all) {
applyStateToAll(state);
process.exit(0);
}
if (!options.id) {
console.log("Provide one id at least or run with the --all flag.");
process.exit(0);
}
options.id.forEach(id => {
const applyState = withLogging(`turn light with id ${id} on`)(applyLightState)
applyState(id, state)
})
const commandLineArgs = require('command-line-args')
const withLogging = require("../lib/with-logging");
const applyLightState = require("../lib/apply-light-state");
const applyLightStateToAll = require("../lib/apply-light-state-to-all");
const applyStateToAll = withLogging("turn all lights off")(applyLightStateToAll);
const optionDefinitions = [
{ name: 'id', type: Number, multiple: true },
{ name: 'all', alias: 'A', type: Boolean, defaultOption: false }
]
const options = commandLineArgs(optionDefinitions)
const state = lightState.create().off();
if (options.all) {
applyStateToAll(state);
process.exit(0);
}
if (!options.id) {
console.log("Provide one id at least or run with the --all flag.");
process.exit(0);
}
options.id.forEach(id => {
const applyState = withLogging(`turn light with id ${id} off`)(applyLightState)
applyState(id, state)
})
setLightBrightness (light, event) {
this.props.api.setLightState(
light.id,
lightState.create().transitionFast().bri(event.target.value)
)
.done(this.props.api.updateState)
}
setColor (rgb) {
this.props.api.setLightState(
this.state.currentLight.id,
lightState.create().rgb(...rgb)
)
.done(this.props.api.updateState)
}
setColor (rgb) {
for (let light of this.state.currentLightGroup.lights) {
this.props.api.setLightState(
light,
lightState.create().rgb(...rgb)
)
.done(this.props.api.updateState)
}
}
if (!brightnessLevel) {
throw new Error("Brightness level argument is missing. Make sure you ran it like: `npm run set-brightness -- 70`");
}
if (brightnessLevel > 100) {
throw new Error("Brightness level cannot be above 100. Select a value between 0 and 100.");
}
if (brightnessLevel < 0) {
throw new Error("Brightness level cannot be below 0. Select a value between 0 and 100.");
}
const applyState = withLogging(`set brightness to ${brightnessLevel}%`)(applyLightStateToAll);
applyState(lightState.create().brightness(brightnessLevel));
if (!colorTemperatureLevel) {
throw new Error("ColorTemperature level argument is missing. Make sure you ran it like: `npm run set-color-temperature -- 170`");
}
if (colorTemperatureLevel > 500) {
throw new Error("Color Temperature level cannot be above 500. Select a value between 153 and 500.");
}
if (colorTemperatureLevel < 153) {
throw new Error("Color Temperature level cannot be below 153. Select a value between 153 and 500.");
}
const applyState = withLogging(`set color temperature to "${colorTemperatureLevel}"`)(applyLightStateToAll);
applyState(lightState.create().colorTemperature(colorTemperatureLevel));
setGroupBrightness (group, event) {
this.props.api.setGroupLightState(
group.id,
lightState.create().transitionFast().bri(event.target.value)
)
.done(this.props.api.updateState)
}
throw new Error(createColorErrorMessage('Color was not defined'));
}
const recognizedColor = color(colorHex);
if (!recognizedColor) {
throw new Error(createColorErrorMessage('Color could not be recognized'));
}
const colorAsHex = recognizedColor.hex();
const [red, green, blue] = recognizedColor.toJSON().slice(1, -1);
const colorName = colorToName.findClosestColor(colorAsHex).name;
const applyState = withLogging(`set color to '${colorName} (${colorAsHex})'`)(applyLightStateToAll);
applyState(lightState.create().rgb(red, green, blue));
if (!saturationLevel) {
throw new Error("Saturation level argument is missing. Make sure you ran it like: `npm run set-saturation -- 50`");
}
if (saturationLevel > 100) {
throw new Error("Saturation level cannot be above 100. Select a value between 0 and 100.");
}
if (saturationLevel < 0) {
throw new Error("Saturation level cannot be below 0. Select a value between 0 and 100.");
}
const applyState = withLogging(`set saturation to ${saturationLevel}%`)(applyLightStateToAll);
applyState(lightState.create().saturation(saturationLevel));