alexryd / node-shellies

Handles communication with Shelly devices
MIT License
35 stars 13 forks source link

Report RGB as one entity #9

Open jghaanstra opened 4 years ago

jghaanstra commented 4 years ago

Nice library. Will probably be using this to integrate Shelly devices with the Homey domotica controller. I have a request though.

Currently the Shelly RGBW2 and Shelly Bulb report color changes with individual reports for each R, G and B values. Is it possible to receive only one status change when the color changes containing all values for red, green and blue channel at once?

alexryd commented 4 years ago

That can be achieved using something like this:

device.on('change:red', changeHandler)
device.on('change:green', changeHandler)
device.on('change:blue', changeHandler)

let timeout = null

const changeHandler = () => {
  if (timeout !== null) {
    return
  }

  timeout = setTimeout(() => {
    console.log(device.red, device.green, device.blue)
    timeout = null
  }, 0)
}
jghaanstra commented 4 years ago

Yeah, I already have something similar in place but just thought it would make more sense to report the RGB color as one entity. Feel free to close it though.

alexryd commented 4 years ago

Yeah it might, I'll look in to it.