From ab24980d84e3d7043802e3ff27d1bd7412a584cc Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Tue, 10 Sep 2019 08:54:23 -0500 Subject: [PATCH] Allow wait_for_reponse can be configured on subscribe or unsubscribe 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 --- pygatt/device.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pygatt/device.py b/pygatt/device.py index 79bdb0fb..9e13b9b4 100644 --- a/pygatt/device.py +++ b/pygatt/device.py @@ -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. @@ -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 = ( @@ -215,7 +219,7 @@ 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 @@ -223,7 +227,7 @@ def subscribe(self, uuid, callback=None, indication=False): 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. """ @@ -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: