8000 fix(timer): BlynkTimer Broken on Low Memory Ports (#6) · fgervais/lib-python@37df411 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37df411

Browse files
BradenMantohaUa
authored andcommitted
fix(timer): BlynkTimer Broken on Low Memory Ports (blynkkk#6)
* 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 blynkkk#5 * docs(timer): Added note about Low Memory ports * feat(timer): Cleanup Code, handle all cases * docs(timer): Added some docstrings for clarification
1 parent 2631963 commit 37df411

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

TIMERS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ print(blynk_timer.get_timers())
6666

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

73+
7174
while True:
7275
intervals = blynk_timer.run()
7376
# print real passed time for timer fired events

blynktimer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ def __init__(self, no_timers_err=True):
4444
self.no_timers_err = no_timers_err
4545

4646
def _get_func_name(self, obj):
47-
if getattr(obj, '__name__', None) is None:
47+
"""retrieves a suitable name for a function"""
48+
if hasattr(obj, 'func'):
49+
# handles nested decorators
4850
return self._get_func_name(obj.func)
49-
return obj.__name__
51+
# simply returns 'timer' if on port without function attrs
52+
return getattr(obj, '__name__', 'timer')
5053

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

0 commit comments

Comments
 (0)
0