Skip to content

Commit

Permalink
fix(timer): BlynkTimer Broken on Low Memory Ports (#6)
Browse files Browse the repository at this point in the history
* fix(timer): BlynkTimer Broken on Low Memory Ports

On low memory ports MICROPY_PY_FUNCTION_ATTRS is disabled, leading BlynkTimer to raise an AttributeError when trying to get a name for a new timer. This fixes it by naming each timer 'X_timer' (where X is the # of timer) if the __name__ attribute does not exist.

Fixes #5

* docs(timer): Added note about Low Memory ports

* feat(timer): Cleanup Code, handle all cases

* docs(timer): Added some docstrings for clarification
  • Loading branch information
BradenM authored and antohaUa committed Jun 20, 2019
1 parent 2631963 commit 37df411
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions TIMERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ print(blynk_timer.get_timers())

# switch timer state to stopped by timer id
# id = order_num + '_' + function_name
# OR: on ports with low memory (such as the esp8266)
# id = order_num + '_' + 'timer'
blynk_timer.stop('2_function2')


while True:
intervals = blynk_timer.run()
# print real passed time for timer fired events
Expand Down
7 changes: 5 additions & 2 deletions blynktimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def __init__(self, no_timers_err=True):
self.no_timers_err = no_timers_err

def _get_func_name(self, obj):
if getattr(obj, '__name__', None) is None:
"""retrieves a suitable name for a function"""
if hasattr(obj, 'func'):
# handles nested decorators
return self._get_func_name(obj.func)
return obj.__name__
# simply returns 'timer' if on port without function attrs
return getattr(obj, '__name__', 'timer')

def register(blynk, *args, interval=DEFAULT_INTERVAL, run_once=False, **kwargs):
class Deco(object):
Expand Down

0 comments on commit 37df411

Please sign in to comment.