Skip to content

Commit

Permalink
bumped to 0.1.3; fixed init bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
suzker committed Aug 27, 2018
1 parent 9803113 commit 4c598d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
8 changes: 6 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
1. used [peplin/pygatt](https://github.com/peplin/pygatt) as backend
2. made _PyAnova_ object thread-safe

# pyanova-[0.1.2]
# ~~pyanova-[0.1.2]~~ recalled

1. removed default debug logger
2. fixed up the demo
3. added this changelog
3. added this changelog

# pyanova-[0.1.3]

1. bug fix: fixed initialization bug, removed logger provider
29 changes: 6 additions & 23 deletions pyanova/pyanova.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
DEFAULT_HANDLER.setFormatter(DEFAULT_LOGGING_FORMATER)
DEFAULT_LOGGER = logging.getLogger('pyanova_default_logger')
DEFAULT_LOGGER.addHandler(DEFAULT_HANDLER)
DEFAULT_LOGGER.setLevel(logging.INFO)

import pygatt
import threading
Expand All @@ -100,26 +101,6 @@ class PyAnova(object):
cb_cond = threading.Condition(threading.Lock())
cb_resp = None

@staticmethod
def DEFAULT_DEBUG_LOGGER_PROVIDER():
"""This method returns the default logger in debug level
Returns:
logging.Logger: the debug logger
"""
DEFAULT_LOGGER.setLevel(logging.DEBUG)
return DEFAULT_LOGGER

@staticmethod
def DEFAULT_LOGGER_PROVIDER():
"""This method returns the default logger in info level
Returns:
logging.Logger: the default logger
"""
DEFAULT_LOGGER.setLevel(logging.INFO)
return DEFAULT_LOGGER

@staticmethod
def indication_callback(handle, value):
"""This is a callback function for `pygatt`_ BLE notification
Expand All @@ -135,7 +116,7 @@ def indication_callback(handle, value):
PyAnova.cb_cond.notify()
PyAnova.cb_cond.release()

def __init__(self, auto_connect=True, logger_provider=PyAnova.DEFAULT_LOGGER_PROVIDER):
def __init__(self, auto_connect=True, logger=DEFAULT_LOGGER, debug=False):
"""This is the constructor for a pyanova.PyAnova object
there are two ways of constructing a PyAnova object: 'auto mode' and 'manual mode'
Expand All @@ -145,12 +126,14 @@ def __init__(self, auto_connect=True, logger_provider=PyAnova.DEFAULT_LOGGER_PRO
Args:
auto_connect (bool): to use auto mode or not
logger_provider (func): a function handle that returns a `logging.Logger`_ object, defualt to `DEFAULT_DEBUG_LOGGER_PROVIDER`_
logger (logging.Logger): logger, defualt to `DEFAULT_LOGGER`_
debug (bool): if set to Ture logger would set to `logging.DEBUG`_ level
"""
self._dev = None
self._adapter = pygatt.GATTToolBackend()
self._logger = logger_provider()
self._logger = DEFAULT_LOGGER
if debug: self._logger.setLevel(logging.DEBUG)
if auto_connect: self.auto_connect()

def __del__(self):
Expand Down
2 changes: 1 addition & 1 deletion samples/pyanova_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if __name__ == '__main__':
print '~~ pyanova demo ~~'
print '-- Initializing PyAnova object'
pa = pyanova.PyAnova(logger_provider=pyanova.DEFAULT_DEBUG_LOGGER_PROVIDER)
pa = pyanova.PyAnova(debug=True)
cmd_re = re.compile('^get|^stop|^set')
cmd_list = list(filter(lambda m: cmd_re.match(m), dir(pa)))
print '-- PyAnova object initialized'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
name='pyanova',
author='c3V6a2Vy',
author_email='c3V6a2Vy@protonmail.com',
version='0.1.2',
version='0.1.3',
packages=['pyanova',],
url='https://github.com/c3V6a2Vy/pyanova',
license='Apache License 2.0',
Expand Down

0 comments on commit 4c598d2

Please sign in to comment.