themoosman / blynclight-api-server

BlyncLight API Server for the Embrava BlyncLight
Apache License 2.0
8 stars 0 forks source link

Required blynclight package is going dormant. #2

Closed JnyJny closed 4 years ago

JnyJny commented 4 years ago

First, I love the solution you built to solve the "I'm on a call" problem! Also I am very proud (and flattered) to see you that you leveraged my blynclight package to get it done!

I wanted to let you know that the I've stopped working on blynclight (except for small fixes) and most of my effort has gone into the BusyLight package that supports lights from multiple vendors. I would recommend that you swap BusyLight for blynclight, which should be a relatively painless change. That way you'll benefit from continued bug fixes and features as I refine busylight.

The busylight.manager.LightManager class was designed for web API use and provides some threading support (mostly of light animations). I think adapting those threaded animation classes to your use should be pretty straight-forward. If you are interested in a more one-for-one replacement for the blynclight.Blynclight class, you could use busylight.lights.embrava.Blynclight:

from busylight.lights import Blynclight

light = Blynclight.first_light()

with light.batch_update():
    light.on((255,0,255))  

# light is on purple

If you are interested in help with porting your project to the new API, I'd be more than happy to work up a PR for it.

Edited to fix my terrible memory of my own API.

themoosman commented 4 years ago

I did some testing last evening and didn't have much luck. So I created a simple test case and got the same results. The code below does not display the light color (red). When I use the CLI it works just fine.

import time
from busylight.lights import Blynclight

light = Blynclight.first_light()

with light.batch_update():
    light.color = (255, 0, 0)
    light.speed = 1
    light.flash = 1
    light.on = True

time.sleep(10)
themoosman commented 4 years ago

Okay, so when I needed to modify the code slightly.

import time
from busylight.lights import Blynclight

light = Blynclight.first_light()

with light.batch_update():
    light.reset(flush=True)
    light.on()

time.sleep(10)
JnyJny commented 4 years ago

Ugh. It isn't a good sign when I don't know my own API. Also, I should never write examples off the top of my head.

Commenting on your snippet above, the batch_update context manager will call USBLight.write() when the context exits, so the reset(flush=True) causes a write, the light.on() calls busylight.lights.embrava.Blynclight.impl_on which again invokes batch_update.. there are a lot of unnecessary writes occurring in that snippet.


light = Blynclight.first_light()

light.on()                                      # turns the light on green
light.off()                                     # turns the light off
light.blink((255,0,0), speed=1)                 # blink red slowly

You can directly modify the Blynclight using it's hardware attributes similar to the BlyncLight package:


light = Blynclight.first_light()

light._off = True                # toggle the light off, no effect on current light state
light.write()                    # now the light turns off

light.red = 255
light.green = 255
light.blue = 255
light._off = False 
light.write()                    # light turns on with white color

The batch_update context manager comes in handy here:


with light.batch_update():
    light.red = 0
    light.green = 0
    light.blue = 0xff
    light.dim = 1
    light._off = False

# the light turns on with a dim blue color when the context manager exits.