Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep current color when changing brightness #18

Open
xiaohuim opened this issue Apr 26, 2017 · 2 comments
Open

Keep current color when changing brightness #18

xiaohuim opened this issue Apr 26, 2017 · 2 comments
Labels

Comments

@xiaohuim
Copy link

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
Copy link
Owner

Betree commented Apr 26, 2017

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.

  • Downside : set_brightness would have a strange behaviour before the first call to turn_on, set_warm_light or set_color as the first color would be unknown
  • Upside : easy to implement, as setting the brightness basically consists in applying it to each component of the colour. Example (admitting current_color contains the colors list as [red, green, blue]) :
def set_brightness(self, brightness):
    """
    Changes current brightness
    :param brightness: between 0.0 and 1.0 : brightness ratio
    """
    self.set_color([
        int(self.current_color[0] * brightness),
        int(self.current_color[1] * brightness),
        int(self.current_color[2] * brightness)
    ])

@Betree Betree added the feature label Apr 26, 2017
@StevenLooman
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants