Skip to content

Commit

Permalink
Fixed bug in timeout setting by environment variable.
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
hbldh committed Sep 14, 2016
1 parent 3deb542 commit 7a622c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pymetawear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from pymetawear.utils import IS_64_BIT

# Version information.
__version__ = '0.5.0a3'
__version__ = '0.5.0a4'
version = __version__ # backwards compatibility name
version_info = (0, 5, 0, 'a3')
version_info = (0, 5, 0, 'a4')

if os.environ.get('METAWEAR_LIB_SO_NAME') is not None:
libmetawear = cdll.LoadLibrary(os.environ["METAWEAR_LIB_SO_NAME"])
Expand Down
17 changes: 12 additions & 5 deletions pymetawear/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
except ImportError as e:
BluepyBackend = e

PYMETAWEAR_TIMEOUT = os.environ.get('PYMETAWEAR_TIMEOUT', )


def discover_devices(timeout=5):
"""Discover Bluetooth Low Energy Devices nearby.
Expand Down Expand Up @@ -109,27 +107,36 @@ def __init__(self, address, backend='pygatt',
if self._debug:
print("Creating MetaWearClient for {0}...".format(address))

# Handling of timeout.
if timeout is None:
timeout = os.environ.get('PYMETAWEAR_TIMEOUT', None)
if timeout is not None:
try:
timeout = float(timeout)
except:
timeout = None

if backend == 'pygatt':
if isinstance(PyGattBackend, Exception):
raise PyMetaWearException(
"pygatt[GATTTOOL] package error :{0}".format(PyGattBackend))
self._backend = PyGattBackend(
self._address, interface=interface,
timeout=PYMETAWEAR_TIMEOUT if timeout is None else timeout, debug=debug)
timeout=timeout, debug=debug)
elif backend == 'pybluez':
if isinstance(PyBluezBackend, Exception):
raise PyMetaWearException(
"pybluez[ble] package error: {0}".format(PyBluezBackend))
self._backend = PyBluezBackend(
self._address, interface=interface,
timeout=PYMETAWEAR_TIMEOUT if timeout is None else timeout, debug=debug)
timeout=timeout, debug=debug)
elif backend == 'bluepy':
if isinstance(BluepyBackend, Exception):
raise PyMetaWearException(
"bluepy package error: {0}".format(BluepyBackend))
self._backend = BluepyBackend(
self._address, interface=interface,
timeout=PYMETAWEAR_TIMEOUT if timeout is None else timeout, debug=debug)
timeout=timeout, debug=debug)
else:
raise PyMetaWearException("Unknown backend: {0}".format(backend))

Expand Down

0 comments on commit 7a622c9

Please sign in to comment.