Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ampledata committed Oct 15, 2015
2 parents 39f6bef + c0e7aea commit 8c73d62
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
38 changes: 19 additions & 19 deletions pygatt/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class BluetoothLEDevice(object):

"""BluetoothLEDevice Object."""

logger = logging.getLogger(__name__)
logger.setLevel(pygatt.constants.LOG_LEVEL)
console_handler = logging.StreamHandler()
console_handler.setLevel(pygatt.constants.LOG_LEVEL)
formatter = logging.Formatter(pygatt.constants.LOG_FORMAT)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
logger.propagate = False
_logger = logging.getLogger(__name__)
if not _logger.handlers:
_logger.setLevel(pygatt.constants.LOG_LEVEL)
_console_handler = logging.StreamHandler()
_console_handler.setLevel(pygatt.constants.LOG_LEVEL)
_console_handler.setFormatter(pygatt.constants.LOG_FORMAT)
_logger.addHandler(_console_handler)
_logger.propagate = False

def __init__(self, mac_address, hci_device='hci0', app_options=''):
self.handles = {}
Expand All @@ -58,7 +58,7 @@ def __init__(self, mac_address, hci_device='hci0', app_options=''):
'-I'
]))

self.logger.debug('gatttool_cmd=%s', gatttool_cmd)
self._logger.debug('gatttool_cmd=%s', gatttool_cmd)
self.con = pexpect.spawn(gatttool_cmd)

self.con.expect(r'\[LE\]>', timeout=1)
Expand All @@ -81,12 +81,12 @@ def __del__(self):

def bond(self):
"""Securely Bonds to the BLE device."""
self.logger.info('Bonding.')
self._logger.info('Bonding.')
self.con.sendline('sec-level medium')

def connect(self, timeout=pygatt.constants.DEFAULT_CONNECT_TIMEOUT_S):
"""Connect to the device."""
self.logger.info('Connecting with timeout=%s', timeout)
self._logger.info('Connecting with timeout=%s', timeout)
try:
with self.connection_lock:
self.con.sendline('connect')
Expand All @@ -97,7 +97,7 @@ def connect(self, timeout=pygatt.constants.DEFAULT_CONNECT_TIMEOUT_S):

def disconnect(self):
"""Send gatttool disconnect command"""
self.logger.info('Disconnecting...')
self._logger.info('Disconnecting...')
self.con.sendline('disconnect')

def get_handle(self, uuid):
Expand Down Expand Up @@ -180,13 +180,13 @@ def char_write(self, handle, value, wait_for_response=False):

cmd = 'char-write-%s 0x%02x %s' % (cmd, handle, hexstring)

self.logger.debug('Sending cmd=%s', cmd)
self._logger.debug('Sending cmd=%s', cmd)
self.con.sendline(cmd)

if wait_for_response:
self._expect('Characteristic value was written successfully')

self.logger.debug('Sent cmd=%s', cmd)
self._logger.debug('Sent cmd=%s', cmd)

def char_read_uuid(self, uuid, timeout=pygatt.constants.DEFAULT_TIMEOUT_S):
"""
Expand Down Expand Up @@ -233,7 +233,7 @@ def subscribe(self, uuid, callback=None, indication=False):
:return:
:rtype:
"""
self.logger.info(
self._logger.info(
'Subscribing to uuid=%s with callback=%s and indication=%s',
uuid, callback, indication)
definition_handle = self.get_handle(uuid)
Expand All @@ -247,7 +247,7 @@ def subscribe(self, uuid, callback=None, indication=False):
else:
properties = bytearray([0x01, 0x00])

self.logger.debug(locals())
self._logger.debug(locals())
try:
self.lock.acquire()

Expand All @@ -268,7 +268,7 @@ def _handle_notification(self, msg):
"""
Handles notification?
"""
self.logger.debug('Handling notification msg=%s', msg)
self._logger.debug('Handling notification msg=%s', msg)
handle, _, value = string.split(msg.strip(), maxsplit=5)[3:]
handle = int(handle, 16)
value = bytearray.fromhex(value)
Expand All @@ -284,12 +284,12 @@ def _handle_notification(self, msg):

def stop(self):
"""Stops?"""
self.logger.info('Stopping')
self._logger.info('Stopping')
self.running = False

def run(self):
"""Runs...?"""
self.logger.info('Running...')
self._logger.info('Running...')
while self.running:
with self.connection_lock:
try:
Expand Down
7 changes: 4 additions & 3 deletions pygatt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import logging


LOG_LEVEL = logging.DEBUG
LOG_FORMAT = ('%(asctime)s %(levelname)s %(name)s.%(funcName)s:%(lineno)d'
' - %(message)s')
LOG_LEVEL = logging.INFO
LOG_FORMAT = logging.Formatter(
'%(asctime)s %(levelname)s %(name)s.%(funcName)s:%(lineno)d - pygatt '
'- %(message)s')

DEFAULT_TIMEOUT_S = .5
DEFAULT_ASYNC_TIMEOUT_S = .5
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


__title__ = 'pygatt'
__version__ = '1.2.0'
__version__ = '1.3.0'
__author__ = 'Greg Albrecht <gba@orionlabs.co>'
__license__ = 'Apache License, Version 2.0'
__copyright__ = 'Copyright 2015 Orion Labs, Inc.'
Expand Down Expand Up @@ -47,7 +47,7 @@ def publish():
install_requires=['pexpect >= 3.3'],
setup_requires=[
'coverage >= 3.7.1',
'nose >= 1.3.1'
'nose >= 1.3.7'
],
package_dir={'pygatt': 'pygatt'},
zip_safe=False,
Expand Down

0 comments on commit 8c73d62

Please sign in to comment.