blynkkk/lib-python

Catching generic button events possible?

arkhipenko opened this issue · 3 comments

Hi,
I am writing a python script that deals with a changing number of buttons on the Blynk app side.
Currently every button event is caught individually:

@blynk.handle_event('write V1')
def write_virtual_pin_handler1(pin, value):
...

@blynk.handle_event('write V3')
def write_virtual_pin_handler3(pin, value):
...

Is there a way to catch all or a subset of buttons via same method? Since pin is available I can make determination which event happened?
Like this for instance?

@blynk.handle_event('write V*')
def write_virtual_pin_handler_all(pin, value):
...

Right now I am "solving" this like illustrated below, but it is not elegant.

@blynk.handle_event('write V1')
def write_virtual_pin_handler1(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V2')
def write_virtual_pin_handler2(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V3')
def write_virtual_pin_handler3(pin, value):
    virtual_pin_handler_all(pin, value)
    
@blynk.handle_event('write V4')
def write_virtual_pin_handler4(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V5')
def write_virtual_pin_handler5(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V6')
def write_virtual_pin_handler6(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V7')
def write_virtual_pin_handler7(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V8')
def write_virtual_pin_handler9(pin, value):
    virtual_pin_handler_all(pin, value)


    
def virtual_pin_handler_all(pin, value):
    global logger
    ...

Hi Anatoli!
We have global capture for multiple pins
Please see example: https://github.com/blynkkk/lib-python/blob/master/examples/07_tweet_and_logging.py

@blynk.handle_event('write V*')
will capture write events from virtual pins 0-32, but if needed you can change hardcoded MAX allowed value inside lib VPIN_MAX_NUM

Hope this is what you are looking for. If no - just ping me additionally )).

You guys are go-o-o-d! It works like a charm. Thank you. 32 is a decent number of buttons for what I need to do. Thanks for the VPIN_MAX_NUM tip.
I can't believe I didn't just test the "write V*" option prior to creating this issue! Could have discovered this by myself.