Betree / magicblue

💡 Unofficial Python API to control Magic Blue bulbs over Bluetooth
MIT License
100 stars 23 forks source link

Keep current color when changing brightness #18

Open xiaohuim opened 7 years ago

xiaohuim commented 7 years ago

The color is set to white when bulb.turn_on(BRIGHTNESS) is called. And the brightness is set to 100% when calling bulb.set_color([R, G, B]).

I haven't looked into the MagicBlue's BLE characteristic, so I'm not sure if this is easy to accomplish.

Betree commented 7 years ago

Such a feature would be nice indeed. Ideally we would have to read the current color from the bulb but that part is still tricky (see #17).

But we could be able to do that right now by storing the current color in MagicBlueLib.

StevenLooman commented 7 years ago

It appears from this article that the bulb actually has two sets of LEDs: one set for colors, one set for warm light. (As seen on this image.) I think that you cannot use both sets of LEDs at the same time (at least via Bluetooth), possibly due to prevention of overheating or drawing too much current.

The name 'brightness' is perhaps misleading since RGB and warm light are actually two different (physical) things for this bulb. The brightness of RGB is controlled by setting a darker RGB color. The brightness of warm light is controlled by setting a lower intensity for warm light.

Maybe the API should avoid the word brightness and instead use warm_light_intensity in method turn_on(). The method can also be extended by adding an additional parameter for RGB. Or, the API can be simplified by not accepting any further paramters, forcing the user to call it turn_on() and set_warm_light()/set_color() directly. (The last has my preference.)

By looking at turn_on(), actually, I see that it calls set_color() with a RGB color. Maybe the firmware is smart enough to use the warm light LEDS if all parts of the RGB color are the same.