jangxx / node-magichome

An incomplete implementation of the functionality of the "Magic Home" app. Partially a port of https://github.com/Danielhiversen/flux_led to Node.js
ISC License
124 stars 26 forks source link

Set Color Issue #40

Closed ArtichautDev closed 2 years ago

ArtichautDev commented 2 years ago

C:\Users\pierr\Documents\Chroma\commands\core\ping.js:29 light.setColor(green) ^

ReferenceError: green is not defined at C:\Users\pierr\Documents\Chroma\commands\core\ping.js:29:28

i have this error D; can you send me how to set the correct color 

my code : let light = new Control("192.168.0.103"); light.setPower(true).then(success => { light.setColor(green) });

ArtichautDev commented 2 years ago

and what is callback in the readme.md please

jangxx commented 2 years ago

The signature of the setColor method is setColor(red, green, blue, ?callback) so you need to provide all 3 values. Also you don't seem to set the variable green in your code before using it so of course it is going to be undefined.

Here is a minimal example that turns the light on and then sets the color to 100% green:

const { Control } = require('magic-home');

const light = new Control("192.168.1.100");
light.setPower(true).then(() => {
    const red = 0;
    const green = 255;
    const blue = 0;
    return light.setColor(red, green, blue);
}).then(() => {
    console.log("success");
}).catch(err => {
   console.log(`An error occured: ${err}`);
});
jangxx commented 2 years ago

Also this question really belongs into the Discussions and not the Issues, since the issue is clearly within your own code. If you have general questions, please open a discussion instead of an issue - that's what they are for after all.