def _set_notification(self, conn, char, enabled, timeout=1.0):
        """Enable/disable notifications on a GATT characteristic

        Args:
            conn (int): The connection handle for the device we should interact with
            char (dict): The characteristic we should modify
            enabled (bool): Should we enable or disable notifications
            timeout (float): How long to wait before failing
        """

        if 'client_configuration' not in char:
            return False, {'reason': 'Cannot enable notification without a client configuration attribute for characteristic'}

        props = char['properties']
        if not props.notify:
            return False, {'reason': 'Cannot enable notification on a characteristic that does not support it'}

        value = char['client_configuration']['value']

        #Check if we don't have to do anything
        current_state = bool(value & (1 << 0))
        if current_state == enabled:
            return

        if enabled:
            value |= 1 << 0
        else:
            value &= ~(1 << 0)

        char['client_configuration']['value'] = value

        valarray = struct.pack("<H", value)
        return self._write_handle(conn, char['client_configuration']['handle'], True, valarray, timeout)
def _set_notification ( self , conn , char , enabled , timeout = 1.0 ) : if 'client_configuration' not in char : return False , { 'reason' : 'Cannot enable notification without a client configuration attribute for characteristic' } props = char [ 'properties' ] if not props . notify : return False , { 'reason' : 'Cannot enable notification on a characteristic that does not support it' } value = char [ 'client_configuration' ] [ 'value' ] current_state = bool ( value & ( 1 << 0 ) ) if current_state == enabled : return if enabled : value |= 1 << 0 else : value &= ~ ( 1 << 0 ) char [ 'client_configuration' ] [ 'value' ] = value valarray = struct . pack ( "<H" , value ) return self . _write_handle ( conn , char [ 'client_configuration' ] [ 'handle' ] , True , valarray , timeout )
Enable/disable notifications on a GATT characteristic

        Args:
            conn (int): The connection handle for the device we should interact with
            char (dict): The characteristic we should modify
            enabled (bool): Should we enable or disable notifications
            timeout (float): How long to wait before failing