Skip to content

Commit

Permalink
Allow wait_for_reponse can be configured on subscribe or unsubscribe …
Browse files Browse the repository at this point in the history
…method (#248)

* allow wait_for_reponse can be configured on subscribe or unsubscribe method

* allow wait_for_reponse can be configured on subscribe or unsubscribe method
  • Loading branch information
josephillips85 authored and peplin committed Sep 10, 2019
1 parent d6846d1 commit ab24980
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pygatt/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def _notification_handles(self, uuid):

return value_handle, characteristic_config_handle

def subscribe(self, uuid, callback=None, indication=False):
def subscribe(self, uuid, callback=None, indication=False,
wait_for_response=True):

"""
Enable notifications or indications for a characteristic and register a
callback function to be called whenever a new value arrives.
Expand All @@ -196,6 +198,8 @@ def subscribe(self, uuid, callback=None, indication=False):
received on this characteristic.
indication -- use indications (where each notificaiton is ACKd). This is
more reliable, but slower.
wait_for_response -- wait for response after subscription.
"""

value_handle, characteristic_config_handle = (
Expand All @@ -215,15 +219,15 @@ def subscribe(self, uuid, callback=None, indication=False):
self.char_write_handle(
characteristic_config_handle,
properties,
wait_for_response=True
wait_for_response=wait_for_response
)
log.info("Subscribed to uuid=%s", uuid)
self._subscribed_handlers[value_handle] = properties
self._subscribed_uuids[uuid] = indication
else:
log.debug("Already subscribed to uuid=%s", uuid)

def unsubscribe(self, uuid):
def unsubscribe(self, uuid, wait_for_response=True):
"""
Disable notification for a charecteristic and de-register the callback.
"""
Expand All @@ -243,7 +247,7 @@ def unsubscribe(self, uuid):
self.char_write_handle(
characteristic_config_handle,
properties,
wait_for_response=True
wait_for_response=wait_for_response
)
log.info("Unsubscribed from uuid=%s", uuid)
else:
Expand Down

0 comments on commit ab24980

Please sign in to comment.